00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030 #if !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)
00031 #define ZIPARCHIVE_ZIPARCHIVE_DOT_H
00032
00033 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
00034 #pragma warning (push)
00035 #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
00036 #pragma warning( disable : 4275 ) // non dll-interface class used as base for dll-interface
00037 #endif
00038
00039 #include "_features.h"
00040 #include "ZipException.h"
00041 #include "ZipAutoBuffer.h"
00042 #include "ZipCentralDir.h"
00043 #include "ZipStorage.h"
00044 #include "ZipPathComponent.h"
00045 #include "ZipString.h"
00046 #include "ZipExport.h"
00047 #include "ZipCryptograph.h"
00048 #include "FileFilter.h"
00049 #include "DirEnumerator.h"
00050 #include "ZipCompressor.h"
00051 #include "ZipCallbackProvider.h"
00052 #include "BitFlag.h"
00053
00054 #define ZIP_DEFAULT_CODE_PAGE UINT(-1)
00055
00063 struct ZIP_API CZipAddNewFileInfo
00064 {
00074 CZipAddNewFileInfo(LPCTSTR lpszFilePath, bool bFullPath = true)
00075 {
00076 Defaults();
00077 m_szFilePath = lpszFilePath;
00078 m_bFullPath = bFullPath;
00079 }
00080
00090 CZipAddNewFileInfo(LPCTSTR lpszFilePath, LPCTSTR lpszFileNameInZip)
00091 {
00092 Defaults();
00093 m_szFilePath = lpszFilePath;
00094 m_szFileNameInZip = lpszFileNameInZip;
00095 }
00096
00106 CZipAddNewFileInfo(CZipAbstractFile* pFile, LPCTSTR lpszFileNameInZip)
00107 {
00108 Defaults();
00109 m_pFile = pFile;
00110 m_szFileNameInZip = lpszFileNameInZip;
00111 }
00112
00123 CZipAbstractFile* m_pFile;
00124
00130 CZipString m_szFilePath;
00131
00137 CZipString m_szFileNameInZip;
00138
00151 bool m_bFullPath;
00152
00157 int m_iComprLevel;
00158
00163 ZipArchiveLib::CBitFlag m_iSmartLevel;
00164
00182 ZIP_INDEX_TYPE m_uReplaceIndex;
00183
00187 unsigned long m_nBufSize;
00188
00193 void Defaults();
00194 };
00195
00196
00197
00201 class ZIP_API CZipArchive
00202 {
00203 public:
00204 static const char m_gszCopyright[];
00205 static const char m_gszVersion[];
00206
00207 CZipArchive();
00208
00209 virtual ~CZipArchive();
00210
00237 bool SetPassword(LPCTSTR lpszPassword = NULL, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
00238
00246 CZipString GetPassword()const ;
00247
00265 bool WillEncryptNextFile() const
00266 {
00267 return m_pszPassword.GetSize() != 0 && m_iEncryptionMethod != CZipCryptograph::encNone;
00268 }
00269
00295 bool SetEncryptionMethod(int iEncryptionMethod = CZipCryptograph::encStandard);
00296
00308 int GetEncryptionMethod() const
00309 {
00310 return m_iEncryptionMethod;
00311 }
00312
00341 bool EncryptFile(ZIP_INDEX_TYPE uIndex)
00342 {
00343 CZipIndexesArray aIndexes;
00344 aIndexes.Add(uIndex);
00345 return EncryptFilesInternal(&aIndexes);
00346 }
00347
00376 bool EncryptFiles(CZipIndexesArray &aIndexes)
00377 {
00378 return EncryptFilesInternal(&aIndexes);
00379 }
00380
00406 bool EncryptAllFiles()
00407 {
00408 return EncryptFilesInternal(NULL);
00409 }
00410
00436 bool SetCompressionMethod(WORD uCompressionMethod = CZipCompressor::methodDeflate);
00437
00447 WORD GetCompressionMethod() const
00448 {
00449 return m_uCompressionMethod;
00450 }
00451
00471 void SetCompressionOptions(CZipCompressor::COptions* pOptions)
00472 {
00473 if (m_iFileOpened)
00474 {
00475 ZIPTRACE("%s(%i) : The options will have no effect on the current file processing.\n");
00476 }
00477 m_compressorsOptions.Set(pOptions);
00478 }
00479
00501 void SetAdvanced(int iWriteBuffer = 65536, int iGeneralBuffer = 65536, int iSearchBuffer = 32768);
00502
00503
00516 void GetAdvanced(int* piWriteBuffer = NULL, int* piGeneralBuffer = NULL, int* piSearchBuffer= NULL)
00517 {
00518 if (piWriteBuffer)
00519 *piWriteBuffer = m_storage.m_iWriteBufferSize;
00520 if (piGeneralBuffer)
00521 *piGeneralBuffer = m_iBufferSize;
00522 if (piSearchBuffer)
00523 *piSearchBuffer = m_storage.m_iLocateBufferSize;
00524 }
00525
00526
00547 void SetCallback(CZipActionCallback* pCallback = NULL, int iWhich = CZipActionCallback::cbAll)
00548 {
00549 m_callbacks.Set(pCallback, iWhich);
00550 }
00551
00568 CZipActionCallback* GetCallback(CZipActionCallback::CallbackType iWhich)
00569 {
00570 return m_callbacks.Get(iWhich);
00571 }
00572
00579 enum SegmCallbackType
00580 {
00581 scSpan = 0x01,
00582 scSplit = 0x02,
00583 scAll = scSpan | scSplit
00584 };
00585
00606 void SetSegmCallback(CZipSegmCallback* pCallback = NULL, int callbackType = scSpan);
00607
00624 bool SetSplitNamesHandler(CZipSplitNamesHandler& names)
00625 {
00626 return SetSplitNamesHandler(&names, false);
00627 }
00628
00648 bool SetSplitNamesHandler(CZipSplitNamesHandler* pNames, bool bAutoDelete = true)
00649 {
00650 return m_storage.SetSplitNamesHandler(pNames, bAutoDelete);
00651 }
00652
00653
00658 enum OpenMode
00659 {
00660 zipOpen = 0x0001,
00661 zipOpenReadOnly = zipOpen | 0x0002,
00662 zipCreate = 0x0004,
00663 zipCreateAppend = zipCreate | 0x0008,
00664
00665 zipModeSplit = 0x0100,
00666 zipModeBinSplit = 0x0200,
00667 zipModeSpan = 0x0400,
00668 zipModeSegmented = zipModeSplit | zipModeBinSplit | zipModeSpan,
00669
00670 zipCreateSplit = zipCreate | zipModeSplit,
00671 zipCreateBinSplit = zipCreate | zipModeBinSplit,
00672 zipCreateSpan = zipCreate | zipModeSpan,
00673
00674 zipOpenSplit = zipOpen | zipModeSplit,
00675 zipOpenBinSplit = zipOpen | zipModeBinSplit
00676
00677 };
00678
00709 bool Open(LPCTSTR szPathName, int iMode = zipOpen, ZIP_SIZE_TYPE uVolumeSize = 0);
00710
00711
00737 bool Open(CZipAbstractFile& af, int iMode = zipOpen, bool bAutoClose = false);
00738
00765 bool OpenFrom(CZipArchive& zip, CZipAbstractFile* pArchiveFile = NULL);
00766
00789 void SetRootPath(LPCTSTR szPath = NULL);
00790
00791
00801 CZipString GetRootPath()const
00802 {
00803 return m_szRootPath;
00804 }
00805
00813 enum Smartness
00814 {
00815 zipsmLazy = 0x0000,
00816 zipsmCPassDir = 0x0001,
00817 zipsmCPFile0 = 0x0002,
00818
00822 zipsmNotCompSmall = 0x0004,
00823
00833 zipsmCheckForEff = 0x0008,
00834
00840 zipsmMemoryFlag = 0x0010,
00841
00846 zipsmCheckForEffInMem = zipsmMemoryFlag | zipsmCheckForEff,
00847 zipsmSmartPass = zipsmCPassDir | zipsmCPFile0,
00848 zipsmSmartAdd = zipsmNotCompSmall | zipsmCheckForEff,
00849 zipsmSafeSmart = zipsmSmartPass | zipsmNotCompSmall,
00850 zipsmSmartest = zipsmSmartPass | zipsmSmartAdd,
00851
00858 zipsmIgnoreDirectories = 0x0020,
00859
00860 zipsmInternal01 = 0xf000
00861 };
00862
00863
00896 bool AddNewFile(CZipAddNewFileInfo& info);
00897
00898
00905 bool AddNewFile(LPCTSTR lpszFilePath, int iComprLevel = -1, bool bFullPath = true,
00906 int iSmartLevel = zipsmSafeSmart, unsigned long nBufSize = 65536);
00907
00908
00914 bool AddNewFile(LPCTSTR lpszFilePath,
00915 LPCTSTR lpszFileNameInZip,
00916 int iComprLevel = -1,
00917 int iSmartLevel = zipsmSafeSmart,
00918 unsigned long nBufSize = 65536);
00919
00925 bool AddNewFile(CZipAbstractFile& af,
00926 LPCTSTR lpszFileNameInZip,
00927 int iComprLevel = -1,
00928 int iSmartLevel = zipsmSafeSmart,
00929 unsigned long nBufSize = 65536);
00930
00931
00982 bool AddNewFiles(LPCTSTR lpszPath,
00983 ZipArchiveLib::CFileFilter& filter,
00984 bool bRecursive = true,
00985 int iComprLevel = -1,
00986 bool bSkipInitialPath = true,
00987 int iSmartLevel = zipsmSafeSmart,
00988 unsigned long nBufSize = 65536);
00989
01034 bool AddNewFiles(LPCTSTR lpszPath,
01035 LPCTSTR lpszFileMask = _T("*.*"),
01036 bool bRecursive = true,
01037 int iComprLevel = -1,
01038 bool bSkipInitialPath = true,
01039 int iSmartLevel = zipsmSafeSmart,
01040 unsigned long nBufSize = 65536)
01041 {
01042 ZipArchiveLib::CNameFileFilter filter(lpszFileMask);
01043 return AddNewFiles(lpszPath, filter, bRecursive, iComprLevel,
01044 bSkipInitialPath, iSmartLevel, nBufSize);
01045 }
01046
01105 bool OpenNewFile(CZipFileHeader& header, int iLevel = CZipCompressor::levelDefault, LPCTSTR lpszFilePath = NULL)
01106 {
01107 return OpenNewFile(header, iLevel, lpszFilePath, ZIP_FILE_INDEX_UNSPECIFIED);
01108 }
01109
01130 bool WriteNewFile(const void *pBuf, DWORD uSize);
01131
01150 bool CloseNewFile(bool bAfterException = false);
01151
01204 bool GetFromArchive(CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName = NULL, ZIP_INDEX_TYPE uReplaceIndex = ZIP_FILE_INDEX_UNSPECIFIED, bool bKeepSystComp = false)
01205 {
01206 InitBuffer();
01207 bool bRet;
01208 try
01209 {
01210 bRet = GetFromArchive(zip, uIndex, lpszNewFileName, uReplaceIndex, bKeepSystComp, GetCallback(CZipActionCallback::cbGet));
01211 }
01212 catch(...)
01213 {
01214 ReleaseBuffer();
01215 throw;
01216 }
01217 ReleaseBuffer();
01218 if (bRet)
01219 Finalize(true);
01220
01221 return bRet;
01222 }
01223
01270 bool GetFromArchive(CZipArchive& zip, CZipIndexesArray &aIndexes, bool bKeepSystComp = false);
01271
01320 bool GetFromArchive(CZipArchive& zip, CZipStringArray &aNames, bool bKeepSystComp = false)
01321 {
01322 CZipIndexesArray indexes;
01323 zip.GetIndexes(aNames, indexes);
01324 return GetFromArchive(zip, indexes, bKeepSystComp);
01325 }
01326
01345 void GetIndexes(const CZipStringArray &aNames, CZipIndexesArray& aIndexes);
01346
01405 bool ExtractFile(ZIP_INDEX_TYPE uIndex,
01406 LPCTSTR lpszPath,
01407 bool bFullPath = true,
01408 LPCTSTR lpszNewName = NULL,
01409 DWORD nBufSize = 65536);
01410
01443 bool ExtractFile(ZIP_INDEX_TYPE uIndex,
01444 CZipAbstractFile& af,
01445 bool bRewind = true,
01446 DWORD nBufSize = 65536);
01447
01471 bool OpenFile(ZIP_INDEX_TYPE uIndex);
01472
01491 DWORD ReadFile(void *pBuf, DWORD uSize);
01492
01493
01522 int CloseFile(LPCTSTR lpszFilePath = NULL, bool bAfterException = false);
01523
01543 int CloseFile(CZipFile &file);
01544
01566 bool TestFile(ZIP_INDEX_TYPE uIndex, DWORD uBufSize = 65536);
01567
01595 bool RemoveFile(ZIP_INDEX_TYPE uIndex, bool bRemoveData = true);
01596
01621 bool RemoveFiles(CZipIndexesArray& aIndexes);
01622
01623
01647 bool RemoveFiles(const CZipStringArray& aNames);
01648
01672 bool ShiftData(ZIP_SIZE_TYPE uOffset);
01673
01703 bool PrependData(LPCTSTR lpszFilePath, LPCTSTR lpszNewExt =
01704 #ifdef _ZIP_SYSTEM_WIN
01705 _T("exe")
01706 #else
01707 _T("")
01708 #endif
01709 );
01710
01739 bool PrependData(CZipAbstractFile& file, LPCTSTR lpszNewExt = NULL);
01740
01759 bool SetGlobalComment(LPCTSTR lpszComment, UINT codePage = ZIP_DEFAULT_CODE_PAGE);
01760
01761
01773 CZipString GetGlobalComment()const ;
01774
01775
01784 CZipString GetArchivePath()const;
01785
01799 ZIP_VOLUME_TYPE GetCurrentVolume() const ;
01800
01808 enum FFCaseSens
01809 {
01816 ffDefault,
01817
01824 ffCaseSens,
01825
01832 ffNoCaseSens
01833 };
01834
01864 ZIP_INDEX_TYPE FindFile(LPCTSTR lpszFileName, int iCaseSensitive = ffDefault, bool bFileNameOnly = false);
01865
01891 bool GetFileInfo(CZipFileHeader& fhInfo, ZIP_INDEX_TYPE uIndex) const;
01892
01918 CZipFileHeader* GetFileInfo(ZIP_INDEX_TYPE uIndex);
01919
01944 const CZipFileHeader* GetFileInfo(ZIP_INDEX_TYPE uIndex) const;
01945
01970 CZipFileHeader* operator[](ZIP_INDEX_TYPE uIndex)
01971 {
01972 return GetFileInfo(uIndex);
01973 }
01974
01998 const CZipFileHeader* operator[](ZIP_INDEX_TYPE uIndex) const
01999 {
02000 return GetFileInfo(uIndex);
02001 }
02002
02003
02016 ZIP_INDEX_TYPE GetCount(bool bOnlyFiles)
02017 {
02018 if (IsClosed())
02019 return 0;
02020
02021 ZIP_INDEX_TYPE iTotalCount = GetCount();
02022 if (bOnlyFiles)
02023 {
02024 ZIP_INDEX_TYPE iCount = 0;
02025 for (ZIP_INDEX_TYPE i = 0; i < iTotalCount; i++)
02026 {
02027 if (!m_centralDir[i]->IsDirectory())
02028 iCount++;
02029 }
02030 return iCount;
02031 }
02032 else
02033 return iTotalCount;
02034 }
02035
02043 ZIP_INDEX_TYPE GetCount() const
02044 {
02045 return (ZIP_INDEX_TYPE) m_centralDir.GetCount();
02046 }
02047
02048
02059 ZIP_SIZE_TYPE GetOccupiedSpace() const
02060 {
02061 if (IsClosed(true) || IsClosed(false))
02062 {
02063 ZIPTRACE("%s(%i) : ZipArchive or the current volume file is closed.\n");
02064 return 0;
02065 }
02066 return m_storage.GetOccupiedSpace() + m_centralDir.GetSize(true);
02067 }
02068
02072 enum CloseAfterException
02073 {
02077 afNoException,
02078
02084 afAfterException,
02085
02091 afWriteDir
02092 };
02093
02117 CZipString Close(int iAfterException = afNoException, bool bUpdateTimeStamp = false);
02118
02119
02132 bool IsClosed(bool bArchive = true)const
02133 {
02134 return m_storage.IsClosed(bArchive);
02135 }
02136
02162 bool Finalize(bool bOnlyIfAuto = false);
02163
02172 void FlushBuffers()
02173 {
02174 if (IsClosed())
02175 {
02176 ZIPTRACE("%s(%i) : ZipArchive should be opened first.\n");
02177 return;
02178 }
02179
02180 m_storage.FlushBuffers();
02181 }
02182
02183
02201 bool SetAutoFinalize(bool bAutoFinalize = true);
02202
02203
02217 bool GetAutoFinalize()const {return m_bAutoFinalize;}
02218
02246 bool SetSystemCompatibility(int iSystemComp);
02247
02265 int GetSystemCompatibility() const {return m_iArchiveSystCompatib;}
02266
02276 CZipStorage* GetStorage(){return &m_storage;}
02277
02278 #ifdef _ZIP_UNICODE_CUSTOM
02279
02296 void SetStringStoreSettings(const CZipStringStoreSettings& settings)
02297 {
02298 m_stringSettings = settings;
02299 }
02300
02324 void SetStringStoreSettings(UINT uFileNameCodePage, bool bStoreNameInExtraData, UINT uCommentCodePage)
02325 {
02326 m_stringSettings.Set(uFileNameCodePage, bStoreNameInExtraData, uCommentCodePage);
02327 }
02328
02350 void SetStringStoreSettings(UINT uFileNameCodePage, bool bStoreNameInExtraData = false)
02351 {
02352 SetStringStoreSettings(uFileNameCodePage, bStoreNameInExtraData, m_stringSettings.m_uCommentCodePage);
02353 }
02354
02370 void ResetStringStoreSettings()
02371 {
02372 m_stringSettings.Reset(m_iArchiveSystCompatib);
02373 }
02374
02394 CZipStringStoreSettings& GetStringStoreSettings()
02395 {
02396 return m_stringSettings;
02397 }
02398 #endif
02399
02406 enum UnicodeMode
02407 {
02408 umNone = 0x00,
02409 #ifdef _ZIP_UNICODE_CUSTOM
02410 umCustom = 0x04
02411 #endif
02412 };
02413
02423 void SetUnicodeMode(int iMode){ m_centralDir.SetUnicodeMode(iMode); }
02424
02434 int GetUnicodeMode() const { return m_centralDir.GetUnicodeMode(); }
02435
02448 void EnableFindFast(bool bEnable = true);
02449
02450
02469 ZIP_INDEX_TYPE GetFindFastIndex(ZIP_INDEX_TYPE iFindFastIndex) const
02470 {
02471 if (IsClosed())
02472 {
02473 ZIPTRACE("CZipArchive::GetFindFastIndex: ZipArchive should be opened first.\n");
02474 return ZIP_FILE_INDEX_UNSPECIFIED;
02475 }
02476
02477 return m_centralDir.GetFindFastIndex(iFindFastIndex);
02478 }
02479
02480
02508 void SetTempPath(LPCTSTR lpszPath = NULL, bool bForce = true);
02509
02519 CZipString GetTempPath()const
02520 {
02521 return m_szTempPath;
02522 }
02523
02527 enum Predict
02528 {
02529
02530 prDir,
02531 prFile,
02532 prAuto
02533 };
02534
02549 CZipString PredictFileNameInZip(LPCTSTR lpszFilePath, bool bFullPath, int iWhat = prAuto)const ;
02550
02583 ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(CZipFileHeader& fh);
02584
02602 ZIP_SIZE_TYPE PredictMaximumFileSizeInArchive(LPCTSTR lpszFilePath, bool bFullPath);
02603
02604
02625 ZIP_INDEX_TYPE WillBeDuplicated(LPCTSTR lpszFilePath, bool bFullPath, bool bFileNameOnly = false, int iWhat = prAuto);
02626
02645 CZipString PredictExtractedFileName(LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath, bool bFullPath, LPCTSTR lpszNewName = NULL)const ;
02646
02647
02657 CZipString TrimRootPath(CZipPathComponent& zpc) const ;
02658
02675 static bool RemovePathBeginning(LPCTSTR lpszBeginning, CZipString& szPath, ZIPSTRINGCOMPARE pCompareFunction);
02676
02698 void SetCaseSensitivity(bool bCaseSensitive)
02699 {
02700 m_bCaseSensitive = bCaseSensitive;
02701 m_pZipCompare = GetCZipStrCompFunc(bCaseSensitive);
02702 }
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713 bool GetCaseSensitivity() const
02714 {
02715 return m_bCaseSensitive;
02716 }
02717
02726 void GetCentralDirInfo(CZipCentralDir::CInfo& info)const;
02727
02728
02741 ZIP_SIZE_TYPE GetCentralDirSize(bool bWhole = true) const
02742 {
02743 if (IsClosed())
02744 {
02745 ZIPTRACE("%s(%i) : ZipArchive is closed.\n");
02746 return 0;
02747 }
02748 return m_centralDir.GetSize(bWhole);
02749 }
02750
02759 bool IsReadOnly(){return m_storage.IsReadOnly();} const
02760
02772 void SetBytesBeforeZip(ZIP_SIZE_TYPE uCount = 0)
02773 {
02774 if (!IsClosed())
02775 {
02776 ZIPTRACE("%s(%i) : Set it before opening the archive.\n");
02777 return;
02778 }
02779 m_storage.m_uBytesBeforeZip = uCount;
02780 }
02781
02790 ZIP_SIZE_TYPE GetBytesBeforeZip() const
02791 {
02792 return m_storage.m_uBytesBeforeZip;
02793 }
02794
02799 enum ConsistencyCheck
02800 {
02801 checkNone,
02802 checkCRC = 0x0001,
02803 checkLocalMethod = 0x0002,
02804 checkLocalSizes = 0x0004,
02805 checkLocalCRC = 0x0008,
02806 checkLocalFlag = 0x0010,
02807 checkLocalAll = checkLocalMethod | checkLocalSizes | checkLocalCRC | checkLocalFlag,
02808 checkDataDescriptor = 0x0100,
02809 checkVolumeEntries = 0x0200,
02810 checkAll = checkCRC | checkLocalAll | checkDataDescriptor | checkVolumeEntries,
02811 checkIgnoredByDefault = checkDataDescriptor | checkVolumeEntries
02812 };
02813
02826 void SetIgnoredConsistencyChecks(int iLevel = checkIgnoredByDefault)
02827 {
02828 if (IsClosed())
02829 {
02830 ZIPTRACE("%s(%i) : Set it after opening the archive.\n");
02831 return;
02832 }
02833 m_centralDir.m_iIgnoredChecks = iLevel;
02834 }
02835
02842 int GetIgnoredConsistencyChecks() const
02843 {
02844 return m_centralDir.m_iIgnoredChecks;
02845 }
02846
02861 void SetExhaustiveRead(bool bExhaustiveRead)
02862 {
02863 if (!IsClosed())
02864 {
02865 ZIPTRACE("%s(%i) : Set it before opening the archive.\n");
02866 return;
02867 }
02868 m_bExhaustiveRead = bExhaustiveRead;
02869 }
02870
02880 bool GetExhaustiveRead() const
02881 {
02882 return m_bExhaustiveRead;
02883 }
02884
02911 void FindMatches(LPCTSTR lpszPattern, CZipIndexesArray& ar, bool bFullPath = true);
02912
02919 enum CommitMode
02920 {
02921 cmManual,
02922 cmOnChange
02923 };
02924
02938 void SetCommitMode(int iCommitMode = cmOnChange)
02939 {
02940 m_iCommitMode = iCommitMode;
02941 }
02942
02956 int GetCommitMode() const {return m_iCommitMode;}
02957
02979 bool CommitChanges();
02980
02992 bool IsModified() const {return m_centralDir.IsAnyFileModified();}
02993
03004 bool RemoveCentralDirectoryFromArchive();
03005
03021 bool ReadLocalHeader(ZIP_INDEX_TYPE uIndex);
03022
03038 bool OverwriteLocalHeader(ZIP_INDEX_TYPE uIndex);
03039
03047 const CZipCompressor* GetCurrentCompressor() const
03048 {
03049 return m_pCompressor;
03050 }
03051
03064 bool CanModify(bool bAllowNewSegmented = false, bool bNeedsClosed = true)
03065 {
03066 if (IsClosed())
03067 {
03068 ZIPTRACE("%s(%i) : ZipArchive is closed.\n");
03069 return false;
03070 }
03071
03072 if (m_storage.IsReadOnly())
03073 {
03074 return false;
03075 }
03076
03077 if (m_storage.IsNewSegmented() && !bAllowNewSegmented)
03078 {
03079 return false;
03080 }
03081
03082 if (bNeedsClosed && m_iFileOpened)
03083 {
03084 ZIPTRACE("%s(%i) : The file cannot be open during modifications.\n");
03085 return false;
03086 }
03087
03088 return true;
03089 }
03090
03091 bool IsPasswordSet() const
03092 {
03093 return m_pszPassword.GetSize() > 0;
03094 }
03095
03096
03107 bool ResetCurrentVolume();
03108
03121 static bool IsZipArchive(LPCTSTR lpszPathName);
03122
03138 static bool IsZipArchive(CZipAbstractFile& af, bool bAutoClose = false);
03139
03146 bool m_bRemoveDriveLetter;
03147
03148 protected:
03149
03157 void ReadLocalHeaderInternal(ZIP_INDEX_TYPE uIndex)
03158 {
03159
03160 GetFileInfo(uIndex)->ReadLocal(&m_centralDir);
03161 }
03162
03175 bool EncryptFilesInternal(CZipIndexesArray* pIndexes);
03176
03177
03181 bool m_bExhaustiveRead;
03182
03194 bool OpenNewFile(CZipFileHeader & header, int iLevel, LPCTSTR lpszFilePath, ZIP_INDEX_TYPE uReplaceIndex);
03195
03199 ZipArchiveLib::CZipCallbackProvider m_callbacks;
03200
03201
03205 void WriteCentralDirectory(bool bFlush = true);
03206
03210 bool m_bCaseSensitive;
03211
03212
03217 ZIPSTRINGCOMPARE m_pZipCompare;
03218
03219
03225 CZipStorage m_storage;
03226
03232 CZipCentralDir m_centralDir;
03233
03237 enum OpenFileType
03238 {
03239 extract = -1,
03240 nothing,
03241 compress
03242 };
03243
03247 int m_iFileOpened;
03248
03252 bool m_bAutoFinalize;
03253
03257 int m_iCommitMode;
03258
03262 CZipString m_szRootPath;
03263
03267 CZipString m_szTempPath;
03268
03269
03276 void OpenInternal(int iMode);
03277
03288 void InitOnOpen(int iArchiveSystCompatib, CZipCentralDir* pSource = NULL);
03289
03293 int m_iArchiveSystCompatib;
03294
03298 CZipAutoBuffer m_pszPassword;
03299
03305 CZipFileHeader* CurrentFile();
03306
03310 void ClearCryptograph()
03311 {
03312 if (m_pCryptograph)
03313 {
03314 delete m_pCryptograph;
03315 m_pCryptograph = NULL;
03316 }
03317 }
03318
03328 virtual void CreateCryptograph(int iEncryptionMethod)
03329 {
03330 if (m_pCryptograph != NULL)
03331 if (m_pCryptograph->CanHandle(iEncryptionMethod))
03332 return;
03333
03334 ClearCryptograph();
03335 m_pCryptograph = CZipCryptograph::CreateCryptograph(iEncryptionMethod);
03336 }
03337
03341 CZipCryptograph* m_pCryptograph;
03342
03346 void ClearCompressor()
03347 {
03348 if (m_pCompressor)
03349 {
03350 delete m_pCompressor;
03351 m_pCompressor = NULL;
03352 }
03353 }
03354
03364 virtual void CreateCompressor(WORD uMethod)
03365 {
03366 if (m_pCompressor == NULL || !m_pCompressor->CanProcess(uMethod))
03367 {
03368 ClearCompressor();
03369 m_pCompressor = CZipCompressor::CreateCompressor(uMethod, &m_storage);
03370 }
03371 m_pCompressor->UpdateOptions(m_compressorsOptions);
03372 }
03373
03377 CZipCompressor* m_pCompressor;
03378
03382 int m_iEncryptionMethod;
03383
03387 WORD m_uCompressionMethod;
03388
03389
03398 CZipAutoBuffer m_pBuffer;
03399
03408 DWORD m_iBufferSize;
03409
03410 #ifdef _ZIP_UNICODE_CUSTOM
03411
03414 CZipStringStoreSettings m_stringSettings;
03415 #endif
03416
03417 private:
03418 CZipCompressor::COptionsMap m_compressorsOptions;
03419 void Initialize();
03420 void MakeSpaceForReplace(ZIP_INDEX_TYPE iReplaceIndex, ZIP_SIZE_TYPE uTotal, LPCTSTR lpszFileName);
03421
03422 void MovePackedFiles(ZIP_SIZE_TYPE uStartOffset, ZIP_SIZE_TYPE uEndOffset, ZIP_SIZE_TYPE uMoveBy, CZipActionCallback* pCallback, bool bForward = false, bool bLastCall = true);
03423
03424 bool RemoveLast(bool bRemoveAnyway = false);
03425
03426 bool GetFromArchive(CZipArchive& zip, ZIP_INDEX_TYPE uIndex, LPCTSTR lpszNewFileName, ZIP_INDEX_TYPE iReplaceIndex, bool bKeepSystComp, CZipActionCallback* pCallback);
03427
03428 bool UpdateReplaceIndex(ZIP_INDEX_TYPE& iReplaceIndex);
03429
03430 void ThrowError(int err) const;
03431
03432 void InitBuffer()
03433 {
03434 m_pBuffer.Allocate(m_iBufferSize);
03435 }
03436 void ReleaseBuffer()
03437 {
03438 m_pBuffer.Release();
03439 }
03440 };
03441
03442 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
03443 #pragma warning (pop)
03444 #endif
03445
03446 #endif // !defined(ZIPARCHIVE_ZIPARCHIVE_DOT_H)