123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include "ZipFile.h"
- #include "zlib/zip.h"
- CZipFile::CZipFile(void):m_IsZipOpened(false)
- {
- m_file_inzip_open =false;
- }
- CZipFile::~CZipFile(void)
- {
- if(m_IsZipOpened)CloseZip();
- }
- bool CZipFile::PutNextEntry( std::string lpszFileNameInZip, bool bUtf8 /*= false*/ )
- {
- #define ZIP_GPBF_LANGUAGE_ENCODING_FLAG 0x800
- if(m_file_inzip_open){
- zipCloseFileInZip(zf);
- m_file_inzip_open =false;
- }
- zip_fileinfo FileInfo;
- memset(&FileInfo, 0,sizeof(FileInfo));
- if (bUtf8)
- {
- return false;
- std::wstring wideStr ;
- std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
- std::string utf8 = conv.to_bytes(wideStr);
- if (zipOpenNewFileInZip4(zf, utf8.c_str(), &FileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9,
- 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, NULL, 0, 0, ZIP_GPBF_LANGUAGE_ENCODING_FLAG) != ZIP_OK)
- {
- return false;
- }
- }
- else
- {
- if (zipOpenNewFileInZip(zf, lpszFileNameInZip.c_str(), &FileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9) != ZIP_OK)
- {
- return false;
- }
- }
- m_file_inzip_open =true;
- return true;
- }
- void CZipFile::CloseZip()
- {
- if(m_file_inzip_open){
- zipCloseFileInZip(zf);
- m_file_inzip_open =false;
- }
- zipClose(zf,NULL);
- m_IsZipOpened =false;
- }
- bool CZipFile::Write( void * data,int dataLen )
- {
- return zipWriteInFileInZip(zf,data,dataLen)==ZIP_OK;
- }
- void CZipFile::OpenZip()
- {
- zf=zipOpen2(NULL,0,NULL,(zlib_filefunc_def*)m_pzlib_filefunc_def);
- m_IsZipOpened =true;
- }
|