#include <zzip/zzip.h> #include <zlib.h> #include <zip.h> #include <unzip.h> #include < string> #include <map> #ifdef _debug#pragma comment (lib, "Zlib_d.lib") #pragma comment (lib, "Zzip_d.lib") # pragma comment (lib, "Minizip_d.lib") #else #pragma comment (lib, "Zlib.lib") #pragma comment (lib, "Zzip.lib") #pragma comm Ent (lib, "Minizip.lib") #endif # define Safe_deletearray (P) if (P! = NULL) {delete[] (p); (p) = NULL; };void unzipandzip (const char* pscrfilename, const char* pdstfilename) {struct file_desc{unsigned char* pData; size_t DataSize; }; Std::map<std::string, file_desc> Mapfilestreams; zzip_dir* Pzipdir = Zzip_opendir (pscrfilename); zzip_dirent* pzipdirent = NULL; while (pzipdirent = Zzip_readdir (Pzipdir)) {size_t length = strlen (Pzipdirent->d_name); if (length > 0) {if (pzipdirent->d_name[length-1]! = '//' && Pzipdirent->d_name[leng TH-1]! = '/') { zzip_file* pzipfile = Zzip_file_open (Pzipdir, Pzipdirent->d_name, zzip_caseless); if (pzipfile! = NULL) {Zzip_stat sz; memset (&sz, 0, sizeof (SZ)); Zzip_file_stat (Pzipfile, &sz); if (Sz.st_size > 0) {unsigned char* pbuffer = new unsigned char[sz.st_size]; Zzip_file_read (Pzipfile, pbuffer, sz.st_size); File_desc data = {pbuffer, sz.st_size}; Mapfilestreams[pzipdirent->d_name] = data; } zzip_file_close (Pzipfile); }}}} if (Pzipdir) Zzip_closedir (Pzipdir); Zip_fileinfo Zipfileinfo; ZipFile ZipFile = Zipopen (pdstfilename, 0); Std::map<std::string, File_desc>::iterator iter = Mapfilestreams.begin (); while (iter! = Mapfilestreams.end ()) {int err = Zipopennewfileinzip (ZipFile, Iter->first.c_str (), &zipfileinfo, N ULL, 0, NULL, 0, NULL, 0, 0); Zipwriteinfileinzip (ZipFile, Iter-> Second.pdata, Iter->second. DataSize); Safe_deletearray (Iter->second.pdata); ++iter; } zipclose (ZipFile, NULL);} int main (int argc, char* argv[]) {unzipandzip ("Test.zip", "Dst.zip"); return 0;};
Extracting files using Zzip and Minizip