您的位置:首页 > 其它

解压

2013-10-23 11:37 190 查看
std::string curentPath=CCFileUtils::sharedFileUtils()->getWriteablePath();

std::string canWriteString=CCFileUtils::sharedFileUtils()->getWriteablePath()+"mac.zip";

CCFileUtils::sharedFileUtils()->getWriteablePath();

unzFile cUnzFile;
unz_global_info cGlobalInfo;
unz_file_info cFileInRo={0};
unsigned char buffer[4096] = {0};

//开始解压

cUnzFile = unzOpen( canWriteString.c_str()) ;

if ( cUnzFile == NULL )
{
CCLOG("文件不存在 你自己先去看看这个到底在不在!");
}

if ( UNZ_OK != unzGetGlobalInfo( cUnzFile , &cGlobalInfo ) )
{
CCLOG("获取整个zip文档详情 错误!");
}
for ( int i = 0 ; i < cGlobalInfo.number_entry ; i++ )
{

if ( UNZ_OK != unzGetCurrentFileInfo(cUnzFile , &cFileInRo ,
NULL, (uLong)0,
NULL , (uLong)0 ,
NULL , (uLong)0) )
{
CCLOG("获取整个zip文档中某个文档信息 错误!");
}

char* filename = (char*) malloc(cFileInRo.size_filename +1 );

unzGetCurrentFileInfo(cUnzFile, &cFileInRo, filename, cFileInRo.size_filename + 1, NULL, 0, NULL, 0);

filename[cFileInRo.size_filename] = '\0';

if ( UNZ_OK != unzOpenCurrentFile( cUnzFile ) )
{

}

FILE* fp = fopen((curentPath+filename).c_str(), "wb");

while( fp)
{
int len = unzReadCurrentFile(cUnzFile , (voidp)buffer, 4096) ;

if( len > 0 )
{
fwrite(buffer,sizeof(char),len,fp);
}
else if( read<=0 )
{
CCLOG("读取文档内容错误!");

break;
}
else
{
break;
}
}

if(fp)
{
fclose( fp );
}

delete filename;

CCLOG("outString %s",filename);

unzCloseCurrentFile( cUnzFile );

unzGoToNextFile( cUnzFile );
}

unzClose( cUnzFile ) ;

cout << "完了" << endl ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: