diff --git a/cocos2dx/platform/ios/CCFileUtils_ios.mm b/cocos2dx/platform/ios/CCFileUtils_ios.mm index 1404f14156..414a6df171 100644 --- a/cocos2dx/platform/ios/CCFileUtils_ios.mm +++ b/cocos2dx/platform/ios/CCFileUtils_ios.mm @@ -369,6 +369,48 @@ namespace cocos2d { strRet.append("/"); return strRet; } + + unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize) + { + unsigned char * pBuffer = NULL; + unzFile pFile = NULL; + *pSize = 0; + + do + { + CC_BREAK_IF(!pszZipFilePath || !pszFileName); + CC_BREAK_IF(strlen(pszZipFilePath) == 0); + + pFile = unzOpen(pszZipFilePath); + CC_BREAK_IF(!pFile); + + int nRet = unzLocateFile(pFile, pszFileName, 1); + CC_BREAK_IF(UNZ_OK != nRet); + + char szFilePathA[260]; + unz_file_info FileInfo; + nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0); + CC_BREAK_IF(UNZ_OK != nRet); + + nRet = unzOpenCurrentFile(pFile); + CC_BREAK_IF(UNZ_OK != nRet); + + pBuffer = new unsigned char[FileInfo.uncompressed_size]; + int nSize = 0; + nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size); + CCAssert(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong"); + + *pSize = FileInfo.uncompressed_size; + unzCloseCurrentFile(pFile); + } while (0); + + if (pFile) + { + unzClose(pFile); + } + + return pBuffer; + } }//namespace cocos2d