ZipFile.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "StdAfx.h"
  2. #include "ZipFile.h"
  3. #include "..\ZLibWrapLib\Encoding.h"
  4. #include "io_mfc_mem.h"
  5. #define ZIP_GPBF_LANGUAGE_ENCODING_FLAG 0x800
  6. CZipFile::CZipFile(void):m_IsZipOpened(FALSE)
  7. {
  8. m_file_inzip_open =FALSE;
  9. }
  10. CZipFile::~CZipFile(void)
  11. {
  12. if(m_IsZipOpened)Close();
  13. }
  14. BOOL CZipFile::Write( void * data,int dataLen )
  15. {
  16. if(zipWriteInFileInZip(zf,data,dataLen)<0){return FALSE;}return TRUE;
  17. }
  18. BOOL CZipFile::PutNextEntry( LPCTSTR lpszFileNameInZip, bool bUtf8 /*= false*/ )
  19. {
  20. if(m_file_inzip_open){
  21. zipCloseFileInZip(zf);
  22. m_file_inzip_open =FALSE;
  23. }
  24. zip_fileinfo FileInfo;
  25. ZeroMemory(&FileInfo, sizeof(FileInfo));
  26. if (bUtf8)
  27. {
  28. //char strFileNameInZipA[1025];
  29. //WideCharToMultiByte(CP_UTF8,0,(LPCWSTR)lpszFileNameInZip,-1,strFileNameInZipA,1025,NULL,NULL);
  30. //CStringA strFileNameInZipA = UCS2ToANSI(lpszFileNameInZip, CP_UTF8);
  31. CStringA strFileNameInZipA = CT2A(lpszFileNameInZip, CP_UTF8);
  32. if (zipOpenNewFileInZip4(zf, strFileNameInZipA, &FileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9,
  33. 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, NULL, 0, 0, ZIP_GPBF_LANGUAGE_ENCODING_FLAG) != ZIP_OK)
  34. {
  35. return FALSE;
  36. }
  37. }
  38. else
  39. {
  40. //char strFileNameInZipA[1025];
  41. //WideCharToMultiByte(CP_ACP,0,(LPCWSTR)lpszFileNameInZip,-1,strFileNameInZipA,1025,NULL,NULL);
  42. //CStringA strFileNameInZipA = UCS2ToANSI(lpszFileNameInZip);
  43. CStringA strFileNameInZipA = CT2A(lpszFileNameInZip);
  44. if (zipOpenNewFileInZip(zf, strFileNameInZipA, &FileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9) != ZIP_OK)
  45. {
  46. return FALSE;
  47. }
  48. }
  49. m_file_inzip_open =TRUE;
  50. return TRUE;
  51. }
  52. void CZipFile::Close()
  53. {
  54. if(m_file_inzip_open){
  55. zipCloseFileInZip(zf);
  56. m_file_inzip_open =FALSE;
  57. }
  58. zipClose(zf,NULL);
  59. m_IsZipOpened =FALSE;
  60. }