实现zip文件解压,网上已经有很多c++代码实现,核心代码如下:
static bool unzip(const char *zipPath, const char *dirpath, const char *passwd, bool bAsset)
{
CCLOG("unzip info:zippath[%s]\n dirpath[%s]", zipPath, dirpath);
if (false == FileUtils::getInstance()->isFileExist(zipPath)) {
CCLOG("zipfile [%s] not exist", zipPath);
return false;
}
unzFile pFile;
if (!bAsset) {
pFile = unzOpen(zipPath);
}
else {
ssize_t len = 0;
unsigned char *data = FileUtils::getInstance()->getFileData(zipPath, "rb", &len);
pFile = unzOpenBuffer(data, len);
}
if (!pFile) {
CCLOG("unzip error get zip file false");
return false;
}
//解压目录
string szTmpDir = dirpath;
if (szTmpDir[szTmpDir.length() - 1] != '/'){
szTmpDir = szTmpDir + "/";
}
int err = unzGoToFirstFile(pFile);
bool ret = true;
while (err == UNZ_OK) {
int nRet = 0