码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-04-24 12:36:49      阅读:92      评论:0      收藏:0      [点我收藏+]

标签: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;
}


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

标签:zip

原文地址:http://blog.csdn.net/qingzai_/article/details/45244227

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!