mirror of https://github.com/axmolengine/axmol.git
fixed #917: implement CCFileUtils::getFileDataFromZip() on iOS
This commit is contained in:
parent
a8d5b6544a
commit
28d0737bf3
|
@ -370,5 +370,47 @@ namespace cocos2d {
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue