30 #if !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)
31 #define ZIPARCHIVE_ZIPARCHIVE_DOT_H
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
39 #include "_features.h"
41 #include "ZipAutoBuffer.h"
45 #include "ZipString.h"
46 #include "ZipExport.h"
51 #include "ZipCallbackProvider.h"
54 #define ZIP_DEFAULT_CODE_PAGE UINT(-1)
77 m_szFilePath = lpszFilePath;
78 m_bFullPath = bFullPath;
93 m_szFilePath = lpszFilePath;
94 m_szFileNameInZip = lpszFileNameInZip;
110 m_szFileNameInZip = lpszFileNameInZip;
204 static const char m_gszCopyright[];
205 static const char m_gszVersion[];
237 bool SetPassword(LPCTSTR lpszPassword = NULL, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
246 CZipString GetPassword()
const ;
265 bool WillEncryptNextFile()
const
308 int GetEncryptionMethod()
const
310 return m_iEncryptionMethod;
341 bool EncryptFile(ZIP_INDEX_TYPE uIndex)
343 CZipIndexesArray aIndexes;
344 aIndexes.Add(uIndex);
345 return EncryptFilesInternal(&aIndexes);
376 bool EncryptFiles(CZipIndexesArray &aIndexes)
378 return EncryptFilesInternal(&aIndexes);
406 bool EncryptAllFiles()
408 return EncryptFilesInternal(NULL);
447 WORD GetCompressionMethod()
const
449 return m_uCompressionMethod;
475 ZIPTRACE(
"%s(%i) : The options will have no effect on the current file processing.\n");
477 m_compressorsOptions.Set(pOptions);
501 void SetAdvanced(
int iWriteBuffer = 65536,
int iGeneralBuffer = 65536,
int iSearchBuffer = 32768);
516 void GetAdvanced(
int* piWriteBuffer = NULL,
int* piGeneralBuffer = NULL,
int* piSearchBuffer= NULL)
519 *piWriteBuffer = m_storage.m_iWriteBufferSize;
521 *piGeneralBuffer = m_iBufferSize;
523 *piSearchBuffer = m_storage.m_iLocateBufferSize;
549 m_callbacks.Set(pCallback, iWhich);
570 return m_callbacks.Get(iWhich);
583 scAll = scSpan | scSplit
606 void SetSegmCallback(
CZipSegmCallback* pCallback = NULL,
int callbackType = scSpan);
626 return SetSplitNamesHandler(&names,
false);
650 return m_storage.SetSplitNamesHandler(pNames, bAutoDelete);
661 zipOpenReadOnly = zipOpen | 0x0002,
663 zipCreateAppend = zipCreate | 0x0008,
665 zipModeSplit = 0x0100,
666 zipModeBinSplit = 0x0200,
667 zipModeSpan = 0x0400,
668 zipModeSegmented = zipModeSplit | zipModeBinSplit | zipModeSpan,
670 zipCreateSplit = zipCreate | zipModeSplit,
671 zipCreateBinSplit = zipCreate | zipModeBinSplit,
672 zipCreateSpan = zipCreate | zipModeSpan,
674 zipOpenSplit = zipOpenReadOnly | zipModeSplit,
675 zipOpenBinSplit = zipOpenReadOnly | zipModeBinSplit
709 bool Open(LPCTSTR szPathName,
int iMode = zipOpen, ZIP_SIZE_TYPE uVolumeSize = 0);
737 bool Open(CZipAbstractFile& af,
int iMode = zipOpen,
bool bAutoClose =
false);
773 bool OpenFrom(
CZipArchive& zip, CZipAbstractFile* pArchiveFile = NULL,
bool bAllowNonReadOnly =
false);
797 void SetRootPath(LPCTSTR szPath = NULL);
809 CZipString GetRootPath()
const
824 zipsmCPassDir = 0x0001,
825 zipsmCPFile0 = 0x0002,
830 zipsmNotCompSmall = 0x0004,
841 zipsmCheckForEff = 0x0008,
848 zipsmMemoryFlag = 0x0010,
854 zipsmCheckForEffInMem = zipsmMemoryFlag | zipsmCheckForEff,
855 zipsmSmartPass = zipsmCPassDir | zipsmCPFile0,
856 zipsmSmartAdd = zipsmNotCompSmall | zipsmCheckForEff,
857 zipsmSafeSmart = zipsmSmartPass | zipsmNotCompSmall,
858 zipsmSmartest = zipsmSmartPass | zipsmSmartAdd,
866 zipsmIgnoreDirectories = 0x0020,
868 zipsmInternal01 = 0xf000
915 bool AddNewFile(LPCTSTR lpszFilePath,
int iComprLevel = -1,
bool bFullPath =
true,
916 int iSmartLevel = zipsmSafeSmart,
unsigned long nBufSize = 65536);
924 bool AddNewFile(LPCTSTR lpszFilePath,
925 LPCTSTR lpszFileNameInZip,
926 int iComprLevel = -1,
927 int iSmartLevel = zipsmSafeSmart,
928 unsigned long nBufSize = 65536);
935 bool AddNewFile(CZipAbstractFile& af,
936 LPCTSTR lpszFileNameInZip,
937 int iComprLevel = -1,
938 int iSmartLevel = zipsmSafeSmart,
939 unsigned long nBufSize = 65536);
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);
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)
1057 return AddNewFiles(lpszPath, filter, bRecursive, iComprLevel,
1058 bSkipInitialPath, iSmartLevel, nBufSize);
1109 ZIP_INDEX_TYPE GetLastIndexAdded()
const
1111 return m_centralDir.GetLastIndexAdded();
1174 return OpenNewFile(header, iLevel, lpszFilePath, ZIP_FILE_INDEX_UNSPECIFIED);
1197 bool WriteNewFile(
const void *pBuf, DWORD uSize);
1217 bool CloseNewFile(
bool bAfterException =
false);
1271 bool GetFromArchive(
CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName = NULL, ZIP_INDEX_TYPE uReplaceIndex = ZIP_FILE_INDEX_UNSPECIFIED,
bool bKeepSystComp =
false)
1277 bRet = GetFromArchive(zip, uIndex, lpszNewFileName, uReplaceIndex, bKeepSystComp, GetCallback(
CZipActionCallback::cbGet));
1337 bool GetFromArchive(
CZipArchive& zip, CZipIndexesArray &aIndexes,
bool bKeepSystComp =
false);
1387 bool GetFromArchive(
CZipArchive& zip, CZipStringArray &aNames,
bool bKeepSystComp =
false)
1389 CZipIndexesArray indexes;
1391 return GetFromArchive(zip, indexes, bKeepSystComp);
1412 void GetIndexes(
const CZipStringArray &aNames, CZipIndexesArray& aIndexes);
1475 bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1477 bool bFullPath =
true,
1478 LPCTSTR lpszNewName = NULL,
1480 DWORD nBufSize = 65536);
1513 bool ExtractFile(ZIP_INDEX_TYPE uIndex,
1514 CZipAbstractFile& af,
1515 bool bRewind =
true,
1516 DWORD nBufSize = 65536);
1541 bool OpenFile(ZIP_INDEX_TYPE uIndex);
1561 DWORD ReadFile(
void *pBuf, DWORD uSize);
1592 int CloseFile(LPCTSTR lpszFilePath = NULL,
bool bAfterException =
false);
1613 int CloseFile(CZipFile &file);
1636 bool TestFile(ZIP_INDEX_TYPE uIndex, DWORD uBufSize = 65536);
1665 bool RemoveFile(ZIP_INDEX_TYPE uIndex,
bool bRemoveData =
true);
1691 bool RemoveFiles(CZipIndexesArray& aIndexes);
1717 bool RemoveFiles(
const CZipStringArray& aNames);
1742 bool ShiftData(ZIP_SIZE_TYPE uOffset);
1773 bool PrependData(LPCTSTR lpszFilePath, LPCTSTR lpszNewExt =
1774 #ifdef _ZIP_SYSTEM_WIN
1809 bool PrependData(CZipAbstractFile& file, LPCTSTR lpszNewExt = NULL);
1829 bool SetGlobalComment(LPCTSTR lpszComment, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
1843 CZipString GetGlobalComment()
const ;
1854 CZipString GetArchivePath()
const;
1869 ZIP_VOLUME_TYPE GetCurrentVolume()
const ;
1934 ZIP_INDEX_TYPE FindFile(LPCTSTR lpszFileName,
int iCaseSensitive = ffDefault,
bool bFileNameOnly =
false);
1961 bool GetFileInfo(
CZipFileHeader& fhInfo, ZIP_INDEX_TYPE uIndex)
const;
2042 return GetFileInfo(uIndex);
2070 return GetFileInfo(uIndex);
2086 ZIP_INDEX_TYPE GetCount(
bool bOnlyFiles)
2091 ZIP_INDEX_TYPE iTotalCount = GetCount();
2094 ZIP_INDEX_TYPE iCount = 0;
2095 for (ZIP_INDEX_TYPE i = 0; i < iTotalCount; i++)
2113 ZIP_INDEX_TYPE GetCount()
const
2115 return (ZIP_INDEX_TYPE) m_centralDir.GetCount();
2129 ZIP_SIZE_TYPE GetOccupiedSpace()
const
2131 if (IsClosed(
true) || IsClosed(
false))
2133 ZIPTRACE(
"%s(%i) : ZipArchive or the current volume file is closed.\n");
2136 return m_storage.GetOccupiedSpace() + m_centralDir.GetSize(
true);
2187 CZipString Close(
int iAfterException = afNoException,
bool bUpdateTimeStamp =
false);
2202 bool IsClosed(
bool bArchive =
true)
const
2204 return m_storage.IsClosed(bArchive);
2232 bool Finalize(
bool bOnlyIfAuto =
false);
2246 ZIPTRACE(
"%s(%i) : ZipArchive should be opened first.\n");
2250 m_storage.FlushBuffers();
2271 bool SetAutoFinalize(
bool bAutoFinalize =
true);
2316 bool SetSystemCompatibility(
int iSystemComp);
2348 #ifdef _ZIP_UNICODE_CUSTOM
2368 m_stringSettings = settings;
2394 void SetStringStoreSettings(UINT uFileNameCodePage,
bool bStoreNameInExtraData, UINT uCommentCodePage)
2396 m_stringSettings.
Set(uFileNameCodePage, bStoreNameInExtraData, uCommentCodePage);
2420 void SetStringStoreSettings(UINT uFileNameCodePage,
bool bStoreNameInExtraData =
false)
2422 SetStringStoreSettings(uFileNameCodePage, bStoreNameInExtraData, m_stringSettings.m_uCommentCodePage);
2440 void ResetStringStoreSettings()
2442 m_stringSettings.Reset(m_iArchiveSystCompatib);
2466 return m_stringSettings;
2479 #ifdef _ZIP_UNICODE_CUSTOM
2518 void EnableFindFast(
bool bEnable =
true);
2539 ZIP_INDEX_TYPE GetFindFastIndex(ZIP_INDEX_TYPE iFindFastIndex)
const
2543 ZIPTRACE(
"CZipArchive::GetFindFastIndex: ZipArchive should be opened first.\n");
2544 return ZIP_FILE_INDEX_UNSPECIFIED;
2547 return m_centralDir.GetFindFastIndex(iFindFastIndex);
2578 void SetTempPath(LPCTSTR lpszPath = NULL,
bool bForce =
true);
2589 CZipString GetTempPath()
const
2591 return m_szTempPath;
2619 CZipString PredictFileNameInZip(LPCTSTR lpszFilePath,
bool bFullPath,
int iWhat = prAuto)
const ;
2653 ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(
CZipFileHeader& fh);
2672 ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(LPCTSTR lpszFilePath,
bool bFullPath);
2695 ZIP_INDEX_TYPE WillBeDuplicated(LPCTSTR lpszFilePath,
bool bFullPath,
bool bFileNameOnly =
false,
int iWhat = prAuto);
2717 CZipString PredictExtractedFileName(LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath,
bool bFullPath, LPCTSTR lpszNewName = NULL)
const ;
2747 static bool RemovePathBeginning(LPCTSTR lpszBeginning, CZipString& szPath, ZIPSTRINGCOMPARE pCompareFunction);
2770 void SetCaseSensitivity(
bool bCaseSensitive)
2772 m_bCaseSensitive = bCaseSensitive;
2773 m_pZipCompare = GetCZipStrCompFunc(bCaseSensitive);
2785 bool GetCaseSensitivity()
const
2787 return m_bCaseSensitive;
2813 ZIP_SIZE_TYPE GetCentralDirSize(
bool bWhole =
true)
const
2817 ZIPTRACE(
"%s(%i) : ZipArchive is closed.\n");
2820 return m_centralDir.GetSize(bWhole);
2844 void SetBytesBeforeZip(ZIP_SIZE_TYPE uCount = 0)
2848 ZIPTRACE(
"%s(%i) : Set it before opening the archive.\n");
2851 m_storage.m_uBytesBeforeZip = uCount;
2862 ZIP_SIZE_TYPE GetBytesBeforeZip()
const
2864 return m_storage.m_uBytesBeforeZip;
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
2919 void SetIgnoredConsistencyChecks(
int iLevel = checkIgnoredByDefault)
2923 ZIPTRACE(
"%s(%i) : Set it after opening the archive.\n");
2926 m_centralDir.m_iIgnoredChecks = iLevel;
2935 int GetIgnoredConsistencyChecks()
const
2937 return m_centralDir.m_iIgnoredChecks;
2946 void SetSpecialFlags(
int iSpecialFlags)
2950 ZIPTRACE(
"%s(%i) : Set it before opening the archive.\n");
2953 m_centralDir.m_specialFlags = iSpecialFlags;
2962 int GetSpecialFlags()
const
2964 return m_centralDir.m_specialFlags;
2993 void FindMatches(LPCTSTR lpszPattern, CZipIndexesArray& ar,
bool bFullPath =
true);
3020 void SetCommitMode(
int iCommitMode = cmOnChange)
3022 m_iCommitMode = iCommitMode;
3061 bool CommitChanges();
3074 bool IsModified()
const {
return m_centralDir.IsAnyFileModified();}
3086 bool RemoveCentralDirectoryFromArchive();
3103 bool ReadLocalHeader(ZIP_INDEX_TYPE uIndex);
3120 bool OverwriteLocalHeader(ZIP_INDEX_TYPE uIndex);
3131 return m_pCompressor;
3146 bool CanModify(
bool bAllowNewSegmented =
false,
bool bNeedsClosed =
true)
3150 ZIPTRACE(
"%s(%i) : ZipArchive is closed.\n");
3154 if (m_storage.IsReadOnly())
3159 if (m_storage.IsNewSegmented() && !bAllowNewSegmented)
3164 if (bNeedsClosed && m_iFileOpened)
3166 ZIPTRACE(
"%s(%i) : The file cannot be open during modifications.\n");
3180 bool IsPasswordSet()
const
3182 return m_pszPassword.GetSize() > 0;
3196 bool IsFullFileTimes()
const
3198 return m_bStoreFullFileTimes;
3209 void SetFullFileTimes(
bool bFullFileTimes =
true)
3213 ZIPTRACE(
"%s(%i) : Set it after opening the archive.\n");
3216 m_bStoreFullFileTimes = bFullFileTimes;
3230 bool ResetCurrentVolume();
3244 static bool IsZipArchive(LPCTSTR lpszPathName);
3261 static bool IsZipArchive(CZipAbstractFile& af,
bool bAutoClose =
false);
3280 void ReadLocalHeaderInternal(ZIP_INDEX_TYPE uIndex)
3283 GetFileInfo(uIndex)->ReadLocal(&m_centralDir);
3298 bool EncryptFilesInternal(CZipIndexesArray* pIndexes);
3312 bool OpenNewFile(
CZipFileHeader & header,
int iLevel, LPCTSTR lpszFilePath, ZIP_INDEX_TYPE uReplaceIndex);
3323 void WriteCentralDirectory(
bool bFlush =
true);
3399 void OpenInternal(
int iMode);
3411 void InitOnOpen(
int iArchiveSystCompatib,
CZipCentralDir* pSource = NULL);
3433 void ClearCryptograph()
3437 delete m_pCryptograph;
3438 m_pCryptograph = NULL;
3451 virtual void CreateCryptograph(
int iEncryptionMethod)
3453 if (m_pCryptograph != NULL)
3454 if (m_pCryptograph->CanHandle(iEncryptionMethod))
3469 void ClearCompressor()
3473 delete m_pCompressor;
3474 m_pCompressor = NULL;
3487 virtual void CreateCompressor(WORD uMethod)
3489 if (m_pCompressor == NULL || !m_pCompressor->CanProcess(uMethod))
3494 m_pCompressor->UpdateOptions(m_compressorsOptions);
3533 #ifdef _ZIP_UNICODE_CUSTOM
3543 void MakeSpaceForReplace(ZIP_INDEX_TYPE iReplaceIndex, ZIP_SIZE_TYPE uTotal, LPCTSTR lpszFileName);
3545 void MovePackedFiles(ZIP_SIZE_TYPE uStartOffset, ZIP_SIZE_TYPE uEndOffset, ZIP_SIZE_TYPE uMoveBy,
CZipActionCallback* pCallback,
bool bForward =
false,
bool bLastCall =
true);
3547 bool RemoveLast(
bool bRemoveAnyway =
false);
3549 bool GetFromArchive(
CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName, ZIP_INDEX_TYPE iReplaceIndex,
bool bKeepSystComp,
CZipActionCallback* pCallback);
3551 bool UpdateReplaceIndex(ZIP_INDEX_TYPE& iReplaceIndex);
3553 void ThrowError(
int err, LPCTSTR lpszFilePath = NULL)
const;
3557 m_pBuffer.Allocate(m_iBufferSize);
3559 void ReleaseBuffer()
3561 m_pBuffer.Release();
3581 unsigned long m_nBufSize;
3584 bool bRecursive =
true,
3585 int iComprLevel = -1,
3587 unsigned long nBufSize = 65536);
3618 bool bRecursive =
true,
3619 int iComprLevel = -1,
3621 unsigned long nBufSize = 65536)
3630 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
3631 #pragma warning (pop)
3634 #endif // !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)