ZipArchive.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive library source distribution and
3 // is Copyrighted 2000 - 2013 by Artpol Software - Tadeusz Dracz
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // For the licensing details refer to the License.txt file.
11 //
12 // Web Site: http://www.artpol-software.com
14 // Check the site http://www.artpol-software.com for the updated version of the library.
15 //
16 // The following information files are distributed along with this library:
17 // License.txt - licensing information
18 // Appnote.txt - details on the zip format
19 // ( also available at ftp://ftp.pkware.com/appnote.zip)
20 //
21 
22 
23 
30 #if !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)
31 #define ZIPARCHIVE_ZIPARCHIVE_DOT_H
32 
33 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
34  #pragma warning (push)
35  #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
36  #pragma warning( disable : 4275 ) // non dll-interface class used as base for dll-interface
37 #endif
38 
39 #include "_features.h"
40 #include "ZipException.h"
41 #include "ZipAutoBuffer.h"
42 #include "ZipCentralDir.h"
43 #include "ZipStorage.h"
44 #include "ZipPathComponent.h"
45 #include "ZipString.h"
46 #include "ZipExport.h"
47 #include "ZipCryptograph.h"
48 #include "FileFilter.h"
49 #include "DirEnumerator.h"
50 #include "ZipCompressor.h"
51 #include "ZipCallbackProvider.h"
52 #include "BitFlag.h"
53 
54 #define ZIP_DEFAULT_CODE_PAGE UINT(-1)
55 
63 struct ZIP_API CZipAddNewFileInfo
64 {
74  CZipAddNewFileInfo(LPCTSTR lpszFilePath, bool bFullPath = true)
75  {
76  Defaults();
77  m_szFilePath = lpszFilePath;
78  m_bFullPath = bFullPath;
79  }
80 
90  CZipAddNewFileInfo(LPCTSTR lpszFilePath, LPCTSTR lpszFileNameInZip)
91  {
92  Defaults();
93  m_szFilePath = lpszFilePath;
94  m_szFileNameInZip = lpszFileNameInZip;
95  }
96 
106  CZipAddNewFileInfo(CZipAbstractFile* pFile, LPCTSTR lpszFileNameInZip)
107  {
108  Defaults();
109  m_pFile = pFile;
110  m_szFileNameInZip = lpszFileNameInZip;
111  }
112 
123  CZipAbstractFile* m_pFile;
124 
130  CZipString m_szFilePath;
131 
137  CZipString m_szFileNameInZip;
138 
152 
158 
164 
182  ZIP_INDEX_TYPE m_uReplaceIndex;
183 
187  unsigned long m_nBufSize;
188 
193  void Defaults();
194 };
195 
196 class ZIP_API CZipAddFilesEnumerator;
197 
201 class ZIP_API CZipArchive
202 {
203 public:
204  static const char m_gszCopyright[];
205  static const char m_gszVersion[];
206 
207  CZipArchive();
208 
209  virtual ~CZipArchive();
210 
237  bool SetPassword(LPCTSTR lpszPassword = NULL, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
238 
246  CZipString GetPassword()const ;
247 
265  bool WillEncryptNextFile() const
266  {
267  return m_pszPassword.GetSize() != 0 && m_iEncryptionMethod != CZipCryptograph::encNone;
268  }
269 
295  bool SetEncryptionMethod(int iEncryptionMethod = CZipCryptograph::encStandard);
296 
308  int GetEncryptionMethod() const
309  {
310  return m_iEncryptionMethod;
311  }
312 
341  bool EncryptFile(ZIP_INDEX_TYPE uIndex)
342  {
343  CZipIndexesArray aIndexes;
344  aIndexes.Add(uIndex);
345  return EncryptFilesInternal(&aIndexes);
346  }
347 
376  bool EncryptFiles(CZipIndexesArray &aIndexes)
377  {
378  return EncryptFilesInternal(&aIndexes);
379  }
380 
406  bool EncryptAllFiles()
407  {
408  return EncryptFilesInternal(NULL);
409  }
410 
436  bool SetCompressionMethod(WORD uCompressionMethod = CZipCompressor::methodDeflate);
437 
447  WORD GetCompressionMethod() const
448  {
449  return m_uCompressionMethod;
450  }
451 
471  void SetCompressionOptions(CZipCompressor::COptions* pOptions)
472  {
473  if (m_iFileOpened)
474  {
475  ZIPTRACE("%s(%i) : The options will have no effect on the current file processing.\n");
476  }
477  m_compressorsOptions.Set(pOptions);
478  }
479 
501  void SetAdvanced(int iWriteBuffer = 65536, int iGeneralBuffer = 65536, int iSearchBuffer = 32768);
502 
503 
516  void GetAdvanced(int* piWriteBuffer = NULL, int* piGeneralBuffer = NULL, int* piSearchBuffer= NULL)
517  {
518  if (piWriteBuffer)
519  *piWriteBuffer = m_storage.m_iWriteBufferSize;
520  if (piGeneralBuffer)
521  *piGeneralBuffer = m_iBufferSize;
522  if (piSearchBuffer)
523  *piSearchBuffer = m_storage.m_iLocateBufferSize;
524  }
525 
526 
547  void SetCallback(CZipActionCallback* pCallback = NULL, int iWhich = CZipActionCallback::cbAll)
548  {
549  m_callbacks.Set(pCallback, iWhich);
550  }
551 
569  {
570  return m_callbacks.Get(iWhich);
571  }
572 
580  {
581  scSpan = 0x01,
582  scSplit = 0x02,
583  scAll = scSpan | scSplit
584  };
585 
606  void SetSegmCallback(CZipSegmCallback* pCallback = NULL, int callbackType = scSpan);
607 
624  bool SetSplitNamesHandler(CZipSplitNamesHandler& names)
625  {
626  return SetSplitNamesHandler(&names, false);
627  }
628 
648  bool SetSplitNamesHandler(CZipSplitNamesHandler* pNames, bool bAutoDelete = true)
649  {
650  return m_storage.SetSplitNamesHandler(pNames, bAutoDelete);
651  }
652 
653 
658  enum OpenMode
659  {
660  zipOpen = 0x0001,
661  zipOpenReadOnly = zipOpen | 0x0002,
662  zipCreate = 0x0004,
663  zipCreateAppend = zipCreate | 0x0008,
664 
665  zipModeSplit = 0x0100, // For the internal use only.
666  zipModeBinSplit = 0x0200, // For the internal use only.
667  zipModeSpan = 0x0400, // For the internal use only.
668  zipModeSegmented = zipModeSplit | zipModeBinSplit | zipModeSpan, // For the internal use only.
669 
670  zipCreateSplit = zipCreate | zipModeSplit,
671  zipCreateBinSplit = zipCreate | zipModeBinSplit,
672  zipCreateSpan = zipCreate | zipModeSpan,
673 
674  zipOpenSplit = zipOpenReadOnly | zipModeSplit,
675  zipOpenBinSplit = zipOpenReadOnly | zipModeBinSplit
676 
677  };
678 
709  bool Open(LPCTSTR szPathName, int iMode = zipOpen, ZIP_SIZE_TYPE uVolumeSize = 0);
710 
711 
737  bool Open(CZipAbstractFile& af, int iMode = zipOpen, bool bAutoClose = false);
738 
773  bool OpenFrom(CZipArchive& zip, CZipAbstractFile* pArchiveFile = NULL, bool bAllowNonReadOnly = false);
774 
797  void SetRootPath(LPCTSTR szPath = NULL);
798 
799 
809  CZipString GetRootPath()const
810  {
811  return m_szRootPath;
812  }
813 
822  {
823  zipsmLazy = 0x0000,
824  zipsmCPassDir = 0x0001,
825  zipsmCPFile0 = 0x0002,
826 
830  zipsmNotCompSmall = 0x0004,
831 
841  zipsmCheckForEff = 0x0008,
842 
848  zipsmMemoryFlag = 0x0010,
849 
854  zipsmCheckForEffInMem = zipsmMemoryFlag | zipsmCheckForEff,
855  zipsmSmartPass = zipsmCPassDir | zipsmCPFile0,
856  zipsmSmartAdd = zipsmNotCompSmall | zipsmCheckForEff,
857  zipsmSafeSmart = zipsmSmartPass | zipsmNotCompSmall,
858  zipsmSmartest = zipsmSmartPass | zipsmSmartAdd,
859 
866  zipsmIgnoreDirectories = 0x0020,
867 
868  zipsmInternal01 = 0xf000 // For the internal use only.
869  };
870 
871 
906  bool AddNewFile(CZipAddNewFileInfo& info);
907 
908 
915  bool AddNewFile(LPCTSTR lpszFilePath, int iComprLevel = -1, bool bFullPath = true,
916  int iSmartLevel = zipsmSafeSmart, unsigned long nBufSize = 65536);
917 
918 
924  bool AddNewFile(LPCTSTR lpszFilePath,
925  LPCTSTR lpszFileNameInZip,
926  int iComprLevel = -1,
927  int iSmartLevel = zipsmSafeSmart,
928  unsigned long nBufSize = 65536);
929 
935  bool AddNewFile(CZipAbstractFile& af,
936  LPCTSTR lpszFileNameInZip,
937  int iComprLevel = -1,
938  int iSmartLevel = zipsmSafeSmart,
939  unsigned long nBufSize = 65536);
940 
941 
994  bool AddNewFiles(LPCTSTR lpszPath,
996  bool bRecursive = true,
997  int iComprLevel = -1,
998  bool bSkipInitialPath = true,
999  int iSmartLevel = zipsmSafeSmart,
1000  unsigned long nBufSize = 65536);
1001 
1048  bool AddNewFiles(LPCTSTR lpszPath,
1049  LPCTSTR lpszFileMask = _T("*.*"),
1050  bool bRecursive = true,
1051  int iComprLevel = -1,
1052  bool bSkipInitialPath = true,
1053  int iSmartLevel = zipsmSafeSmart,
1054  unsigned long nBufSize = 65536)
1055  {
1056  ZipArchiveLib::CNameFileFilter filter(lpszFileMask);
1057  return AddNewFiles(lpszPath, filter, bRecursive, iComprLevel,
1058  bSkipInitialPath, iSmartLevel, nBufSize);
1059  }
1060 
1101  bool AddNewFiles(CZipAddFilesEnumerator& addFilesEnumerator, ZipArchiveLib::CFileFilter& filter, bool bSkipInitialPath = true );
1102 
1109  ZIP_INDEX_TYPE GetLastIndexAdded() const
1110  {
1111  return m_centralDir.GetLastIndexAdded();
1112  }
1113 
1172  bool OpenNewFile(CZipFileHeader& header, int iLevel = CZipCompressor::levelDefault, LPCTSTR lpszFilePath = NULL)
1173  {
1174  return OpenNewFile(header, iLevel, lpszFilePath, ZIP_FILE_INDEX_UNSPECIFIED);
1175  }
1176 
1197  bool WriteNewFile(const void *pBuf, DWORD uSize);
1198 
1217  bool CloseNewFile(bool bAfterException = false);
1218 
1271  bool GetFromArchive(CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName = NULL, ZIP_INDEX_TYPE uReplaceIndex = ZIP_FILE_INDEX_UNSPECIFIED, bool bKeepSystComp = false)
1272  {
1273  InitBuffer();
1274  bool bRet;
1275  try
1276  {
1277  bRet = GetFromArchive(zip, uIndex, lpszNewFileName, uReplaceIndex, bKeepSystComp, GetCallback(CZipActionCallback::cbGet));
1278  }
1279  catch(...)
1280  {
1281  ReleaseBuffer();
1282  throw;
1283  }
1284  ReleaseBuffer();
1285  if (bRet)
1286  Finalize(true);
1287 
1288  return bRet;
1289  }
1290 
1337  bool GetFromArchive(CZipArchive& zip, CZipIndexesArray &aIndexes, bool bKeepSystComp = false);
1338 
1387  bool GetFromArchive(CZipArchive& zip, CZipStringArray &aNames, bool bKeepSystComp = false)
1388  {
1389  CZipIndexesArray indexes;
1390  zip.GetIndexes(aNames, indexes);
1391  return GetFromArchive(zip, indexes, bKeepSystComp);
1392  }
1393 
1412  void GetIndexes(const CZipStringArray &aNames, CZipIndexesArray& aIndexes);
1413 
1475  bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1476  LPCTSTR lpszPath,
1477  bool bFullPath = true,
1478  LPCTSTR lpszNewName = NULL,
1480  DWORD nBufSize = 65536);
1481 
1513  bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1514  CZipAbstractFile& af,
1515  bool bRewind = true,
1516  DWORD nBufSize = 65536);
1517 
1541  bool OpenFile(ZIP_INDEX_TYPE uIndex);
1542 
1561  DWORD ReadFile(void *pBuf, DWORD uSize);
1562 
1563 
1592  int CloseFile(LPCTSTR lpszFilePath = NULL, bool bAfterException = false);
1593 
1613  int CloseFile(CZipFile &file);
1614 
1636  bool TestFile(ZIP_INDEX_TYPE uIndex, DWORD uBufSize = 65536);
1637 
1665  bool RemoveFile(ZIP_INDEX_TYPE uIndex, bool bRemoveData = true);
1666 
1691  bool RemoveFiles(CZipIndexesArray& aIndexes);
1692 
1693 
1717  bool RemoveFiles(const CZipStringArray& aNames);
1718 
1742  bool ShiftData(ZIP_SIZE_TYPE uOffset);
1743 
1773  bool PrependData(LPCTSTR lpszFilePath, LPCTSTR lpszNewExt =
1774 #ifdef _ZIP_SYSTEM_WIN
1775  _T("exe")
1776 #else
1777  _T("")
1778 #endif
1779  );
1780 
1809  bool PrependData(CZipAbstractFile& file, LPCTSTR lpszNewExt = NULL);
1810 
1829  bool SetGlobalComment(LPCTSTR lpszComment, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
1830 
1831 
1843  CZipString GetGlobalComment()const ;
1844 
1845 
1854  CZipString GetArchivePath()const;
1855 
1869  ZIP_VOLUME_TYPE GetCurrentVolume() const ;
1870 
1879  {
1887 
1895 
1902  ffNoCaseSens
1903  };
1904 
1934  ZIP_INDEX_TYPE FindFile(LPCTSTR lpszFileName, int iCaseSensitive = ffDefault, bool bFileNameOnly = false);
1935 
1961  bool GetFileInfo(CZipFileHeader& fhInfo, ZIP_INDEX_TYPE uIndex) const;
1962 
1988  CZipFileHeader* GetFileInfo(ZIP_INDEX_TYPE uIndex);
1989 
2014  const CZipFileHeader* GetFileInfo(ZIP_INDEX_TYPE uIndex) const;
2015 
2040  CZipFileHeader* operator[](ZIP_INDEX_TYPE uIndex)
2041  {
2042  return GetFileInfo(uIndex);
2043  }
2044 
2068  const CZipFileHeader* operator[](ZIP_INDEX_TYPE uIndex) const
2069  {
2070  return GetFileInfo(uIndex);
2071  }
2072 
2073 
2086  ZIP_INDEX_TYPE GetCount(bool bOnlyFiles)
2087  {
2088  if (IsClosed())
2089  return 0;
2090 
2091  ZIP_INDEX_TYPE iTotalCount = GetCount();
2092  if (bOnlyFiles)
2093  {
2094  ZIP_INDEX_TYPE iCount = 0;
2095  for (ZIP_INDEX_TYPE i = 0; i < iTotalCount; i++)
2096  {
2097  if (!m_centralDir[i]->IsDirectory())
2098  iCount++;
2099  }
2100  return iCount;
2101  }
2102  else
2103  return iTotalCount;
2104  }
2105 
2113  ZIP_INDEX_TYPE GetCount() const
2114  {
2115  return (ZIP_INDEX_TYPE) m_centralDir.GetCount();
2116  }
2117 
2118 
2129  ZIP_SIZE_TYPE GetOccupiedSpace() const
2130  {
2131  if (IsClosed(true) || IsClosed(false))
2132  {
2133  ZIPTRACE("%s(%i) : ZipArchive or the current volume file is closed.\n");
2134  return 0;
2135  }
2136  return m_storage.GetOccupiedSpace() + m_centralDir.GetSize(true);
2137  }
2138 
2143  {
2148 
2155 
2161  afWriteDir
2162  };
2163 
2187  CZipString Close(int iAfterException = afNoException, bool bUpdateTimeStamp = false);
2188 
2189 
2202  bool IsClosed(bool bArchive = true)const
2203  {
2204  return m_storage.IsClosed(bArchive);
2205  }
2206 
2232  bool Finalize(bool bOnlyIfAuto = false);
2233 
2242  void FlushBuffers()
2243  {
2244  if (IsClosed())
2245  {
2246  ZIPTRACE("%s(%i) : ZipArchive should be opened first.\n");
2247  return;
2248  }
2249 
2250  m_storage.FlushBuffers();
2251  }
2252 
2253 
2271  bool SetAutoFinalize(bool bAutoFinalize = true);
2272 
2273 
2287  bool GetAutoFinalize()const {return m_bAutoFinalize;}
2288 
2316  bool SetSystemCompatibility(int iSystemComp);
2317 
2335  int GetSystemCompatibility() const {return m_iArchiveSystCompatib;}
2336 
2346  CZipStorage* GetStorage(){return &m_storage;}
2347 
2348 #ifdef _ZIP_UNICODE_CUSTOM
2349 
2366  void SetStringStoreSettings(const CZipStringStoreSettings& settings)
2367  {
2368  m_stringSettings = settings;
2369  }
2370 
2394  void SetStringStoreSettings(UINT uFileNameCodePage, bool bStoreNameInExtraData, UINT uCommentCodePage)
2395  {
2396  m_stringSettings.Set(uFileNameCodePage, bStoreNameInExtraData, uCommentCodePage);
2397  }
2398 
2420  void SetStringStoreSettings(UINT uFileNameCodePage, bool bStoreNameInExtraData = false)
2421  {
2422  SetStringStoreSettings(uFileNameCodePage, bStoreNameInExtraData, m_stringSettings.m_uCommentCodePage);
2423  }
2424 
2440  void ResetStringStoreSettings()
2441  {
2442  m_stringSettings.Reset(m_iArchiveSystCompatib);
2443  }
2444 
2464  CZipStringStoreSettings& GetStringStoreSettings()
2465  {
2466  return m_stringSettings;
2467  }
2468 #endif
2469 
2477  {
2478  umNone = 0x00,
2479 #ifdef _ZIP_UNICODE_CUSTOM
2480  umCustom = 0x04
2481 #endif
2482  };
2483 
2493  void SetUnicodeMode(int iMode){ m_centralDir.SetUnicodeMode(iMode); }
2494 
2504  int GetUnicodeMode() const { return m_centralDir.GetUnicodeMode(); }
2505 
2518  void EnableFindFast(bool bEnable = true);
2519 
2520 
2539  ZIP_INDEX_TYPE GetFindFastIndex(ZIP_INDEX_TYPE iFindFastIndex) const
2540  {
2541  if (IsClosed())
2542  {
2543  ZIPTRACE("CZipArchive::GetFindFastIndex: ZipArchive should be opened first.\n");
2544  return ZIP_FILE_INDEX_UNSPECIFIED;
2545  }
2546 
2547  return m_centralDir.GetFindFastIndex(iFindFastIndex);
2548  }
2549 
2550 
2578  void SetTempPath(LPCTSTR lpszPath = NULL, bool bForce = true);
2579 
2589  CZipString GetTempPath()const
2590  {
2591  return m_szTempPath;
2592  }
2593 
2597  enum Predict
2598  {
2599 
2602  prAuto
2603  };
2604 
2619  CZipString PredictFileNameInZip(LPCTSTR lpszFilePath, bool bFullPath, int iWhat = prAuto) const ;
2620 
2653  ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(CZipFileHeader& fh);
2654 
2672  ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(LPCTSTR lpszFilePath, bool bFullPath);
2673 
2674 
2695  ZIP_INDEX_TYPE WillBeDuplicated(LPCTSTR lpszFilePath, bool bFullPath, bool bFileNameOnly = false, int iWhat = prAuto);
2696 
2717  CZipString PredictExtractedFileName(LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath, bool bFullPath, LPCTSTR lpszNewName = NULL)const ;
2718 
2719 
2729  CZipString TrimRootPath(CZipPathComponent& zpc) const ;
2730 
2747  static bool RemovePathBeginning(LPCTSTR lpszBeginning, CZipString& szPath, ZIPSTRINGCOMPARE pCompareFunction);
2748 
2770  void SetCaseSensitivity(bool bCaseSensitive)
2771  {
2772  m_bCaseSensitive = bCaseSensitive;
2773  m_pZipCompare = GetCZipStrCompFunc(bCaseSensitive);
2774  }
2775 
2785  bool GetCaseSensitivity() const
2786  {
2787  return m_bCaseSensitive;
2788  }
2789 
2798  void GetCentralDirInfo(CZipCentralDir::CInfo& info)const;
2799 
2800 
2813  ZIP_SIZE_TYPE GetCentralDirSize(bool bWhole = true) const
2814  {
2815  if (IsClosed())
2816  {
2817  ZIPTRACE("%s(%i) : ZipArchive is closed.\n");
2818  return 0;
2819  }
2820  return m_centralDir.GetSize(bWhole);
2821  }
2822 
2831  bool IsReadOnly(){return m_storage.IsReadOnly();} const
2832 
2844  void SetBytesBeforeZip(ZIP_SIZE_TYPE uCount = 0)
2845  {
2846  if (!IsClosed())
2847  {
2848  ZIPTRACE("%s(%i) : Set it before opening the archive.\n");
2849  return;
2850  }
2851  m_storage.m_uBytesBeforeZip = uCount;
2852  }
2853 
2862  ZIP_SIZE_TYPE GetBytesBeforeZip() const
2863  {
2864  return m_storage.m_uBytesBeforeZip;
2865  }
2866 
2872  {
2874  checkCRC = 0x0001,
2875  checkLocalMethod = 0x0002,
2876  checkLocalSizes = 0x0004,
2877  checkLocalCRC = 0x0008,
2878  checkLocalFlag = 0x0010,
2879  checkLocalAll = checkLocalMethod | checkLocalSizes | checkLocalCRC | checkLocalFlag,
2880  checkDataDescriptor = 0x0100,
2881  checkVolumeEntries = 0x0200,
2882  checkDecryptionVerifier = 0x0400,
2883  checkAll = checkCRC | checkLocalAll | checkDataDescriptor | checkVolumeEntries | checkDecryptionVerifier,
2884  checkIgnoredByDefault = checkDataDescriptor | checkVolumeEntries
2885  };
2886 
2894  {
2895  sfNone,
2905  };
2906 
2919  void SetIgnoredConsistencyChecks(int iLevel = checkIgnoredByDefault)
2920  {
2921  if (IsClosed())
2922  {
2923  ZIPTRACE("%s(%i) : Set it after opening the archive.\n");
2924  return;
2925  }
2926  m_centralDir.m_iIgnoredChecks = iLevel;
2927  }
2928 
2935  int GetIgnoredConsistencyChecks() const
2936  {
2937  return m_centralDir.m_iIgnoredChecks;
2938  }
2939 
2946  void SetSpecialFlags(int iSpecialFlags)
2947  {
2948  if (!IsClosed())
2949  {
2950  ZIPTRACE("%s(%i) : Set it before opening the archive.\n");
2951  return;
2952  }
2953  m_centralDir.m_specialFlags = iSpecialFlags;
2954  }
2955 
2962  int GetSpecialFlags() const
2963  {
2964  return m_centralDir.m_specialFlags;
2965  }
2966 
2993  void FindMatches(LPCTSTR lpszPattern, CZipIndexesArray& ar, bool bFullPath = true);
2994 
3002  {
3004  cmOnChange
3005  };
3006 
3020  void SetCommitMode(int iCommitMode = cmOnChange)
3021  {
3022  m_iCommitMode = iCommitMode;
3023  }
3024 
3038  int GetCommitMode() const {return m_iCommitMode;}
3039 
3061  bool CommitChanges();
3062 
3074  bool IsModified() const {return m_centralDir.IsAnyFileModified();}
3075 
3086  bool RemoveCentralDirectoryFromArchive();
3087 
3103  bool ReadLocalHeader(ZIP_INDEX_TYPE uIndex);
3104 
3120  bool OverwriteLocalHeader(ZIP_INDEX_TYPE uIndex);
3121 
3129  const CZipCompressor* GetCurrentCompressor() const
3130  {
3131  return m_pCompressor;
3132  }
3133 
3146  bool CanModify(bool bAllowNewSegmented = false, bool bNeedsClosed = true)
3147  {
3148  if (IsClosed())
3149  {
3150  ZIPTRACE("%s(%i) : ZipArchive is closed.\n");
3151  return false;
3152  }
3153 
3154  if (m_storage.IsReadOnly())
3155  {
3156  return false;
3157  }
3158 
3159  if (m_storage.IsNewSegmented() && !bAllowNewSegmented)
3160  {
3161  return false;
3162  }
3163 
3164  if (bNeedsClosed && m_iFileOpened)
3165  {
3166  ZIPTRACE("%s(%i) : The file cannot be open during modifications.\n");
3167  return false;
3168  }
3169 
3170  return true;
3171  }
3172 
3173 
3180  bool IsPasswordSet() const
3181  {
3182  return m_pszPassword.GetSize() > 0;
3183  }
3184 
3196  bool IsFullFileTimes() const
3197  {
3198  return m_bStoreFullFileTimes;
3199  }
3200 
3209  void SetFullFileTimes(bool bFullFileTimes = true)
3210  {
3211  if (IsClosed())
3212  {
3213  ZIPTRACE("%s(%i) : Set it after opening the archive.\n");
3214  return;
3215  }
3216  m_bStoreFullFileTimes = bFullFileTimes;
3217  }
3218 
3219 
3230  bool ResetCurrentVolume();
3231 
3244  static bool IsZipArchive(LPCTSTR lpszPathName);
3245 
3261  static bool IsZipArchive(CZipAbstractFile& af, bool bAutoClose = false);
3262 
3270 
3271 protected:
3272 
3280  void ReadLocalHeaderInternal(ZIP_INDEX_TYPE uIndex)
3281  {
3282  // update sizes of the local filename and the extra field - they may differ from the ones in the central directory
3283  GetFileInfo(uIndex)->ReadLocal(&m_centralDir);
3284  }
3285 
3298  bool EncryptFilesInternal(CZipIndexesArray* pIndexes);
3299 
3300 
3312  bool OpenNewFile(CZipFileHeader & header, int iLevel, LPCTSTR lpszFilePath, ZIP_INDEX_TYPE uReplaceIndex);
3313 
3317  ZipArchiveLib::CZipCallbackProvider m_callbacks;
3318 
3319 
3323  void WriteCentralDirectory(bool bFlush = true);
3324 
3329 
3334 
3335 
3340  ZIPSTRINGCOMPARE m_pZipCompare;
3341 
3342 
3349 
3356 
3361  {
3362  extract = -1,
3364  compress
3365  };
3366 
3371 
3376 
3381 
3385  CZipString m_szRootPath;
3386 
3390  CZipString m_szTempPath;
3391 
3392 
3399  void OpenInternal(int iMode);
3400 
3411  void InitOnOpen(int iArchiveSystCompatib, CZipCentralDir* pSource = NULL);
3412 
3417 
3421  CZipAutoBuffer m_pszPassword;
3422 
3428  CZipFileHeader* CurrentFile();
3429 
3433  void ClearCryptograph()
3434  {
3435  if (m_pCryptograph)
3436  {
3437  delete m_pCryptograph;
3438  m_pCryptograph = NULL;
3439  }
3440  }
3441 
3451  virtual void CreateCryptograph(int iEncryptionMethod)
3452  {
3453  if (m_pCryptograph != NULL)
3454  if (m_pCryptograph->CanHandle(iEncryptionMethod))
3455  return;
3456 
3457  ClearCryptograph();
3458  m_pCryptograph = CZipCryptograph::CreateCryptograph(iEncryptionMethod);
3459  }
3460 
3465 
3469  void ClearCompressor()
3470  {
3471  if (m_pCompressor)
3472  {
3473  delete m_pCompressor;
3474  m_pCompressor = NULL;
3475  }
3476  }
3477 
3487  virtual void CreateCompressor(WORD uMethod)
3488  {
3489  if (m_pCompressor == NULL || !m_pCompressor->CanProcess(uMethod))
3490  {
3491  ClearCompressor();
3492  m_pCompressor = CZipCompressor::CreateCompressor(uMethod, &m_storage);
3493  }
3494  m_pCompressor->UpdateOptions(m_compressorsOptions);
3495  }
3496 
3501 
3506 
3511 
3512 
3521  CZipAutoBuffer m_pBuffer;
3522 
3532 
3533 #ifdef _ZIP_UNICODE_CUSTOM
3534 
3538 #endif
3539 
3540 private:
3541  CZipCompressor::COptionsMap m_compressorsOptions;
3542  void Initialize();
3543  void MakeSpaceForReplace(ZIP_INDEX_TYPE iReplaceIndex, ZIP_SIZE_TYPE uTotal, LPCTSTR lpszFileName);
3544 
3545  void MovePackedFiles(ZIP_SIZE_TYPE uStartOffset, ZIP_SIZE_TYPE uEndOffset, ZIP_SIZE_TYPE uMoveBy, CZipActionCallback* pCallback, bool bForward = false, bool bLastCall = true);
3546 
3547  bool RemoveLast(bool bRemoveAnyway = false);
3548 
3549  bool GetFromArchive(CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName, ZIP_INDEX_TYPE iReplaceIndex, bool bKeepSystComp, CZipActionCallback* pCallback);
3550 
3551  bool UpdateReplaceIndex(ZIP_INDEX_TYPE& iReplaceIndex);
3552 
3553  void ThrowError(int err, LPCTSTR lpszFilePath = NULL) const;
3554 
3555  void InitBuffer()
3556  {
3557  m_pBuffer.Allocate(m_iBufferSize);
3558  }
3559  void ReleaseBuffer()
3560  {
3561  m_pBuffer.Release();
3562  }
3563 };
3564 
3565 
3573 {
3574 friend class CZipArchive;
3575  CZipArchive* m_pZip;
3576 
3577 protected:
3578  CZipActionCallback* m_pMultiCallback;
3579  int m_iComprLevel;
3580  int m_iSmartLevel;
3581  unsigned long m_nBufSize;
3582 public:
3583  CZipAddFilesEnumerator(LPCTSTR lpszDirectory,
3584  bool bRecursive = true,
3585  int iComprLevel = -1,
3586  int iSmartLevel = CZipArchive::zipsmSafeSmart,
3587  unsigned long nBufSize = 65536);
3588 protected:
3589  CZipArchive* GetZip()
3590  {
3591  return m_pZip;
3592  }
3593 
3594  virtual void Initialize(CZipArchive* pZip)
3595  {
3596  m_pZip = pZip;
3597  m_pMultiCallback = m_pZip->GetCallback(CZipActionCallback::cbMultiAdd);
3598  }
3599 
3600  virtual void UpdateAddNewFileInfo(CZipAddNewFileInfo* )
3601  {
3602  }
3603 
3604  bool Process(LPCTSTR lpszPath, const ZipArchiveLib::CFileInfo& info);
3605 };
3606 
3615 {
3616 public:
3617  CReplacingAddFilesEnumerator(LPCTSTR lpszDirectory,
3618  bool bRecursive = true,
3619  int iComprLevel = -1,
3620  int iSmartLevel = CZipArchive::zipsmSafeSmart,
3621  unsigned long nBufSize = 65536)
3622  :CZipAddFilesEnumerator(lpszDirectory, bRecursive, iComprLevel, iSmartLevel, nBufSize)
3623  {
3624 
3625  }
3626 protected:
3627  void UpdateAddNewFileInfo(CZipAddNewFileInfo* info);
3628 };
3629 
3630 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
3631  #pragma warning (pop)
3632 #endif
3633 
3634 #endif // !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)

The ZipArchive Library Copyright © 2000 - 2013 Artpol Software - Tadeusz Dracz. Generated at Mon Feb 25 2013 16:29:20.