在MFC中实现Zip压缩及解压缩概述:This library allows creating, modifying, and extracting zip archives in a compatible way with PKZIP (2.5 and higher) and WinZip. Supported are all possible operations on the zip archive: creating, extracting, adding, deleting files from the archive, modifications of the existing archive. There is also support for creating and extracting multiple disk archives (on non-removable devices as well) and for password encryption and decryption. This module uses compression and decompression functions from the zlib library by Jean-loup Gailly and Mark Adler.这个库允许以兼容的方式创建、修改和提取以PKZIP(2.5或更高版本)和WinZip压缩的zip文档格式。
支持几乎所有zip文档格式的相关操作,比如:创建、提取、添加、以及从zip文档中删除文件,修改现有的zip文档等。
同时,该库也支持创建和提取分卷压缩的文档(非移动设备),并且支持带密码的加密以及解密操作。
本模块使用的压缩和解压缩函数来自于zlib库,作者:Jean-loup Gailly、Mark Adler.How to integrate with the projectZip is a static library and statically links to the compiled zlib.lib (version 1.13 nowadays). The zlib library can be replaced with a newer version, providing you also replace the files "zlib.h" and "zconf.h" in the Zip project. The Zip library uses MFC in a shared library as a Release and Debug configuration. Your project must use MFC in the same way in the appropriate project configuration. You may need to adapt this to your needs. To add Zip library functionality to your project, you need to link the library to the project. You can do this in at least two ways (in both cases, you need to include the ZipArchive.h header in your sources like this: #include "ZipArchive.h"):如何将该库整合到您的工程中:Zip是个lib的静态库,他以静态链接的方式编译链接到zlib.lib库(现在是1.13版本)。
当然工程中的zlib库能被替换成您认为当前的最新版本,同时“zlib.h”和“zconf.h”这两个文件别忘记也要做相应的替换。
在工程的Debug和Release编译时,Zip库通过MFC共享DLL的方式链接到MFC的运行库,所以,您的工程应该也是用同样的配置方式链接到MFC运行库才可以。
您可能会根据您的特定需求来做调整。
添加Zip库到您的工程中,之后链接到Zip库,您可以使用至少两种方式(在这两种方式中,您需要包含ZipArchive.h 这个头文件,例如:#include "ZipArchive.h")Method 1Add "..\Zip\debug(release)\ZipArchive.lib" to Project Settings->Link->Input->Object/library modules and add the Zip directory to the preprocessor searches (Project Settings -> C++ -> Preprocessor -> Additional include directories).Method 2 (simpler)Insert the Zip project into the workspace and set the project dependencies (your project dependent on the Zip project).方法1:将"..\Zip\debug(release)\ZipArchive.lib" 添加到您的工程设置中,具体设置选项的位置在(vc6为版本讲解):Project Settings->Link->Input->Object/library modules,同时还要添加到preprocessor searches,具体位置在:Project Settings -> C++ -> Preprocessor -> Additional include directorie备注:当然,也可以使用代码的方式实现方法1,代码为:#pragma comment(lib,“..\Zip\debug(release)\ZipArchive.lib”)方法2:将Zip工程插入到您当前的工作区(workspace)下,同时设定工程间的编译依赖关系,编译时您的工程要依赖Zip工程How to useThe details about using this library are in the sources. The example available for download at the bottom of the page is an almost complete compression\decompression program. There are only the main issues mentioned below about using this library. If you have a question about using the library and you can't find the answer here, don't hesitate to ask.如何使用?关于本库的详细使用信息见源代码。
示例代码已提供下载,里面包含了比较完全的压缩与解压缩程序。
Compression and decompressionThere are some functions defined for fast operations on archives; amongothers: AddNewFile(), ExtractFile(), DeleteFile(). You only need to call the functions Open() - before, and Close() - after using them. Remember to callthe Close() function when you finish working with the CZipArchive class.压缩与解压缩为了更快的实现压缩与解压缩操作,这里提供一些额外的函数定义,其中包括:AddNewFile(), ExtractFile(), DeleteFile(),您仅需要在使用之前调用Open()函数进行打开操作,在使用完成结束之后调用 Close()函数即可,当您使用完CZipArchive类之后一定要记得调用Close() 函数,切记!Multi-disk archivesThis library supports two kinds of multi-disk archives:1.Disk spanning performed in the compatible way with all other main zipprograms. It means that the archive can only be created on a removabledevice, the size of the volume is auto-detected, and the label is written to the disk. To use this kind of disk spanning, you need to define a static callback function for changing disks and set it withthe SetSpanCallback() function.2.Disk spanning performed in the internal mode, called in the sources TD spanmode. This allows creating multi disk archives also on non-removabledevices and with user-defined volume size. There is no need to set thecallback function in this mode.分卷压缩该库可支持两种方式的分卷压缩:1、。