in isFileExistInternal in FileUtilsAndroid (CCFileUtils-android)
if (obbfile && obbfile->fileExists(s))
returns false because _data->fileList in ZipUtils is empty. Finally I’ve discovered that:
_data->zipFile = unzOpen(FileUtils::getInstance()->getSuitableFOpen(zipFile).c_str()); // line 540 in ZipUtils.cpp
is NULL so no fileList entry can be added in setFilter(filter) and therefore files are never found in zip (obb).
Cocos2dxHelper.sOBBFile contains all the resources in the obb file.
Have you created a GitHub issue for this yet? There are a few changes noted here: https://github.com/cocos2d/cocos2d-x/blob/v3/CHANGELOG but I’m not sure if anything effects you. Perhaps this has been broken before 3.17.
I’m creating a GitHub issue.
Not sure when between versions 3.13 - 3.17.1 the loading of obb content files stopped working. I’m unable to find what change from the change log generated the issue.
Hi,
Has anyone been able to look at it?
Digging more I’ve found out why unzOpen returns NULL, in unzip.cpp line 618:
us.filestream = ZOPEN64(us.z_filefunc,
path,
ZLIB_FILEFUNC_MODE_READ |
ZLIB_FILEFUNC_MODE_EXISTING);
if (us.filestream==NULL)
return NULL; // is returning here although the path is correct
I’ve created the obb (zip) file with the following command:
$ zip -r -n .mp3 main.1.com.sample.zip *
The problem is that can’t directly open the zip package in android apk (assets/) by fopen() method. I used another method to circumvent this problem. The following is the solution:
Data buffer;
string zipPath = "assets/page1.zip";
string dataPath = "page1/json.txt";
ssize_t size = 0;
Data zipBuffer;
FileUtils::getInstance()->getContents(zipPath, &zipBuffer);
ZipFile* zipfile = ZipFile::createWithBuffer(zipBuffer.getBytes(), zipBuffer.getSize());
auto data = zipfile->getFileData(dataPath, &size);
// auto data = FileUtils::getInstance()->getFileDataFromZip(zipPath, dataPath, &size);
if (data) {
buffer.fastSet(data, size);
}
return buffer;
Use remember to release free(buffer)
I hope to solve your problem.