解壓

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 ;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章