ZipArchive.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive Library Open Source distribution
3 // and is Copyrighted 2000 - 2022 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: https://www.artpol-software.com
14 // Check the site https://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 
28 #if !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)
29 #define ZIPARCHIVE_ZIPARCHIVE_DOT_H
30 
31 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
32  #pragma warning (push)
33  #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
34  #pragma warning( disable : 4275 ) // non dll-interface class used as base for dll-interface
35 #endif
36 
37 #include "_features.h"
38 #include "ZipException.h"
39 #include "ZipAutoBuffer.h"
40 #include "ZipCentralDir.h"
41 #include "ZipStorage.h"
42 #include "ZipPathComponent.h"
43 #include "ZipString.h"
44 #include "ZipExport.h"
45 #include "ZipCryptograph.h"
46 #include "FileFilter.h"
47 #include "DirEnumerator.h"
48 #include "ZipCompressor.h"
49 #include "ZipCallbackProvider.h"
50 #include "BitFlag.h"
51 
52 #define ZIP_DEFAULT_CODE_PAGE UINT(-1)
53 
61 struct ZIP_API CZipAddNewFileInfo
62 {
72 #pragma warning(suppress: 26495)
73  CZipAddNewFileInfo(LPCTSTR lpszFilePath, bool bFullPath = true)
74  {
75  Defaults();
76  m_szFilePath = lpszFilePath;
77  m_bFullPath = bFullPath;
78  }
79 
89 #pragma warning(suppress: 26495)
90  CZipAddNewFileInfo(LPCTSTR lpszFilePath, LPCTSTR lpszFileNameInZip)
91  {
92  Defaults();
93  m_szFilePath = lpszFilePath;
94  m_szFileNameInZip = lpszFileNameInZip;
95  }
96 
106 #pragma warning(suppress: 26495)
107  CZipAddNewFileInfo(CZipAbstractFile* pFile, LPCTSTR lpszFileNameInZip)
108  {
109  Defaults();
110  m_pFile = pFile;
111  m_szFileNameInZip = lpszFileNameInZip;
112  }
113 
124  CZipAbstractFile* m_pFile;
125 
131  CZipString m_szFilePath;
132 
138  CZipString m_szFileNameInZip;
139 
153 
159 
165 
183  ZIP_INDEX_TYPE m_uReplaceIndex;
184 
188  unsigned long m_nBufSize;
189 
194  void Defaults();
195 };
196 
197 class ZIP_API CZipAddFilesEnumerator;
198 
202 class ZIP_API CZipArchive
203 {
204 public:
205  static const char m_gszCopyright[];
206  static const char m_gszVersion[];
207 
208  CZipArchive();
209 
210  virtual ~CZipArchive();
211 
238  bool SetPassword(LPCTSTR lpszPassword = NULL, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
239 
247  CZipString GetPassword()const ;
248 
266  bool WillEncryptNextFile() const
267  {
268  return m_pszPassword.GetSize() != 0 && m_iEncryptionMethod != CZipCryptograph::encNone;
269  }
270 
296  bool SetEncryptionMethod(int iEncryptionMethod = CZipCryptograph::encStandard);
297 
309  int GetEncryptionMethod() const
310  {
311  return m_iEncryptionMethod;
312  }
313 
342  bool EncryptFile(ZIP_INDEX_TYPE uIndex)
343  {
344  CZipIndexesArray aIndexes;
345  aIndexes.Add(uIndex);
346  return EncryptFilesInternal(&aIndexes);
347  }
348 
377  bool EncryptFiles(CZipIndexesArray &aIndexes)
378  {
379  return EncryptFilesInternal(&aIndexes);
380  }
381 
407  bool EncryptAllFiles()
408  {
409  return EncryptFilesInternal(NULL);
410  }
411 
437  bool SetCompressionMethod(WORD uCompressionMethod = CZipCompressor::methodDeflate);
438 
448  WORD GetCompressionMethod() const
449  {
450  return m_uCompressionMethod;
451  }
452 
472  void SetCompressionOptions(CZipCompressor::COptions* pOptions)
473  {
474  if (m_iFileOpened)
475  {
476  ZIPTRACE("%s(%i) : The options will have no effect on the current file processing.\n");
477  }
478  m_compressorsOptions.Set(pOptions);
479  }
480 
502  void SetAdvanced(int iWriteBuffer = 65536, int iGeneralBuffer = 65536, int iSearchBuffer = 32768);
503 
504 
517  void GetAdvanced(int* piWriteBuffer = NULL, int* piGeneralBuffer = NULL, int* piSearchBuffer= NULL)
518  {
519  if (piWriteBuffer)
520  *piWriteBuffer = m_storage.m_iWriteBufferSize;
521  if (piGeneralBuffer)
522  *piGeneralBuffer = m_iBufferSize;
523  if (piSearchBuffer)
524  *piSearchBuffer = m_storage.m_iLocateBufferSize;
525  }
526 
527 
548  void SetCallback(CZipActionCallback* pCallback = NULL, int iWhich = CZipActionCallback::cbAll)
549  {
550  m_callbacks.Set(pCallback, iWhich);
551  }
552 
570  {
571  return m_callbacks.Get(iWhich);
572  }
573 
581  {
582  scSpan = 0x01,
583  scSplit = 0x02,
584  scAll = scSpan | scSplit
585  };
586 
607  void SetSegmCallback(CZipSegmCallback* pCallback = NULL, int callbackType = scSpan);
608 
625  bool SetSplitNamesHandler(CZipSplitNamesHandler& names)
626  {
627  return SetSplitNamesHandler(&names, false);
628  }
629 
649  bool SetSplitNamesHandler(CZipSplitNamesHandler* pNames, bool bAutoDelete = true)
650  {
651  return m_storage.SetSplitNamesHandler(pNames, bAutoDelete);
652  }
653 
654 
659  enum OpenMode
660  {
661  zipOpen = 0x0001,
662  zipOpenReadOnly = zipOpen | 0x0002,
663  zipCreate = 0x0004,
664  zipCreateAppend = zipCreate | 0x0008,
665 
666  zipModeSplit = 0x0100, // For the internal use only.
667  zipModeBinSplit = 0x0200, // For the internal use only.
668  zipModeSpan = 0x0400, // For the internal use only.
669  zipModeSegmented = zipModeSplit | zipModeBinSplit | zipModeSpan, // For the internal use only.
670 
671  zipCreateSplit = zipCreate | zipModeSplit,
672  zipCreateBinSplit = zipCreate | zipModeBinSplit,
673  zipCreateSpan = zipCreate | zipModeSpan,
674 
675  zipOpenSplit = zipOpenReadOnly | zipModeSplit,
676  zipOpenBinSplit = zipOpenReadOnly | zipModeBinSplit
677 
678  };
679 
710  bool Open(LPCTSTR szPathName, int iMode = zipOpen, ZIP_SIZE_TYPE uVolumeSize = 0);
711 
712 
738  bool Open(CZipAbstractFile& af, int iMode = zipOpen, bool bAutoClose = false);
739 
774  bool OpenFrom(CZipArchive& zip, CZipAbstractFile* pArchiveFile = NULL, bool bAllowNonReadOnly = false);
775 
798  void SetRootPath(LPCTSTR szPath = NULL);
799 
800 
810  CZipString GetRootPath()const
811  {
812  return m_szRootPath;
813  }
814 
823  {
824  zipsmLazy = 0x0000,
825  zipsmCPassDir = 0x0001,
826  zipsmCPFile0 = 0x0002,
827 
831  zipsmNotCompSmall = 0x0004,
832 
842  zipsmCheckForEff = 0x0008,
843 
849  zipsmMemoryFlag = 0x0010,
850 
855  zipsmCheckForEffInMem = zipsmMemoryFlag | zipsmCheckForEff,
856  zipsmSmartPass = zipsmCPassDir | zipsmCPFile0,
857  zipsmSmartAdd = zipsmNotCompSmall | zipsmCheckForEff,
858  zipsmSafeSmart = zipsmSmartPass | zipsmNotCompSmall,
859  zipsmSmartest = zipsmSmartPass | zipsmSmartAdd,
860 
867  zipsmIgnoreDirectories = 0x0020,
868 
869  zipsmInternal01 = 0xf000 // For the internal use only.
870  };
871 
872 
907  bool AddNewFile(CZipAddNewFileInfo& info);
908 
909 
916  bool AddNewFile(LPCTSTR lpszFilePath, int iComprLevel = -1, bool bFullPath = true,
917  int iSmartLevel = zipsmSafeSmart, unsigned long nBufSize = 65536);
918 
919 
925  bool AddNewFile(LPCTSTR lpszFilePath,
926  LPCTSTR lpszFileNameInZip,
927  int iComprLevel = -1,
928  int iSmartLevel = zipsmSafeSmart,
929  unsigned long nBufSize = 65536);
930 
936  bool AddNewFile(CZipAbstractFile& af,
937  LPCTSTR lpszFileNameInZip,
938  int iComprLevel = -1,
939  int iSmartLevel = zipsmSafeSmart,
940  unsigned long nBufSize = 65536);
941 
942 
995  bool AddNewFiles(LPCTSTR lpszPath,
997  bool bRecursive = true,
998  int iComprLevel = -1,
999  bool bSkipInitialPath = true,
1000  int iSmartLevel = zipsmSafeSmart,
1001  unsigned long nBufSize = 65536);
1002 
1049  bool AddNewFiles(LPCTSTR lpszPath,
1050  LPCTSTR lpszFileMask = _T("*.*"),
1051  bool bRecursive = true,
1052  int iComprLevel = -1,
1053  bool bSkipInitialPath = true,
1054  int iSmartLevel = zipsmSafeSmart,
1055  unsigned long nBufSize = 65536)
1056  {
1057  ZipArchiveLib::CNameFileFilter filter(lpszFileMask);
1058  return AddNewFiles(lpszPath, filter, bRecursive, iComprLevel,
1059  bSkipInitialPath, iSmartLevel, nBufSize);
1060  }
1061 
1102  bool AddNewFiles(CZipAddFilesEnumerator& addFilesEnumerator, ZipArchiveLib::CFileFilter& filter, bool bSkipInitialPath = true );
1103 
1110  ZIP_INDEX_TYPE GetLastIndexAdded() const
1111  {
1112  return m_centralDir.GetLastIndexAdded();
1113  }
1114 
1173  bool OpenNewFile(CZipFileHeader& header, int iLevel = CZipCompressor::levelDefault, LPCTSTR lpszFilePath = NULL)
1174  {
1175  return OpenNewFile(header, iLevel, lpszFilePath, ZIP_FILE_INDEX_UNSPECIFIED);
1176  }
1177 
1198  bool WriteNewFile(const void *pBuf, DWORD uSize);
1199 
1218  bool CloseNewFile(bool bAfterException = false);
1219 
1272  bool GetFromArchive(CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName = NULL, ZIP_INDEX_TYPE uReplaceIndex = ZIP_FILE_INDEX_UNSPECIFIED, bool bKeepSystComp = false)
1273  {
1274  InitBuffer();
1275  bool bRet;
1276  try
1277  {
1278  bRet = GetFromArchive(zip, uIndex, lpszNewFileName, uReplaceIndex, bKeepSystComp, GetCallback(CZipActionCallback::cbGet));
1279  }
1280  catch(...)
1281  {
1282  ReleaseBuffer();
1283  throw;
1284  }
1285  ReleaseBuffer();
1286  if (bRet)
1287  Finalize(true);
1288 
1289  return bRet;
1290  }
1291 
1342  bool GetFromArchive(CZipArchive& zip, CZipIndexesArray &aIndexes, bool bKeepSystComp = false, bool bReplaceMode = false);
1343 
1392  bool GetFromArchive(CZipArchive& zip, CZipStringArray &aNames, bool bKeepSystComp = false)
1393  {
1394  CZipIndexesArray indexes;
1395  zip.GetIndexes(aNames, indexes);
1396  return GetFromArchive(zip, indexes, bKeepSystComp);
1397  }
1398 
1417  void GetIndexes(const CZipStringArray &aNames, CZipIndexesArray& aIndexes);
1418 
1480  bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1481  LPCTSTR lpszPath,
1482  bool bFullPath = true,
1483  LPCTSTR lpszNewName = NULL,
1485  DWORD nBufSize = 65536);
1486 
1518  bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1519  CZipAbstractFile& af,
1520  bool bRewind = true,
1521  DWORD nBufSize = 65536);
1522 
1546  bool OpenFile(ZIP_INDEX_TYPE uIndex);
1547 
1566  DWORD ReadFile(void *pBuf, DWORD uSize);
1567 
1568 
1597  int CloseFile(LPCTSTR lpszFilePath = NULL, bool bAfterException = false);
1598 
1618  int CloseFile(CZipFile &file);
1619 
1641  bool TestFile(ZIP_INDEX_TYPE uIndex, DWORD uBufSize = 65536);
1642 
1670  bool RemoveFile(ZIP_INDEX_TYPE uIndex, bool bRemoveData = true);
1671 
1696  bool RemoveFiles(CZipIndexesArray& aIndexes);
1697 
1698 
1722  bool RemoveFiles(const CZipStringArray& aNames);
1723 
1747  bool ShiftData(ZIP_SIZE_TYPE uOffset);
1748 
1778  bool PrependData(LPCTSTR lpszFilePath, LPCTSTR lpszNewExt =
1779 #ifdef _ZIP_SYSTEM_WIN
1780  _T("exe")
1781 #else
1782  _T("")
1783 #endif
1784  );
1785 
1814  bool PrependData(CZipAbstractFile& file, LPCTSTR lpszNewExt = NULL);
1815 
1834  bool SetGlobalComment(LPCTSTR lpszComment, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
1835 
1836 
1848  CZipString GetGlobalComment()const ;
1849 
1850 
1859  CZipString GetArchivePath()const;
1860 
1874  ZIP_VOLUME_TYPE GetCurrentVolume() const ;
1875 
1884  {
1892 
1900 
1907  ffNoCaseSens
1908  };
1909 
1939  ZIP_INDEX_TYPE FindFile(LPCTSTR lpszFileName, int iCaseSensitive = ffDefault, bool bFileNameOnly = false);
1940 
1966  bool GetFileInfo(CZipFileHeader& fhInfo, ZIP_INDEX_TYPE uIndex) const;
1967 
1993  CZipFileHeader* GetFileInfo(ZIP_INDEX_TYPE uIndex);
1994 
2019  const CZipFileHeader* GetFileInfo(ZIP_INDEX_TYPE uIndex) const;
2020 
2045  CZipFileHeader* operator[](ZIP_INDEX_TYPE uIndex)
2046  {
2047  return GetFileInfo(uIndex);
2048  }
2049 
2073  const CZipFileHeader* operator[](ZIP_INDEX_TYPE uIndex) const
2074  {
2075  return GetFileInfo(uIndex);
2076  }
2077 
2078 
2091  ZIP_INDEX_TYPE GetCount(bool bOnlyFiles)
2092  {
2093  if (IsClosed())
2094  return 0;
2095 
2096  ZIP_INDEX_TYPE iTotalCount = GetCount();
2097  if (bOnlyFiles)
2098  {
2099  ZIP_INDEX_TYPE iCount = 0;
2100  for (ZIP_INDEX_TYPE i = 0; i < iTotalCount; i++)
2101  {
2102  if (!m_centralDir[i]->IsDirectory())
2103  iCount++;
2104  }
2105  return iCount;
2106  }
2107  else
2108  return iTotalCount;
2109  }
2110 
2118  ZIP_INDEX_TYPE GetCount() const
2119  {
2120  return (ZIP_INDEX_TYPE) m_centralDir.GetCount();
2121  }
2122 
2123 
2134  ZIP_SIZE_TYPE GetOccupiedSpace() const
2135  {
2136  if (IsClosed(true) || IsClosed(false))
2137  {
2138  ZIPTRACE("%s(%i) : ZipArchive or the current volume file is closed.\n");
2139  return 0;
2140  }
2141  return m_storage.GetOccupiedSpace() + m_centralDir.GetSize(true);
2142  }
2143 
2148  {
2153 
2160 
2166  afWriteDir
2167  };
2168 
2192  CZipString Close(int iAfterException = afNoException, bool bUpdateTimeStamp = false);
2193 
2194 
2207  bool IsClosed(bool bArchive = true)const
2208  {
2209  return m_storage.IsClosed(bArchive);
2210  }
2211 
2237  bool Finalize(bool bOnlyIfAuto = false);
2238 
2247  void FlushBuffers()
2248  {
2249  if (IsClosed())
2250  {
2251  ZIPTRACE("%s(%i) : ZipArchive should be opened first.\n");
2252  return;
2253  }
2254 
2255  m_storage.FlushBuffers();
2256  }
2257 
2258 
2276  bool SetAutoFinalize(bool bAutoFinalize = true);
2277 
2278 
2292  bool GetAutoFinalize()const {return m_bAutoFinalize;}
2293 
2321  bool SetSystemCompatibility(int iSystemComp);
2322 
2340  int GetSystemCompatibility() const {return m_iArchiveSystCompatib;}
2341 
2351  CZipStorage* GetStorage(){return &m_storage;}
2352 
2353 #ifdef _ZIP_UNICODE_CUSTOM
2354 
2371  void SetStringStoreSettings(const CZipStringStoreSettings& settings)
2372  {
2373  m_stringSettings = settings;
2374  }
2375 
2399  void SetStringStoreSettings(UINT uFileNameCodePage, bool bStoreNameInExtraData, UINT uCommentCodePage)
2400  {
2401  m_stringSettings.Set(uFileNameCodePage, bStoreNameInExtraData, uCommentCodePage);
2402  }
2403 
2425  void SetStringStoreSettings(UINT uFileNameCodePage, bool bStoreNameInExtraData = false)
2426  {
2427  SetStringStoreSettings(uFileNameCodePage, bStoreNameInExtraData, m_stringSettings.m_uCommentCodePage);
2428  }
2429 
2445  void ResetStringStoreSettings()
2446  {
2447  m_stringSettings.Reset(m_iArchiveSystCompatib);
2448  }
2449 
2469  CZipStringStoreSettings& GetStringStoreSettings()
2470  {
2471  return m_stringSettings;
2472  }
2473 #endif
2474 
2482  {
2483  umNone = 0x00,
2484 #ifdef _ZIP_UNICODE_CUSTOM
2485  umCustom = 0x04
2486 #endif
2487  };
2488 
2498  void SetUnicodeMode(int iMode){ m_centralDir.SetUnicodeMode(iMode); }
2499 
2509  int GetUnicodeMode() const { return m_centralDir.GetUnicodeMode(); }
2510 
2523  void EnableFindFast(bool bEnable = true);
2524 
2525 
2544  ZIP_INDEX_TYPE GetFindFastIndex(ZIP_INDEX_TYPE iFindFastIndex) const
2545  {
2546  if (IsClosed())
2547  {
2548  ZIPTRACE("CZipArchive::GetFindFastIndex: ZipArchive should be opened first.\n");
2549  return ZIP_FILE_INDEX_UNSPECIFIED;
2550  }
2551 
2552  return m_centralDir.GetFindFastIndex(iFindFastIndex);
2553  }
2554 
2555 
2583  void SetTempPath(LPCTSTR lpszPath = NULL, bool bForce = true);
2584 
2594  CZipString GetTempPath()const
2595  {
2596  return m_szTempPath;
2597  }
2598 
2602  enum Predict
2603  {
2604 
2607  prAuto
2608  };
2609 
2624  CZipString PredictFileNameInZip(LPCTSTR lpszFilePath, bool bFullPath, int iWhat = prAuto) const ;
2625 
2658  ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(CZipFileHeader& fh);
2659 
2677  ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(LPCTSTR lpszFilePath, bool bFullPath);
2678 
2679 
2700  ZIP_INDEX_TYPE WillBeDuplicated(LPCTSTR lpszFilePath, bool bFullPath, bool bFileNameOnly = false, int iWhat = prAuto);
2701 
2722  CZipString PredictExtractedFileName(LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath, bool bFullPath, LPCTSTR lpszNewName = NULL)const ;
2723 
2724 
2734  CZipString TrimRootPath(CZipPathComponent& zpc) const ;
2735 
2752  static bool RemovePathBeginning(LPCTSTR lpszBeginning, CZipString& szPath, ZIPSTRINGCOMPARE pCompareFunction);
2753 
2775  void SetCaseSensitivity(bool bCaseSensitive)
2776  {
2777  m_bCaseSensitive = bCaseSensitive;
2778  m_pZipCompare = GetCZipStrCompFunc(bCaseSensitive);
2779  }
2780 
2790  bool GetCaseSensitivity() const
2791  {
2792  return m_bCaseSensitive;
2793  }
2794 
2803  void GetCentralDirInfo(CZipCentralDir::CInfo& info)const;
2804 
2805 
2818  ZIP_SIZE_TYPE GetCentralDirSize(bool bWhole = true) const
2819  {
2820  if (IsClosed())
2821  {
2822  ZIPTRACE("%s(%i) : ZipArchive is closed.\n");
2823  return 0;
2824  }
2825  return m_centralDir.GetSize(bWhole);
2826  }
2827 
2836  bool IsReadOnly(){return m_storage.IsReadOnly();} const
2837 
2849  void SetBytesBeforeZip(ZIP_SIZE_TYPE uCount = 0)
2850  {
2851  if (!IsClosed())
2852  {
2853  ZIPTRACE("%s(%i) : Set it before opening the archive.\n");
2854  return;
2855  }
2856  m_storage.m_uBytesBeforeZip = uCount;
2857  }
2858 
2867  ZIP_SIZE_TYPE GetBytesBeforeZip() const
2868  {
2869  return m_storage.m_uBytesBeforeZip;
2870  }
2871 
2877  {
2879  checkCRC = 0x0001,
2880  checkLocalMethod = 0x0002,
2881  checkLocalSizes = 0x0004,
2882  checkLocalCRC = 0x0008,
2883  checkLocalFlag = 0x0010,
2884  checkLocalAll = checkLocalMethod | checkLocalSizes | checkLocalCRC | checkLocalFlag,
2885  checkDataDescriptor = 0x0100,
2886  checkVolumeEntries = 0x0200,
2887  checkDecryptionVerifier = 0x0400,
2888  checkTrimmedCentralDir = 0x0800,
2889  checkInvalidExtraData = 0x1000,
2890  checkAll = checkCRC | checkLocalAll | checkDataDescriptor | checkVolumeEntries | checkDecryptionVerifier | checkTrimmedCentralDir | checkInvalidExtraData,
2891  checkIgnoredByDefault = checkDataDescriptor | checkVolumeEntries
2892  };
2893 
2901  {
2906 
2915  sfExhaustiveRead = 0x0001,
2916 
2917  };
2918 
2931  void SetIgnoredConsistencyChecks(int iLevel = checkIgnoredByDefault)
2932  {
2933  m_centralDir.m_iIgnoredChecks = iLevel;
2934  }
2935 
2942  int GetIgnoredConsistencyChecks() const
2943  {
2944  return m_centralDir.m_iIgnoredChecks;
2945  }
2946 
2953  void SetSpecialFlags(int iSpecialFlags)
2954  {
2955  if (!IsClosed())
2956  {
2957  ZIPTRACE("%s(%i) : Set it before opening the archive.\n");
2958  return;
2959  }
2960  m_centralDir.m_specialFlags = iSpecialFlags;
2961  }
2962 
2969  int GetSpecialFlags() const
2970  {
2971  return m_centralDir.m_specialFlags;
2972  }
2973 
3000  void FindMatches(LPCTSTR lpszPattern, CZipIndexesArray& ar, bool bFullPath = true);
3001 
3009  {
3011  cmOnChange
3012  };
3013 
3027  void SetCommitMode(int iCommitMode = cmOnChange)
3028  {
3029  m_iCommitMode = iCommitMode;
3030  }
3031 
3045  int GetCommitMode() const {return m_iCommitMode;}
3046 
3068  bool CommitChanges();
3069 
3081  bool IsModified() const {return m_centralDir.IsAnyFileModified();}
3082 
3093  bool RemoveCentralDirectoryFromArchive();
3094 
3110  bool ReadLocalHeader(ZIP_INDEX_TYPE uIndex);
3111 
3127  bool OverwriteLocalHeader(ZIP_INDEX_TYPE uIndex);
3128 
3136  const CZipCompressor* GetCurrentCompressor() const
3137  {
3138  return m_pCompressor;
3139  }
3140 
3153  bool CanModify(bool bAllowNewSegmented = false, bool bNeedsClosed = true)
3154  {
3155  if (IsClosed())
3156  {
3157  ZIPTRACE("%s(%i) : ZipArchive is closed.\n");
3158  return false;
3159  }
3160 
3161  if (m_storage.IsReadOnly())
3162  {
3163  return false;
3164  }
3165 
3166  if (m_storage.IsNewSegmented() && !bAllowNewSegmented)
3167  {
3168  return false;
3169  }
3170 
3171  if (bNeedsClosed && m_iFileOpened)
3172  {
3173  ZIPTRACE("%s(%i) : The file cannot be open during modifications.\n");
3174  return false;
3175  }
3176 
3177  return true;
3178  }
3179 
3180 
3187  bool IsPasswordSet() const
3188  {
3189  return m_pszPassword.GetSize() > 0;
3190  }
3191 
3203  bool IsFullFileTimes() const
3204  {
3205  return m_bStoreFullFileTimes;
3206  }
3207 
3216  void SetFullFileTimes(bool bFullFileTimes = true)
3217  {
3218  if (IsClosed())
3219  {
3220  ZIPTRACE("%s(%i) : Set it after opening the archive.\n");
3221  return;
3222  }
3223  m_bStoreFullFileTimes = bFullFileTimes;
3224  }
3225 
3237  bool IsUseUtcFileTimes() const
3238  {
3239  return m_bUseUtcFileTimes;
3240  }
3241 
3250  void SetUseUtcFileTimes(bool bUseUtcFileTimes = true)
3251  {
3252  if (IsClosed())
3253  {
3254  ZIPTRACE("%s(%i) : Set it after opening the archive.\n");
3255  return;
3256  }
3257  m_bUseUtcFileTimes = bUseUtcFileTimes;
3258  }
3259 
3260 
3271  bool ResetCurrentVolume();
3272 
3285  static bool IsZipArchive(LPCTSTR lpszPathName);
3286 
3302  static bool IsZipArchive(CZipAbstractFile& af, bool bAutoClose = false);
3303 
3311 
3312 protected:
3313 
3321  void ReadLocalHeaderInternal(ZIP_INDEX_TYPE uIndex)
3322  {
3323  // update sizes of the local filename and the extra field - they may differ from the ones in the central directory
3324  GetFileInfo(uIndex)->ReadLocal(&m_centralDir);
3325  }
3326 
3339  bool EncryptFilesInternal(CZipIndexesArray* pIndexes);
3340 
3341 
3353  bool OpenNewFile(CZipFileHeader & header, int iLevel, LPCTSTR lpszFilePath, ZIP_INDEX_TYPE uReplaceIndex);
3354 
3358  ZipArchiveLib::CZipCallbackProvider m_callbacks;
3359 
3360 
3364  void WriteCentralDirectory(bool bFlush = true);
3365 
3370 
3375 
3376 
3381 
3382 
3387  ZIPSTRINGCOMPARE m_pZipCompare;
3388 
3389 
3396 
3403 
3408  {
3409  extract = -1,
3411  compress
3412  };
3413 
3418 
3423 
3428 
3432  CZipString m_szRootPath;
3433 
3437  CZipString m_szTempPath;
3438 
3439 
3446  void OpenInternal(int iMode);
3447 
3458  void InitOnOpen(int iArchiveSystCompatib, CZipCentralDir* pSource = NULL);
3459 
3464 
3468  CZipAutoBuffer m_pszPassword;
3469 
3475  CZipFileHeader* CurrentFile();
3476 
3480  void ClearCryptograph()
3481  {
3482  if (m_pCryptograph)
3483  {
3484  delete m_pCryptograph;
3485  m_pCryptograph = NULL;
3486  }
3487  }
3488 
3498  virtual void CreateCryptograph(int iEncryptionMethod)
3499  {
3500  if (m_pCryptograph != NULL)
3501  if (m_pCryptograph->CanHandle(iEncryptionMethod))
3502  return;
3503 
3504  ClearCryptograph();
3505  m_pCryptograph = CZipCryptograph::CreateCryptograph(iEncryptionMethod);
3506  }
3507 
3512 
3516  void ClearCompressor()
3517  {
3518  if (m_pCompressor)
3519  {
3520  delete m_pCompressor;
3521  m_pCompressor = NULL;
3522  }
3523  }
3524 
3534  virtual void CreateCompressor(WORD uMethod)
3535  {
3536  if (m_pCompressor == NULL || !m_pCompressor->CanProcess(uMethod))
3537  {
3538  ClearCompressor();
3539  m_pCompressor = CZipCompressor::CreateCompressor(uMethod, &m_storage);
3540  }
3541  m_pCompressor->UpdateOptions(m_compressorsOptions);
3542  }
3543 
3548 
3553 
3558 
3559 
3568  CZipAutoBuffer m_pBuffer;
3569 
3579 
3580 #ifdef _ZIP_UNICODE_CUSTOM
3581 
3585 #endif
3586 
3587 private:
3588  CZipCompressor::COptionsMap m_compressorsOptions;
3589  void Initialize();
3590  void MakeSpaceForReplace(ZIP_INDEX_TYPE iReplaceIndex, ZIP_SIZE_TYPE uTotal, LPCTSTR lpszFileName);
3591 
3592  void MovePackedFiles(ZIP_SIZE_TYPE uStartOffset, ZIP_SIZE_TYPE uEndOffset, ZIP_SIZE_TYPE uMoveBy, CZipActionCallback* pCallback, bool bForward = false, bool bLastCall = true);
3593 
3594  bool RemoveLast(bool bRemoveAnyway = false);
3595 
3596  bool GetFromArchive(CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName, ZIP_INDEX_TYPE iReplaceIndex, bool bKeepSystComp, CZipActionCallback* pCallback);
3597 
3598  bool UpdateReplaceIndex(ZIP_INDEX_TYPE& iReplaceIndex);
3599 
3600  void ThrowError(int err, LPCTSTR lpszFilePath = NULL) const;
3601 
3602  void InitBuffer()
3603  {
3604  m_pBuffer.Allocate(m_iBufferSize);
3605  }
3606  void ReleaseBuffer()
3607  {
3608  m_pBuffer.Release();
3609  }
3610 };
3611 
3612 
3620 {
3621 friend class CZipArchive;
3622  CZipArchive* m_pZip;
3623 
3624 protected:
3625  CZipActionCallback* m_pMultiCallback;
3626  int m_iComprLevel;
3627  int m_iSmartLevel;
3628  unsigned long m_nBufSize;
3629 public:
3630  CZipAddFilesEnumerator(LPCTSTR lpszDirectory,
3631  bool bRecursive = true,
3632  int iComprLevel = -1,
3633  int iSmartLevel = CZipArchive::zipsmSafeSmart,
3634  unsigned long nBufSize = 65536);
3635 protected:
3636  CZipArchive* GetZip()
3637  {
3638  return m_pZip;
3639  }
3640 
3641  virtual void Initialize(CZipArchive* pZip)
3642  {
3643  m_pZip = pZip;
3644  m_pMultiCallback = m_pZip->GetCallback(CZipActionCallback::cbMultiAdd);
3645  }
3646 
3647  virtual void UpdateAddNewFileInfo(CZipAddNewFileInfo* )
3648  {
3649  }
3650 
3651  bool Process(LPCTSTR lpszPath, const ZipArchiveLib::CFileInfo& info);
3652 };
3653 
3662 {
3663 public:
3664  CReplacingAddFilesEnumerator(LPCTSTR lpszDirectory,
3665  bool bRecursive = true,
3666  int iComprLevel = -1,
3667  int iSmartLevel = CZipArchive::zipsmSafeSmart,
3668  unsigned long nBufSize = 65536)
3669  :CZipAddFilesEnumerator(lpszDirectory, bRecursive, iComprLevel, iSmartLevel, nBufSize)
3670  {
3671 
3672  }
3673 protected:
3674  void UpdateAddNewFileInfo(CZipAddNewFileInfo* info);
3675 };
3676 
3677 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
3678  #pragma warning (pop)
3679 #endif
3680 
3681 #endif // !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)

The ZipArchive Library Copyright © 2000 - 2022 Artpol Software - Tadeusz Dracz. Generated at Sat Dec 17 2022 19:57:03.