【文件属性】:
文件名称:ZIP 压缩 解压缩 源码
文件大小:196KB
文件格式:ZIP
更新时间:2015-09-12 06:09:59
ZIP 压缩 解压缩 源码
使用ZLIB库 包装的压缩解压缩文件的源码 VS2005 工程创建
/*
*/
class ZIPWRAP_EXP CZipper
{
public:
CZipper();
virtual ~CZipper();
// simple interface
static bool ZipFile(const char* szFilePath); // saves as same name with .zip
static bool ZipFolder(const char* szFilePath, bool ignoreself = false); // saves as same name with .zip
bool AddFolderToZipFile(const char*foldername, const char* rootfolder);
bool AddFileToZipFile(const char*filename, const char*relfolder = NULL, const char* comment = NULL);
bool AddFolderOnlyPathToFile(const char* foldername, const char* comment = NULL);
bool OpenZipFile(const char* zipfilename, bool append = false);
bool CloseZipFile(const char* global_comment = NULL);
private:
void* zipfile_;/* = NULL */
};
/*
*/
#define MAX_COMMENT (255)
/* tm_unz contain date/time info */
typedef struct UZ_s
{
unsigned int tm_sec; /* seconds after the minute - [0,59] */
unsigned int tm_min; /* minutes after the hour - [0,59] */
unsigned int tm_hour; /* hours since midnight - [0,23] */
unsigned int tm_mday; /* day of the month - [1,31] */
unsigned int tm_mon; /* months since January - [0,11] */
unsigned int tm_year; /* years - [1980..2044] */
} UZ_s;
// create our own fileinfo struct to hide the underlying implementation
struct UZ_FileInfo
{
char szFileName[260 + 1];
char szComment[255 + 1];
unsigned long dwVersion;
unsigned long dwVersionNeeded;
unsigned long dwFlags;
unsigned long dwCompressionMethod;
unsigned long dwDosDate;
unsigned long dwCRC;
unsigned long dwCompressedSize;
unsigned long dwUncompressedSize;
unsigned long dwInternalAttrib;
unsigned long dwExternalAttrib;
bool bFolder;
UZ_s tmu_date;
};
class ZIPWRAP_EXP CUnZipper
{
public:
CUnZipper();
virtual ~CUnZipper();
// simple interface
static bool UnZip( const char* filename, const char* dstfolder, bool ingorepath = false, const char* password = NULL);
bool OpenUnZipFile(const char* filename);
bool CloseUnZipFile();
bool UnZipTo( const char* dstfolder, bool ingorepath = false, const char* password = NULL);
int GetFileCount();
bool GotoFirstFile();
bool GotoNextFile();
bool GotoZipFile(int index);
bool GotoZipFile(const char* zipfilename);
bool GetCurrentFileInfo(UZ_FileInfo&fileinfo;);
bool UnCurrentZipFile(const char* dstfolder, bool ingorepath = false, const char* password = NULL);
bool UnOneZipFile(const char* filename, const char* dstfolder, bool ingorepath = false, const char* password = NULL);
bool UnOneZipFile(int index, const char* dstfolder, bool ingorepath = false, const char* password = NULL);
private:
void* unzipfile_;
};
【文件预览】:
zip
----testzipwarp()
--------testzipwarp.vcproj(4KB)
--------testzipwarp.cpp(216B)
--------stdafx.h(276B)
--------ReadMe.txt(974B)
--------stdafx.cpp(216B)
----zip()
--------infback.c(22KB)
--------ioapi.cpp(7KB)
--------zip.c(64KB)
--------inflate.h(6KB)
--------crc32.c(13KB)
--------zip.h(15KB)
--------inffast.c(13KB)
--------inffixed.h(6KB)
--------trees.c(44KB)
--------unzip.h(16KB)
--------gzlib.c(14KB)
--------uncompr.c(2KB)
--------gzread.c(20KB)
--------deflate.h(12KB)
--------gzwrite.c(14KB)
--------inflate.c(51KB)
--------inftrees.h(3KB)
--------deflate.c(66KB)
--------trees.h(8KB)
--------zlib.h(78KB)
--------ioapi.h(7KB)
--------ReadMe.txt(646B)
--------crc32.h(30KB)
--------zconf.h(13KB)
--------unzip.c(69KB)
--------crypt.h(5KB)
--------gzguts.h(5KB)
--------adler32.c(5KB)
--------inftrees.c(13KB)
--------zutil.h(7KB)
--------gzclose.c(678B)
--------inffast.h(427B)
--------zlibvc.def(6KB)
--------compress.c(2KB)
--------zutil.c(7KB)
--------zip.vcproj(5KB)
----zip.sln(2KB)
----release()
--------ziptest.txt(11B)
----debug()
--------ziptest.txt(11B)
----zip.suo(33KB)
----zipwrap()
--------zipwrap_config.h(699B)
--------resource.h(417B)
--------zipwrap.rc(3KB)
--------ZipWrapTools.h(496B)
--------FileOperate.cpp(11KB)
--------zipwrap.vcproj(5KB)
--------stdafx.h(1KB)
--------FileOperate.h(2KB)
--------zipwrap.cpp(350B)
--------ZipWrapper.h(3KB)
--------stdafx.cpp(212B)
--------ZipWrapper.cpp(16KB)
--------ZipWrapTools.cpp(3KB)
--------zipwrap_version_info.txt(1KB)
网友评论
- 谢谢分享已经收藏
- 可以借鉴,正好学习!
- 可以正常使用,挺好的代码
- 有个小bug,FileOperate.cpp line 253 if (TRUE == ::CreateDirectory(strDirPath.c_str(), NULL)) 没有对已经存在的文件夹做过滤,导致对一个zip里面有多层目录类型zip解压失败 建议改为 SetLastError(0); if (TRUE == ::CreateDirectory(strDirPath.c_str(), NULL)) { return true; } else { if (GetLastError() == ERROR_ALREAD
- 可以用 挺好的 就是解压后的文件名后缀有点小问题
- 编辑可用,谢谢
- 封装的相当的好。
- 不错,挺好用~
- 不错 挺好用的
- 不错,正在集成中……。
- 谢谢,可以使用。
- 只能对一个文件解压,有局限性啊
- 谢谢,可以使用。
- 终于找到你,还好我没放弃,哈哈,如获至宝,对我太有用了,真心感谢作者
- 挺好的,可是只等对一个文件解压
- 挺好的,可是只等对一个文件解压
- 看了一下。非常不错,有参考价值!
- 谢谢,可以使用。
- 挺好的,可是只等对一个文件解压
- 使用UNICODE才能使用的呀
- 挺好的,可是只等对一个文件解压
- 挺好的,可是只等对一个文件解压