cocos2dx unzip、createDir
转自:http://www.cnblogs.com/xioapingguo/p/4037323.html
static unsigned long _maxUnzipBufSize = 0x500000;
static bool unzip(const char *zipPath,const char *dirpath,const char *passwd)
{
CCLOG("unzip fullpath =%s",zipPath);
unzFile pFile = unzOpen(zipPath);
if(!pFile)
{
return false;
}
int err = unzGoToFirstFile(pFile);
bool ret = true;
while (err == UNZ_OK)
{
int nRet = ;
int openRet = ;
do
{
if(passwd)
{
openRet = unzOpenCurrentFilePassword( pFile,passwd);
CCLOG("openRet %d",openRet);
}
else
{
openRet = unzOpenCurrentFile(pFile);
}
CC_BREAK_IF(UNZ_OK != openRet);
unz_file_info FileInfo;
char szFilePathA[];
nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, , NULL, );
CC_BREAK_IF(UNZ_OK != nRet);
//如果szFilePathA为中文的话,请使用iocnv转码后再使用。
std::string newName = std::string(dirpath)+"/"+szFilePathA;
if (newName[newName.length()-]=='/')
{
FileUtils::getInstance()->createDir(newName.c_str());
continue;
} FILE* pFile2 = fopen(newName.c_str(), "w");
if (pFile2)
{
fclose(pFile2);
}
else
{
CCLOG("unzip can not create file");
return false;
}
unsigned long savedSize = ;
while(pFile2 != NULL && FileInfo.uncompressed_size > savedSize)
{
unsigned char *pBuffer = NULL;
unsigned long once = FileInfo.uncompressed_size - savedSize;
if(once > _maxUnzipBufSize)
{
once = _maxUnzipBufSize;
pBuffer = new unsigned char[once];
}
else
{
pBuffer = new unsigned char[once];
}
int nSize = unzReadCurrentFile(pFile, pBuffer, once);
fwrite(pBuffer, once, , pFile2); savedSize += nSize;
delete []pBuffer;
}
if (pFile2)
{
fclose(pFile2);
} } while ();
if(nRet != UNZ_OK)
{
ret = false;
}
else
{
unzCloseCurrentFile(pFile);
}
err = unzGoToNextFile(pFile);
} if(err != UNZ_END_OF_LIST_OF_FILE)
{
ret = false;
}
unzClose(pFile);
return ret;
}
这个方法 压缩文件中不能有中文文件名的文件,因为中文在window下zip后里面的中文是用的gb2312编码,而IOS中用的是utf8格式,这时unzip时文件名会出错,导致解压失败。
如果非得一定要使用的话,要使用iconv库进行转码。具体使用方法请参考http://www.cnblogs.com/hewei2012/p/3374147.html
创建目录的方法:在FileUtils中加个方法
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#endif void FileUtils::createDir(const char* p)
{
std::string path = p;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) mode_t processMask = umask();
int ret = false; ret = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
umask(processMask);
if (ret != && (errno != EEXIST))
{
CCLOG("create dir fail");
} #else
BOOL ret = false; ret = CreateDirectoryA(path.c_str(), NULL);
if (!ret && ERROR_ALREADY_EXISTS != GetLastError())
{
CCLOG("create dir fail");
}
#endif
}
cocos2dx unzip、createDir的更多相关文章
- Cocos2d-x开源、跨平台的游戏引擎
from://http://blog.linguofeng.com/pages/language/c/Cocos2dx.html Cocos2d-x 开源.跨平台的游戏引擎 一.下载 http://c ...
- linux下压缩与解压(zip、unzip、tar)详解
linux下压缩与解压(zip.unzip.tar)详解 2012-05-09 13:58:39| 分类: linux | 标签:linux zip unzip tar linux命令详解 |举报|字 ...
- cocos2d-x Menu、MenuItem
转自:http://codingnow.cn/cocos2d-x/832.html 学习cocos2d-x中的菜单主要需要了解:菜单(CCMenu)和菜单项(CCMenuItem)以及CCMenuIt ...
- cocos2d-x ScrollView、TableView
转自:http://codingnow.cn/cocos2d-x/1024.html 在游戏和应用中经常要实现左右滑动展示游戏帮助.以列表显示内容的UI效果,就像android中的Gallery和Li ...
- Cocos2d-X 精灵、动作效果
命名空间宏: USING_NS_CC; 感觉事实上挺鸡肋的. NS_CC_BEGIN. == using namespace cocos2d{ NS_CC_END ; } 推断一个精灵被点击: 1.层 ...
- ROS零门槛学渣教程系列(二)——Linux常用指令:mkdir、tar、 unzip、cp、scp、mv、rm、find、apt、ssh
Linux常用指令通过上一教程,我们获得了ubuntu系统.Linux是一个很大的领域.但不要紧张,我们一步步来就是了,跟着教程,需要能用到新知识,会提前介绍给大家.下面学习几个常用的Linux指令. ...
- linux中tar命令(打包、压缩、解压)、zip和unzip、rar多种压缩文件
一.名词解释 打包:将一大堆文件或目录变成一个总的文件[tar命令] 压缩:将一个大的文件通过一些压缩算法变成一个小文件[gzip,bzip2等] Linux中很多压缩程序只能针对一个文件进行压缩,这 ...
- 压缩 & 解压缩 命令汇总:tar、zip & unzip、
1. tar命令详解 格式:tar [-cxtzjvfpPN] 文件与目录 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五 ...
- 网狐6603 cocos2dx 棋牌、捕鱼、休闲类游戏《李逵捕鱼》手机端完整源码分析及分享
该资源说明: cocos2d 棋牌.捕鱼.休闲类游戏<李逵捕鱼>手机端完整源码,网狐6603配套手机版源码,可以选桌子,适合新手学习参考,小编已亲测试,绝对完整可编译手机端,下载后将文件考 ...
随机推荐
- LRU java实现
实现LRU缓存,用到了一个链表和 HashMap, HashMap保证了get/set的时间复杂度是O(1), 链表用来记录 最近最少使用的元素,以便用来淘汰. package lru; /** * ...
- PHP服务端如何通过程序将图上传到指定的图片服务器与图片服务器的优化方案
一:PHP服务端如何通过程序将图上传到指定的图片服务器与图片服务器的优化方案 (1) php服务器把图片处理成缩率图或指定大小的图片在通过PHP程序代码 操作FTP 上传到图片服务器. 二:图片服务器 ...
- Android 关于软键盘
一..弹出的时候显示Editext框 添加布局replay_input <?xml version="1.0" encoding="utf-8"?> ...
- Objective-C/C++混编编译器设置
本文转载至 http://blog.csdn.net/yu0089/article/details/8220275 当使用Xcode编写C++代码时,难以避免要使用xcode/C++混合编译. 如果你 ...
- 【BZOJ3834】[Poi2014]Solar Panels 分块好题
[BZOJ3834][Poi2014]Solar Panels Description Having decided to invest in renewable energy, Byteasar s ...
- Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fromHere.com' is therefore not allowed access.
Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is presen ...
- Bootstrap aggregating Bagging 合奏 Ensemble Neural Network
zh.wikipedia.org/wiki/Bagging算法 Bagging算法 (英语:Bootstrap aggregating,引导聚集算法),又称装袋算法,是机器学习领域的一种团体学习算法. ...
- adjA=(detA)A-1
A–>adjA 连续性 反函数
- ideal 快捷键
1.输入sout --> System.out.println(); 2.输入psvm --> main函数; IntelliJ Idea 2017 免费激活方法 1. 到网站 http: ...
- 新版本ADT创建Android项目无法自动生成R文件解决办法
本人使用的是ADT是Version 23.0.2,支持Android 6.0之后的系统环境,最高版本23,在创建Android项目的时候,每次创建项目选择“Compile With”低于6.0版本的时 ...