123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include "StdAfx.h"
- #include "ZipFile.h"
- #include "..\ZLibWrapLib\Encoding.h"
- #include "io_mfc_mem.h"
- #define ZIP_GPBF_LANGUAGE_ENCODING_FLAG 0x800
- CZipFile::CZipFile(void):m_IsZipOpened(FALSE)
- {
- m_file_inzip_open =FALSE;
- }
- CZipFile::~CZipFile(void)
- {
- if(m_IsZipOpened)Close();
- }
- BOOL CZipFile::Write( void * data,int dataLen )
- {
- if(zipWriteInFileInZip(zf,data,dataLen)<0){return FALSE;}return TRUE;
- }
- BOOL CZipFile::PutNextEntry( LPCTSTR lpszFileNameInZip, bool bUtf8 /*= false*/ )
- {
- if(m_file_inzip_open){
- zipCloseFileInZip(zf);
- m_file_inzip_open =FALSE;
- }
- zip_fileinfo FileInfo;
- ZeroMemory(&FileInfo, sizeof(FileInfo));
- if (bUtf8)
- {
- //char strFileNameInZipA[1025];
- //WideCharToMultiByte(CP_UTF8,0,(LPCWSTR)lpszFileNameInZip,-1,strFileNameInZipA,1025,NULL,NULL);
- //CStringA strFileNameInZipA = UCS2ToANSI(lpszFileNameInZip, CP_UTF8);
- CStringA strFileNameInZipA = CT2A(lpszFileNameInZip, CP_UTF8);
- if (zipOpenNewFileInZip4(zf, strFileNameInZipA, &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
- {
- //char strFileNameInZipA[1025];
- //WideCharToMultiByte(CP_ACP,0,(LPCWSTR)lpszFileNameInZip,-1,strFileNameInZipA,1025,NULL,NULL);
- //CStringA strFileNameInZipA = UCS2ToANSI(lpszFileNameInZip);
- CStringA strFileNameInZipA = CT2A(lpszFileNameInZip);
- if (zipOpenNewFileInZip(zf, strFileNameInZipA, &FileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9) != ZIP_OK)
- {
- return FALSE;
- }
- }
- m_file_inzip_open =TRUE;
- return TRUE;
- }
- void CZipFile::Close()
- {
- if(m_file_inzip_open){
- zipCloseFileInZip(zf);
- m_file_inzip_open =FALSE;
- }
- zipClose(zf,NULL);
- m_IsZipOpened =FALSE;
- }
|