Hello,
i’m facing this issue in iOS specifically, it works fine in android.
here’s the code the I use to unzip zip files :
cocos2d::ZipFile zFile = cocos2d::ZipFile(zipLocation);
std::string fileName = zFile.getFirstFilename();
std::string file = fileName;
ssize_t filesize;
unsigned char* data = zFile.getFileData(fileName, &filesize);
std::string directoryName = cocos2d::FileUtils::getInstance()->getWritablePath();
if (!cocos2d::FileUtils::getInstance()->isDirectoryExist(directoryName))
{
cocos2d::FileUtils::getInstance()->createDirectory(directoryName);
}
while (data != nullptr)
{
std::string fullFileName = directoryName + file;
//log("filename DIR : %s\n", fullFileName.c_str());
if (fullFileName[fullFileName.size() - 1] == '/') {
cocos2d::FileUtils::getInstance()->createDirectory(fullFileName);
free(data);
fileName = zFile.getNextFilename();
file = fileName;
data = zFile.getFileData(fileName, &filesize);
continue;
}
FILE *fp = fopen(fullFileName.c_str(), "wb");
if (fp)
{
fwrite(data, 1, filesize, fp);
fclose(fp);
}
free(data);
fileName = zFile.getNextFilename();
file = fileName;
data = zFile.getFileData(fileName, &filesize);
}
the problem comes from the fact the my zip has nested folders inside, the next code piece is responsible for that :
if (!cocos2d::FileUtils::getInstance()->isDirectoryExist(directoryName)){
cocos2d::FileUtils::getInstance()->createDirectory(directoryName);
}
but it’s unable to create directories, i’m getting : Fail to create directory
the code for createDirectory function :
bool FileUtilsApple::createDirectory(const std::string& path)
{
CCASSERT(!path.empty(), "Invalid path");
if (isDirectoryExist(path))
return true;
NSError* error;
bool result = [s_fileManager createDirectoryAtPath:[NSString stringWithUTF8String:path.c_str()] withIntermediateDirectories:YES attributes:nil error:&error];
if(!result && error != nil)
{
CCLOGERROR("Fail to create directory \"%s\": %s", path.c_str(), [error.localizedDescription UTF8String]);
}
return result;
}
I’m using an iphone 8 emulator.
1 post - 1 participant
Read full topic