提示:
这种方法解压后会释放所有文件在你选择的路径下,但是有个缺点是不会删除解压的文件
需要在项目中添加XUnzip.cpp和XUnzip.h代码:(需要的朋友可留言)
//载入zip资源包
BOOL ui_dlg_main::LoadZipFileToDir(LPSTR lpDir) //lpDir为载入资源包的路径
{
OPENFILENAMEA ofn = { 0 };
char strFileName[MAX_PATH] = "";
memset(&ofn, 0, sizeof(OPENFILENAME));
memset(strFileName, 0, sizeof(char)*MAX_PATH);
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = "配置(*.zip)";
ofn.lpstrFile = strFileName;
ofn.nFilterIndex = 1;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST;
BOOL ret = GetOpenFileNameA(&ofn);
LPSTR lpZipPath = NULL;
if (ret)
{
lpZipPath = ofn.lpstrFile;//json_name为打开文件的完整路径
}
if (lpZipPath == NULL)
{
return FALSE;
}
HZIP hz = OpenZip(CA2W(lpZipPath),0, ZIP_FILENAME);
if( hz )
{
ZIPENTRYW ze;
GetZipItem(hz,-1,&ze);
int numitems=ze.index;
// -1 gives overall information about the zipfile
std::vector< std::wstring > vts;
for (int zi=0; zi<numitems; zi++)
{
ZIPENTRYW ze;
GetZipItemW(hz,zi,&ze); // fetch individual details
boost::filesystem::path path_dst = lpDir;
path_dst /= ze.name;
vts.push_back( ze.name );
boost::filesystem::path path_dir = path_dst.parent_path();
if ( !boost::filesystem::exists ( path_dir ) )
{
boost::filesystem::create_directories( path_dir);
}
ZRESULT zr = UnzipItem(hz, ze.index, ATL::CA2W(path_dst.string().c_str()), 0 , ZIP_FILENAME ); // e.g. the item's name.
}
CloseZip(hz);
hz = NULL;
MessageBoxA(NULL,"导入成功","提示",MB_OK);
return TRUE;
}
return FALSE;
}