记录一下在cocos2dx中读取zip和解压zip
1.读取zip
获取可读写入路径,把zip文件拷到可读写路径下,如下
- boolResourcesDecode::loadZIP(conststd::string&zipFilename,conststd::string&password)
- {
- std::stringfilename=zipFilename;
- std::stringdataFilePath=FileUtils::getInstance()->getWritablePath()+filename;
-
- #if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID||CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
- if(access(dataFilePath.c_str(),0)!=0)
- std::stringstrPath=FileUtils::getInstance()->fullPathForFilename(filename);
- ssize_tlen=0;
- unsignedchar*data=0;
- CCLOG("strPath:%s",strPath.c_str());
- data=FileUtils::getInstance()->getFileData(strPath.c_str(),"r",&len);
- CCLOG("file:%s,len:%zd",dataFilePath.c_str(),len);
- FILE*fp=fopen(dataFilePath.c_str(),"w+");
- if(!fp)
- {
- CCLOG("filenotfound!");
- }
- fwrite(data,sizeof(char),len,fp);
- fclose(fp);
- delete[]data;
- data=0;
- }
- #endif
-
- unCompress(dataFilePath.c_str(),password);
- returntrue;
- }
上面参数中password为zip压缩文件密码,在使用资源之前调用loadZIP即可
2.解压zip
读取zip到内存,并且解压zip,如下