cocos2d zip文件解压(C++)

在使用C++和Cocos2d-x进行zip文件解压时,遇到编译错误,主要包括找不到zlib.h和unistd.h头文件。解决方法是将zlib.h的路径添加到VS的附加包含目录,并为zconf.h添加一个空的unistd.h文件。
摘要由CSDN通过智能技术生成

实现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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值