28 #if !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)
29 #define ZIPARCHIVE_ZIPARCHIVE_DOT_H
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
37 #include "_features.h"
39 #include "ZipAutoBuffer.h"
43 #include "ZipString.h"
44 #include "ZipExport.h"
49 #include "ZipCallbackProvider.h"
52 #define ZIP_DEFAULT_CODE_PAGE UINT(-1)
72 #pragma warning(suppress: 26495)
76 m_szFilePath = lpszFilePath;
77 m_bFullPath = bFullPath;
89 #pragma warning(suppress: 26495)
93 m_szFilePath = lpszFilePath;
94 m_szFileNameInZip = lpszFileNameInZip;
106 #pragma warning(suppress: 26495)
111 m_szFileNameInZip = lpszFileNameInZip;
205 static const char m_gszCopyright[];
206 static const char m_gszVersion[];
238 bool SetPassword(LPCTSTR lpszPassword = NULL, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
247 CZipString GetPassword()
const ;
266 bool WillEncryptNextFile()
const
309 int GetEncryptionMethod()
const
311 return m_iEncryptionMethod;
342 bool EncryptFile(ZIP_INDEX_TYPE uIndex)
344 CZipIndexesArray aIndexes;
345 aIndexes.Add(uIndex);
346 return EncryptFilesInternal(&aIndexes);
377 bool EncryptFiles(CZipIndexesArray &aIndexes)
379 return EncryptFilesInternal(&aIndexes);
407 bool EncryptAllFiles()
409 return EncryptFilesInternal(NULL);
448 WORD GetCompressionMethod()
const
450 return m_uCompressionMethod;
476 ZIPTRACE(
"%s(%i) : The options will have no effect on the current file processing.\n");
478 m_compressorsOptions.Set(pOptions);
502 void SetAdvanced(
int iWriteBuffer = 65536,
int iGeneralBuffer = 65536,
int iSearchBuffer = 32768);
517 void GetAdvanced(
int* piWriteBuffer = NULL,
int* piGeneralBuffer = NULL,
int* piSearchBuffer= NULL)
520 *piWriteBuffer = m_storage.m_iWriteBufferSize;
522 *piGeneralBuffer = m_iBufferSize;
524 *piSearchBuffer = m_storage.m_iLocateBufferSize;
550 m_callbacks.Set(pCallback, iWhich);
571 return m_callbacks.Get(iWhich);
584 scAll = scSpan | scSplit
607 void SetSegmCallback(
CZipSegmCallback* pCallback = NULL,
int callbackType = scSpan);
627 return SetSplitNamesHandler(&names,
false);
651 return m_storage.SetSplitNamesHandler(pNames, bAutoDelete);
662 zipOpenReadOnly = zipOpen | 0x0002,
664 zipCreateAppend = zipCreate | 0x0008,
666 zipModeSplit = 0x0100,
667 zipModeBinSplit = 0x0200,
668 zipModeSpan = 0x0400,
669 zipModeSegmented = zipModeSplit | zipModeBinSplit | zipModeSpan,
671 zipCreateSplit = zipCreate | zipModeSplit,
672 zipCreateBinSplit = zipCreate | zipModeBinSplit,
673 zipCreateSpan = zipCreate | zipModeSpan,
675 zipOpenSplit = zipOpenReadOnly | zipModeSplit,
676 zipOpenBinSplit = zipOpenReadOnly | zipModeBinSplit
710 bool Open(LPCTSTR szPathName,
int iMode = zipOpen, ZIP_SIZE_TYPE uVolumeSize = 0);
738 bool Open(CZipAbstractFile& af,
int iMode = zipOpen,
bool bAutoClose =
false);
774 bool OpenFrom(
CZipArchive& zip, CZipAbstractFile* pArchiveFile = NULL,
bool bAllowNonReadOnly =
false);
798 void SetRootPath(LPCTSTR szPath = NULL);
810 CZipString GetRootPath()
const
825 zipsmCPassDir = 0x0001,
826 zipsmCPFile0 = 0x0002,
831 zipsmNotCompSmall = 0x0004,
842 zipsmCheckForEff = 0x0008,
849 zipsmMemoryFlag = 0x0010,
855 zipsmCheckForEffInMem = zipsmMemoryFlag | zipsmCheckForEff,
856 zipsmSmartPass = zipsmCPassDir | zipsmCPFile0,
857 zipsmSmartAdd = zipsmNotCompSmall | zipsmCheckForEff,
858 zipsmSafeSmart = zipsmSmartPass | zipsmNotCompSmall,
859 zipsmSmartest = zipsmSmartPass | zipsmSmartAdd,
867 zipsmIgnoreDirectories = 0x0020,
869 zipsmInternal01 = 0xf000
916 bool AddNewFile(LPCTSTR lpszFilePath,
int iComprLevel = -1,
bool bFullPath =
true,
917 int iSmartLevel = zipsmSafeSmart,
unsigned long nBufSize = 65536);
925 bool AddNewFile(LPCTSTR lpszFilePath,
926 LPCTSTR lpszFileNameInZip,
927 int iComprLevel = -1,
928 int iSmartLevel = zipsmSafeSmart,
929 unsigned long nBufSize = 65536);
936 bool AddNewFile(CZipAbstractFile& af,
937 LPCTSTR lpszFileNameInZip,
938 int iComprLevel = -1,
939 int iSmartLevel = zipsmSafeSmart,
940 unsigned long nBufSize = 65536);
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);
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)
1058 return AddNewFiles(lpszPath, filter, bRecursive, iComprLevel,
1059 bSkipInitialPath, iSmartLevel, nBufSize);
1110 ZIP_INDEX_TYPE GetLastIndexAdded()
const
1112 return m_centralDir.GetLastIndexAdded();
1175 return OpenNewFile(header, iLevel, lpszFilePath, ZIP_FILE_INDEX_UNSPECIFIED);
1198 bool WriteNewFile(
const void *pBuf, DWORD uSize);
1218 bool CloseNewFile(
bool bAfterException =
false);
1272 bool GetFromArchive(
CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName = NULL, ZIP_INDEX_TYPE uReplaceIndex = ZIP_FILE_INDEX_UNSPECIFIED,
bool bKeepSystComp =
false)
1278 bRet = GetFromArchive(zip, uIndex, lpszNewFileName, uReplaceIndex, bKeepSystComp, GetCallback(
CZipActionCallback::cbGet));
1342 bool GetFromArchive(
CZipArchive& zip, CZipIndexesArray &aIndexes,
bool bKeepSystComp =
false,
bool bReplaceMode =
false);
1392 bool GetFromArchive(
CZipArchive& zip, CZipStringArray &aNames,
bool bKeepSystComp =
false)
1394 CZipIndexesArray indexes;
1396 return GetFromArchive(zip, indexes, bKeepSystComp);
1417 void GetIndexes(
const CZipStringArray &aNames, CZipIndexesArray& aIndexes);
1480 bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1482 bool bFullPath =
true,
1483 LPCTSTR lpszNewName = NULL,
1485 DWORD nBufSize = 65536);
1518 bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1519 CZipAbstractFile& af,
1520 bool bRewind =
true,
1521 DWORD nBufSize = 65536);
1546 bool OpenFile(ZIP_INDEX_TYPE uIndex);
1566 DWORD ReadFile(
void *pBuf, DWORD uSize);
1597 int CloseFile(LPCTSTR lpszFilePath = NULL,
bool bAfterException =
false);
1618 int CloseFile(CZipFile &file);
1641 bool TestFile(ZIP_INDEX_TYPE uIndex, DWORD uBufSize = 65536);
1670 bool RemoveFile(ZIP_INDEX_TYPE uIndex,
bool bRemoveData =
true);
1696 bool RemoveFiles(CZipIndexesArray& aIndexes);
1722 bool RemoveFiles(
const CZipStringArray& aNames);
1747 bool ShiftData(ZIP_SIZE_TYPE uOffset);
1778 bool PrependData(LPCTSTR lpszFilePath, LPCTSTR lpszNewExt =
1779 #ifdef _ZIP_SYSTEM_WIN
1814 bool PrependData(CZipAbstractFile& file, LPCTSTR lpszNewExt = NULL);
1834 bool SetGlobalComment(LPCTSTR lpszComment, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
1848 CZipString GetGlobalComment()
const ;
1859 CZipString GetArchivePath()
const;
1874 ZIP_VOLUME_TYPE GetCurrentVolume()
const ;
1939 ZIP_INDEX_TYPE FindFile(LPCTSTR lpszFileName,
int iCaseSensitive = ffDefault,
bool bFileNameOnly =
false);
1966 bool GetFileInfo(
CZipFileHeader& fhInfo, ZIP_INDEX_TYPE uIndex)
const;
2047 return GetFileInfo(uIndex);
2075 return GetFileInfo(uIndex);
2091 ZIP_INDEX_TYPE GetCount(
bool bOnlyFiles)
2096 ZIP_INDEX_TYPE iTotalCount = GetCount();
2099 ZIP_INDEX_TYPE iCount = 0;
2100 for (ZIP_INDEX_TYPE i = 0; i < iTotalCount; i++)
2118 ZIP_INDEX_TYPE GetCount()
const
2120 return (ZIP_INDEX_TYPE) m_centralDir.GetCount();
2134 ZIP_SIZE_TYPE GetOccupiedSpace()
const
2136 if (IsClosed(
true) || IsClosed(
false))
2138 ZIPTRACE(
"%s(%i) : ZipArchive or the current volume file is closed.\n");
2141 return m_storage.GetOccupiedSpace() + m_centralDir.GetSize(
true);
2192 CZipString Close(
int iAfterException = afNoException,
bool bUpdateTimeStamp =
false);
2207 bool IsClosed(
bool bArchive =
true)
const
2209 return m_storage.IsClosed(bArchive);
2237 bool Finalize(
bool bOnlyIfAuto =
false);
2251 ZIPTRACE(
"%s(%i) : ZipArchive should be opened first.\n");
2255 m_storage.FlushBuffers();
2276 bool SetAutoFinalize(
bool bAutoFinalize =
true);
2321 bool SetSystemCompatibility(
int iSystemComp);
2353 #ifdef _ZIP_UNICODE_CUSTOM
2373 m_stringSettings = settings;
2399 void SetStringStoreSettings(UINT uFileNameCodePage,
bool bStoreNameInExtraData, UINT uCommentCodePage)
2401 m_stringSettings.
Set(uFileNameCodePage, bStoreNameInExtraData, uCommentCodePage);
2425 void SetStringStoreSettings(UINT uFileNameCodePage,
bool bStoreNameInExtraData =
false)
2427 SetStringStoreSettings(uFileNameCodePage, bStoreNameInExtraData, m_stringSettings.m_uCommentCodePage);
2445 void ResetStringStoreSettings()
2447 m_stringSettings.Reset(m_iArchiveSystCompatib);
2471 return m_stringSettings;
2484 #ifdef _ZIP_UNICODE_CUSTOM
2523 void EnableFindFast(
bool bEnable =
true);
2544 ZIP_INDEX_TYPE GetFindFastIndex(ZIP_INDEX_TYPE iFindFastIndex)
const
2548 ZIPTRACE(
"CZipArchive::GetFindFastIndex: ZipArchive should be opened first.\n");
2549 return ZIP_FILE_INDEX_UNSPECIFIED;
2552 return m_centralDir.GetFindFastIndex(iFindFastIndex);
2583 void SetTempPath(LPCTSTR lpszPath = NULL,
bool bForce =
true);
2594 CZipString GetTempPath()
const
2596 return m_szTempPath;
2624 CZipString PredictFileNameInZip(LPCTSTR lpszFilePath,
bool bFullPath,
int iWhat = prAuto)
const ;
2658 ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(
CZipFileHeader& fh);
2677 ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(LPCTSTR lpszFilePath,
bool bFullPath);
2700 ZIP_INDEX_TYPE WillBeDuplicated(LPCTSTR lpszFilePath,
bool bFullPath,
bool bFileNameOnly =
false,
int iWhat = prAuto);
2722 CZipString PredictExtractedFileName(LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath,
bool bFullPath, LPCTSTR lpszNewName = NULL)
const ;
2752 static bool RemovePathBeginning(LPCTSTR lpszBeginning, CZipString& szPath, ZIPSTRINGCOMPARE pCompareFunction);
2775 void SetCaseSensitivity(
bool bCaseSensitive)
2777 m_bCaseSensitive = bCaseSensitive;
2778 m_pZipCompare = GetCZipStrCompFunc(bCaseSensitive);
2790 bool GetCaseSensitivity()
const
2792 return m_bCaseSensitive;
2818 ZIP_SIZE_TYPE GetCentralDirSize(
bool bWhole =
true)
const
2822 ZIPTRACE(
"%s(%i) : ZipArchive is closed.\n");
2825 return m_centralDir.GetSize(bWhole);
2849 void SetBytesBeforeZip(ZIP_SIZE_TYPE uCount = 0)
2853 ZIPTRACE(
"%s(%i) : Set it before opening the archive.\n");
2856 m_storage.m_uBytesBeforeZip = uCount;
2867 ZIP_SIZE_TYPE GetBytesBeforeZip()
const
2869 return m_storage.m_uBytesBeforeZip;
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
2915 sfExhaustiveRead = 0x0001,
2931 void SetIgnoredConsistencyChecks(
int iLevel = checkIgnoredByDefault)
2933 m_centralDir.m_iIgnoredChecks = iLevel;
2942 int GetIgnoredConsistencyChecks()
const
2944 return m_centralDir.m_iIgnoredChecks;
2953 void SetSpecialFlags(
int iSpecialFlags)
2957 ZIPTRACE(
"%s(%i) : Set it before opening the archive.\n");
2960 m_centralDir.m_specialFlags = iSpecialFlags;
2969 int GetSpecialFlags()
const
2971 return m_centralDir.m_specialFlags;
3000 void FindMatches(LPCTSTR lpszPattern, CZipIndexesArray& ar,
bool bFullPath =
true);
3027 void SetCommitMode(
int iCommitMode = cmOnChange)
3029 m_iCommitMode = iCommitMode;
3068 bool CommitChanges();
3081 bool IsModified()
const {
return m_centralDir.IsAnyFileModified();}
3093 bool RemoveCentralDirectoryFromArchive();
3110 bool ReadLocalHeader(ZIP_INDEX_TYPE uIndex);
3127 bool OverwriteLocalHeader(ZIP_INDEX_TYPE uIndex);
3138 return m_pCompressor;
3153 bool CanModify(
bool bAllowNewSegmented =
false,
bool bNeedsClosed =
true)
3157 ZIPTRACE(
"%s(%i) : ZipArchive is closed.\n");
3161 if (m_storage.IsReadOnly())
3166 if (m_storage.IsNewSegmented() && !bAllowNewSegmented)
3171 if (bNeedsClosed && m_iFileOpened)
3173 ZIPTRACE(
"%s(%i) : The file cannot be open during modifications.\n");
3187 bool IsPasswordSet()
const
3189 return m_pszPassword.GetSize() > 0;
3203 bool IsFullFileTimes()
const
3205 return m_bStoreFullFileTimes;
3216 void SetFullFileTimes(
bool bFullFileTimes =
true)
3220 ZIPTRACE(
"%s(%i) : Set it after opening the archive.\n");
3223 m_bStoreFullFileTimes = bFullFileTimes;
3237 bool IsUseUtcFileTimes()
const
3239 return m_bUseUtcFileTimes;
3250 void SetUseUtcFileTimes(
bool bUseUtcFileTimes =
true)
3254 ZIPTRACE(
"%s(%i) : Set it after opening the archive.\n");
3257 m_bUseUtcFileTimes = bUseUtcFileTimes;
3271 bool ResetCurrentVolume();
3285 static bool IsZipArchive(LPCTSTR lpszPathName);
3302 static bool IsZipArchive(CZipAbstractFile& af,
bool bAutoClose =
false);
3321 void ReadLocalHeaderInternal(ZIP_INDEX_TYPE uIndex)
3324 GetFileInfo(uIndex)->ReadLocal(&m_centralDir);
3339 bool EncryptFilesInternal(CZipIndexesArray* pIndexes);
3353 bool OpenNewFile(
CZipFileHeader & header,
int iLevel, LPCTSTR lpszFilePath, ZIP_INDEX_TYPE uReplaceIndex);
3364 void WriteCentralDirectory(
bool bFlush =
true);
3446 void OpenInternal(
int iMode);
3458 void InitOnOpen(
int iArchiveSystCompatib,
CZipCentralDir* pSource = NULL);
3480 void ClearCryptograph()
3484 delete m_pCryptograph;
3485 m_pCryptograph = NULL;
3498 virtual void CreateCryptograph(
int iEncryptionMethod)
3500 if (m_pCryptograph != NULL)
3501 if (m_pCryptograph->CanHandle(iEncryptionMethod))
3516 void ClearCompressor()
3520 delete m_pCompressor;
3521 m_pCompressor = NULL;
3534 virtual void CreateCompressor(WORD uMethod)
3536 if (m_pCompressor == NULL || !m_pCompressor->CanProcess(uMethod))
3541 m_pCompressor->UpdateOptions(m_compressorsOptions);
3580 #ifdef _ZIP_UNICODE_CUSTOM
3590 void MakeSpaceForReplace(ZIP_INDEX_TYPE iReplaceIndex, ZIP_SIZE_TYPE uTotal, LPCTSTR lpszFileName);
3592 void MovePackedFiles(ZIP_SIZE_TYPE uStartOffset, ZIP_SIZE_TYPE uEndOffset, ZIP_SIZE_TYPE uMoveBy,
CZipActionCallback* pCallback,
bool bForward =
false,
bool bLastCall =
true);
3594 bool RemoveLast(
bool bRemoveAnyway =
false);
3596 bool GetFromArchive(
CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName, ZIP_INDEX_TYPE iReplaceIndex,
bool bKeepSystComp,
CZipActionCallback* pCallback);
3598 bool UpdateReplaceIndex(ZIP_INDEX_TYPE& iReplaceIndex);
3600 void ThrowError(
int err, LPCTSTR lpszFilePath = NULL)
const;
3604 m_pBuffer.Allocate(m_iBufferSize);
3606 void ReleaseBuffer()
3608 m_pBuffer.Release();
3628 unsigned long m_nBufSize;
3631 bool bRecursive =
true,
3632 int iComprLevel = -1,
3634 unsigned long nBufSize = 65536);
3665 bool bRecursive =
true,
3666 int iComprLevel = -1,
3668 unsigned long nBufSize = 65536)
3677 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
3678 #pragma warning (pop)
3681 #endif // !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)