vc解压和载入zip资源包方法

提示:

这种方法解压后会释放所有文件在你选择的路径下,但是有个缺点是不会删除解压的文件

需要在项目中添加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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值