CZipArchive Class Reference

The representation of the zip archive file. More...

#include <ZipArchive.h>

List of all members.

Public Types

enum  CallbackType {
  cbNothing = 0x0000, cbAdd = 0x0001, cbAddTmp = 0x0002, cbAddStore = 0x0004,
  cbExtract = 0x0008, cbDeleteCnt = 0x0010, cbDelete = 0x0020, cbTest = 0x0040,
  cbSave = 0x0080, cbGetFromArchive = 0x0100, cbRename = 0x0200, cbReplace = 0x0400,
  cbNextValue = 0x0800, cbSubActions = cbAddTmp | cbAddStore | cbDeleteCnt | cbReplace, cbActions = cbAdd | cbExtract | cbDelete | cbTest | cbSave | cbGetFromArchive | cbRename, cbAll = cbActions | cbSubActions
}
 Enum values used as iWhich parameter in SetCallback function. More...
enum  OpenMode { zipOpen, zipOpenReadOnly, zipCreate, zipCreateSpan }
 Archive open modes used in Open(LPCTSTR , int , int ) and Open(CZipAbstractFile&, int ) . More...
enum  Smartness {
  zipsmLazy = 0x0000, zipsmCPassDir = 0x0001, zipsmCPFile0 = 0x0002, zipsmNotCompSmall = 0x0004,
  zipsmCheckForEff = 0x0008, zipsmMemoryFlag = 0x0010, zipsmCheckForEffInMem = zipsmMemoryFlag | zipsmCheckForEff, zipsmSmartPass = zipsmCPassDir | zipsmCPFile0,
  zipsmSmartAdd = zipsmNotCompSmall | zipsmCheckForEff, zipsmSafeSmart = zipsmSmartPass | zipsmNotCompSmall, zipsmSmartest = zipsmSmartPass | zipsmSmartAdd, zipsmInternal01 = 0xf000
}
 The levels of smartness of the adding files action (see AddNewFile). More...
enum  FFCaseSens { ffDefault, ffCaseSens, ffNoCaseSens }
 case-sensitivity values used as argument iCaseSensitive in FindFile More...
enum  CloseAfterException { afNoException, afAfterException, afWriteDir }
 values used in Close function as parameter iAfterException More...
enum  Predict { prDir, prFile, prAuto }
 enum values used in PredictFileNameInZip More...

Public Member Functions

bool SetPassword (LPCTSTR lpszPassword=NULL)
 Set the password for the file to be opened or created.
CZipString GetPassword () const
void SetAdvanced (int iWriteBuffer=65536, int iGeneralBuffer=65536, int iSearchBuffer=32768)
 Set the buffer sizes.
void GetAdvanced (int *piWriteBuffer=NULL, int *piGeneralBuffer=NULL, int *piSearchBuffer=NULL)
 retreive buffer size as set by SetAdvanced
void SetCallback (CZipActionCallback *pCallback=NULL, int iWhich=cbAll)
 Set callback objects for the following operations on the zip archive: adding, extracting, testing or deleting files.
CZipActionCallbackGetCallback (CallbackType iWhich)
void SetSpanCallback (CZipSpanCallback *pCallback=NULL)
 Set the callback object used during operations on a PKZIP compatible disk spanning archive to change disks.
void Open (LPCTSTR szPathName, int iMode=zipOpen, int iVolumeSize=0)
 Open or create a zip archive.
void Open (CZipAbstractFile &af, int iMode=zipOpen)
 Open or create the archive in memory.
void SetRootPath (LPCTSTR szPath=NULL)
 Set m_szRootPath to a specified value.
CZipString GetRootPath () const
 Return the current value of m_szRootPath.
bool AddNewFile (CZipAddNewFileInfo &info)
 Add a new file to the archive.
bool AddNewFile (LPCTSTR lpszFilePath, int iComprLevel=-1, bool bFullPath=true, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
bool AddNewFile (LPCTSTR lpszFilePath, LPCTSTR lpszFileNameInZip, int iComprLevel=-1, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
bool AddNewFile (CZipMemFile &mf, LPCTSTR lpszFileNameInZip, int iComprLevel=-1, int iSmartLevel=zipsmSafeSmart, unsigned long nBufSize=65536)
bool OpenNewFile (CZipFileHeader &header, int iLevel=Z_DEFAULT_COMPRESSION, LPCTSTR lpszFilePath=NULL, DWORD uInternal=0)
 Add a new file to the opened zip archive.
bool WriteNewFile (const void *pBuf, DWORD iSize)
 Compress the contents of the buffer and write it to a new file.
void SetExtraField (const char *pBuf, WORD iSize)
 Set the extra field in the central directory of the currently opened file.
bool CloseNewFile (bool bAfterException=false)
 Close the new file in the archive.
bool GetFromArchive (CZipArchive &zip, WORD uIndex, int iReplaceIndex=-1, bool bKeepSystComp=false)
 Acquire a file with the given index from another archive.
bool GetFromArchive (CZipArchive &zip, CZipWordArray &aIndexes, bool bKeepSystComp=false)
 Acquire files with the given indexes from another archive.
bool GetFromArchive (CZipArchive &zip, CZipStringArray &aNames, bool bKeepSystComp=false)
 Acquire files with the given indexes from another archive.
void GetIndexes (const CZipStringArray &aNames, CZipWordArray &aIndexes)
 Get indexes of the files stored int aNames array and put them into aIndexes.
bool ExtractFile (WORD uIndex, LPCTSTR lpszPath, bool bFullPath=true, LPCTSTR lpszNewName=NULL, DWORD nBufSize=65536)
 Extract the file from the archive.
bool ExtractFile (WORD uIndex, CZipMemFile &mf, bool bRewind=true, DWORD nBufSize=65536)
 The same as ExtractFile(WORD , LPCTSTR , bool , LPCTSTR , DWORD ) but instead to a physical file, this function decompress the data into CZipMemFile object.
bool OpenFile (WORD uIndex)
 Open the file with the given index in the archive for extracting.
DWORD ReadFile (void *pBuf, DWORD iSize)
 Decompress currently opened file to the buffer.
bool TestFile (WORD uIndex, DWORD uBufSize=65536)
 Test the file with the given index for the integrity.
void CloseFileWithNoUpdate ()
 Perform the necessary cleanup after an exception was thrown while testing or extracting the archive so that next files in the archive can be tested or extracted.
int GetLocalExtraField (char *pBuf, int iSize) const
 Get the local extra filed of the currently opened for extraction file in the archive.
int CloseFile (CZipFile &file)
 The same as CZipArchive::CloseFile(LPCTSTR), but additionally closes file.
int CloseFile (LPCTSTR lpszFilePath=NULL, bool bAfterException=false)
 Close the file opened for extraction in the archive and copy its date and attributes to the file pointed by lpszFilePath.
void DeleteFile (WORD uIndex)
 Delete the file from the archive with the given index.
void DeleteFiles (CZipWordArray &aIndexes)
 Delete files from the archive.
void DeleteFiles (const CZipStringArray &aNames)
 Delete files from the archive.
bool SetGlobalComment (LPCTSTR lpszComment)
 Set the global comment in the archive.
CZipString GetGlobalComment () const
bool SetFileComment (WORD uIndex, LPCTSTR lpszComment)
 Set the comment of the file with the given index inside the archive.
CZipString GetArchivePath () const
int GetCurrentDisk () const
int GetSpanMode () const
 Return the disk spanning mode of the current archive.
int FindFile (LPCTSTR lpszFileName, int iCaseSensitive=ffDefault, bool bFileNameOnly=false)
 Find the file in the archive.
bool GetFileInfo (CZipFileHeader &fhInfo, WORD uIndex) const
 Get the info of the file with the given index.
int GetCount (bool bOnlyFiles=false) const
DWORD GetOccupiedSpace () const
 Calculates the actual size (in bytes) currently occupied by the archive.
void Close (int iAfterException=afNoException, bool bUpdateTimeStamp=false)
 Close the archive.
bool IsClosed (bool bArchive=true) const
 Test if the archive is closed (a whole or the current volume only).
void Flush ()
 Write the central directory to the archive and flushes the internal buffers to the disk, so that the archive is finalized on the disk, but you can still modify it.
void SetAutoFlush (bool bAutoFlush=true)
 Set the CZipArchive object to call Flush after each operation that modifies the archive (adding a new file, deleting file(s), modifying the global or a file comment).
bool GetAutoFlush () const
 return the current m_bAutoFlush value
int GetSystemCompatibility () const
 Return the system compatibility of the current archive.
bool SetSystemCompatibility (int iSystemComp)
 Set the system compatibility of the archive.
void SetFileHeaderAttr (CZipFileHeader &header, DWORD uAttr) const
 Set the attributes for CZipFileHeader structure to be used in OpenNewFile method as an argument.
CZipStorageGetStorage ()
 Return the underlying archive storage medium.
void SetDetectZlibMemoryLeaks (bool bDetect)
 Set m_bDetectZlibMemoryLeaks value.
void SetConvertAfterOpen (bool bConvertAfterOpen)
 Set CZipCentralDir::m_bConvertAfterOpen value.
void EnableOemConversion (bool enable)
 Set CZipCentralDir::m_bOemConversion value.
void EnableFindFast (bool bEnable=true)
 Enable fast finding by the file name of the files inside the archive.
int GetFindFastIndex (int iFindFastIndex) const
 After you enable FindFast feature with EnableFindFast, you can retrieve how the files are sorted in CZipCentralDir::m_findarray (you can use it in your own program if you need to display the sorted list and do not want to duplicate data).
void SetTempPath (LPCTSTR lpszPath=NULL, bool bForce=true)
 Set a temporary path used when compressing files and zipsmCheckForEff is specified as an argument in AddNewFile and the disk spanning archive is in creation.
CZipString PredictFileNameInZip (LPCTSTR lpszFilePath, bool bFullPath, int iWhat=prAuto, bool bExactly=false) const
 Given the file path in the form it would be passed to AddNewFile as lpszFilePath argument, the function returns the file name as it would be stored in the archive.
DWORD PredictMaximumFileSizeInArchive (CZipFileHeader &fh) const
 Calculate the maximum number of bytes that the file represented by CZipFileHeader would occupy in the current archive.
DWORD PredictMaximumFileSizeInArchive (LPCTSTR lpszFilePath, bool bFullPath) const
 Calls CZipArchive::PredictMaximumFileSizeInArchive(CZipFileHeader&).
int WillBeDuplicated (LPCTSTR lpszFilePath, bool bFullPath, bool bFileNameOnly=false, int iWhat=prAuto)
 Check if the filename will be duplicted in the archive, if added to the archive in the given form.
CZipString PredictExtractedFileName (LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath, bool bFullPath, LPCTSTR lpszNewName=NULL) const
 Predict the full filename with path after extraction.
CZipString GetTempPath () const
 Return the current value of m_szTempPath.
CZipString TrimRootPath (CZipPathComponent &zpc) const
 Function used in conjunction with m_szRootPath to trim paths in AddNewFile and ExtractFile.
void SetCaseSensitivity (bool bCaseSensitive)
 Set the default archive case-sensitivity.
void GetCentralDirInfo (CZipCentralDir::Info &info) const
 Return the central directory information.
DWORD GetCentralDirSize (bool bWhole=true) const
 Get the central directory size.
bool IsReadOnly ()
 return true if the archive cannot be modified, because it is an existing disk spanning archive or it was opened with zipOpenReadOnly
void SetIgnoreCRC (bool bIgnore=true)
 If you set bIgnore to true, CRC is not checked for the files being tested or extracted.
void SetTreatAsSingleDisk (bool bSingleDisk=true)
 If you set bSingleDisk to true, no disk change will occur while reading an existing archive.
void FindMatches (LPCTSTR lpszPattern, CZipWordArray &ar, bool bFullPath=true) const
 This function finds the indexes of the files, which filenames match the specified pattern and stores these indexes in the array.
bool RenameFile (WORD uIndex, LPCTSTR lpszNewName)
 Change the name of the file with the given index.

Static Public Member Functions

static int SingleToWide (const CZipAutoBuffer &szSingle, CZipString &szWide)
 In non-UNICODE version just copy szSingle to szWide.
static int WideToSingle (LPCTSTR lpWide, CZipAutoBuffer &szSingle)
 In non-UNICODE version just copy lpWide to szSingle.
static void WideConversionUseAnsi (bool bUseAnsi)
 Call it to change how the Unicode string conversion is handled.
static void ReadBytes (void *pDestination, const char *pSource, int iCount)
 Read iCount bytes from pSource into pDestination.
static void WriteBytes (char *pDestination, const void *pSource, int iCount)
 Write iCount bytes from pSource into pDestination.
static bool CompareBytes (const char *pBuffer, const void *pBytes, int iCount)
 Compare iCount bytes.
static const DWORD * GetCRCTable ()
 A helper for a various purposes (needed e.g.
static bool RemovePathBeginning (LPCTSTR lpszBeginning, CZipString &szPath, ZIPSTRINGCOMPARE pCompareFunction)
 Remove lpszBeginning from the beginning of the szPath.

Public Attributes

bool m_bRemoveDriveLetter
 If true, the drive letter is removed from the filename stored inside the archive when adding a new file to the archive.

Protected Types

typedef CZipPtrList< void
* >::iterator 
CZipPtrListIter
enum  OpenFileType { extract = -1, nothing, compress }
 The open mode of the current file inside archive. More...

Protected Member Functions

void MakeSpaceForReplace (int iReplaceIndex, DWORD uTotal, LPCTSTR lpszFileName)
void WriteCentralDirectory (bool bFlush=true)
 Write central directory notifying a callback object if available.
void OpenInternal (int iMode)
 Open the archive in the given mode.
void EmptyPtrList ()
 Free the memory allocated by the zlib library that hasn't been freed due to an error in the zlib library (usually never happens).
void MovePackedFiles (DWORD uStartOffset, DWORD uEndOffset, DWORD uMoveBy, CZipActionCallback *pCallback, bool bForward=false)
 Move the range of data in the archive specified by the uStartOffset and uEndOffset by uToMove.
bool RemoveLast (bool bRemoveAnyway=false)
 Remove recently added file (used by AddNewFile) if compressed is larger than uncompressed or if callback method return false.
bool GetFromArchive (CZipArchive &zip, WORD uIndex, int iReplaceIndex, bool bKeepSystComp, CZipActionCallback *pCallback)
 It is used in GetFromArchive public functions and in AddNewFile and the callback parameter is needed.
bool UpdateReplaceIndex (int &iReplaceIndex, LPCTSTR lpszNewFileName)
CZipFileHeaderCurrentFile ()
void CheckForError (int iErr)
 If the parameter iErr signalizes a zlib library error, throw CZipException.
void ThrowError (int err, bool bZlib=false)
 Throw a CZipException error.
void CryptDecodeBuffer (DWORD uCount)
 Decode uCount bytes from the internal buffer.
void CryptEncodeBuffer ()
 Encode the internal buffer.
void CryptEncode (char &c)
 Encode the character c and update encryption keys .
void CryptCryptHeader (long iCrc, CZipAutoBuffer &buf)
 Create an encryption header for the new file in the archive.
DWORD CryptCRC32 (DWORD l, char c)
void CryptDecode (char &c)
 Decode the character c and update encryption keys .
char CryptDecryptByte ()
bool CryptCheck ()
 Decrypt the encryption header and check its control value.
void CryptUpdateKeys (char c)
 Update encryption keys with the given value.
void CryptInitKeys ()
 Initialize encryption keys .

Static Protected Member Functions

static void * _zliballoc (void *opaque, UINT items, UINT size)
 memory allocator called by the zlib library
static void _zlibfree (void *opaque, void *address)
 memory deallocator called by the zlib library

Protected Attributes

CZipClbckStrg m_callbacks
bool m_bCaseSensitive
 Default archive case-sensitivity.
ZIPSTRINGCOMPARE m_pZipCompare
 a pointer to the function in CZipString structure, used to compare elements; can point to Compare, CompareNoCase, Collate or CollateNoCase function address in CZipString structure ZIPSTRINGCOMPARE is defined as follows:
typedef int (CZipString::*ZIPSTRINGCOMPARE)( LPCTSTR ) const;
CZipInternalInfo m_info
 Internal data.
CZipStorage m_storage
 Physical layer of the archive.
CZipCentralDir m_centralDir
 A central directory object.
char m_iFileOpened
 Takes one of the OpenFileType enum values.
bool m_bAutoFlush
 The current AutoFlush value.
bool m_bIgnoreCRC
 The value set with SetIgnoreCRC.
CZipString m_szRootPath
 The root path to be omitted in AddNewFile and ExtractFile functions from the beginning of the full file path.
CZipString m_szTempPath
 A temporary path set with SetTempPath function.
int m_iArchiveSystCompatib
 The system code of the current archive.
CZipPtrList< void * > m_list
 a list holding pointers to the memory areas allocated by the zlib library
bool m_bDetectZlibMemoryLeaks
 Specify whether to control memory allocation and freeing by the zlib library.
CZipAutoBuffer m_pszPassword
 The archive password.
DWORD m_keys [3]
 Encryption keys.

Static Protected Attributes

static void(* m_pReadBytes )(void *, const char *, int)
 Used in ReadBytes.
static void(* m_pWriteBytes )(char *, const void *, int)
 Used in WriteBytes.
static bool(* m_pCompareBytes )(const char *, const void *, int)
 Used in CompareBytes.
static bool g_bWideConversionUseAnsi
static const TCHAR m_gszCopyright []
 Copyright string.

Classes

class  CWildcard
 A class used in wildcard pattern matching. More...
struct  CZipClbckStrg
 Storage for callback objects. More...
struct  CZipDeleteInfo
 Holds map of holes and areas to remain when deleting files from the archive. More...
struct  CZipInternalInfo
 The purpose of this structure is to hold the data that allow communication with the zlib library. More...
struct  CZipSmClrPass
 A structure for the internal use only. More...


Detailed Description

The representation of the zip archive file.

This class provides all the operations on the zip archive.

Definition at line 217 of file ZipArchive.h.


Member Enumeration Documentation

enum CZipArchive::CallbackType
 

Enum values used as iWhich parameter in SetCallback function.

You can assign several values to the same callback object (OR them)

See also:
CZipActionCallback
Enumerator:
cbNothing  you can use it for your own purposes
cbAdd  called when adding a file with one of AddNewFile functions
cbAddTmp  called while adding a file (only on a disk-spanning archive) when the smartness level contains CZipArchive::zipsmCheckForEff or CZipArchive::zipsmCheckForEffInMem and if just compressed file is being moved from a temporary place (file or memory) to the archive
cbAddStore  called while adding a file and if it's compressing has proven to be inefficient and it is now being stored (instead of compressed) in the archive; smartness level must contain CZipArchive::zipsmCheckForEff or CZipArchive::zipsmCheckForEffInMem; the archive can be disk-spanning or not
cbExtract  called when extracting a file with one of ExtractFile functions
cbDeleteCnt  called before the actual deletion takes place and the map of holes and continuous areas is being created (it safe to break it by returning false from the callback method)
cbDelete  called when moving data while deleting file(s) with function DeleteFile or one of DeleteFiles functions
cbTest  called when testing a file with TestFile function
cbSave  called when saving the central directory with CZipCentralDir::Write (usually on close or flush); it is safe to break on non-disk spanning archive - the saved part of the central directory will be removed from disk
cbGetFromArchive  called when using one of GetFromArchive methods
cbRename  called when during the renaming a file there is a need to make less or more space for the new filename
cbReplace  called when moving data while replacing files to make less or more space for the new file
cbNextValue  for CZipActionCallback overrides and user defined callbacks
cbSubActions  sub actions - they are part of bigger actions (cbAddTmp | cbAddStore | cbDeleteCnt | cbReplace)
cbActions  main actions (cbAdd | cbExtract | cbDelete | cbTest | cbSave | cbGetFromArchive | cbRename)
cbAll  assign all callbacks to the same callback object

Definition at line 418 of file ZipArchive.h.

enum CZipArchive::CloseAfterException
 

values used in Close function as parameter iAfterException

Enumerator:
afNoException  normal close, no exception was thrown before by CZipArchive object
afAfterException  an exception has been thrown, don't write any data but perform necessary cleaning to reuse CZipArchive object for another archive
afWriteDir  the same as above, but write the central directory end structure to the archive, so that we can save at least the files that have been added properly and maybe try to repair the archive later

Definition at line 1228 of file ZipArchive.h.

enum CZipArchive::FFCaseSens
 

case-sensitivity values used as argument iCaseSensitive in FindFile

Enumerator:
ffDefault  use the default case-sensitivity as set with SetCaseSensitivity function; if CZipCentralDir::m_findarray was build before with a different case-sensitivity, it is rebuild again, if it hasn't been build so far, it is build now with the default case-sensitivity
ffCaseSens  perform a case-sensitive search (if the CZipArchive is non-case-sensitive, a less effective search is perfomed); does not rebuild CZipCentralDir::m_findarray, but if the array hasn't been built yet, it is build now as non-case-sensitive (you can use SetCaseSensitivity(true) and then ffDefault to build it as case-sensitive)
ffNoCaseSens  perform a non-case-sensitive search (if the CZipArchive is case-sensitive, a less effective search is performed); does not rebuild CZipCentralDir::m_findarray, but if the array hasn't been built yet, it is build now as case-sensitive (you can use SetCaseSensitivity(false) and then ffDefault to build it as non-case-sensitive)

Definition at line 1137 of file ZipArchive.h.

enum CZipArchive::OpenFileType [protected]
 

The open mode of the current file inside archive.

Enumerator:
extract  current file opened for extraction
nothing  no file inside archive opened
compress  a new file opened for compression

Definition at line 2010 of file ZipArchive.h.

enum CZipArchive::OpenMode
 

Archive open modes used in Open(LPCTSTR , int , int ) and Open(CZipAbstractFile&, int ) .

Enumerator:
zipOpen  open an existing archive
zipOpenReadOnly  Open an existing archive as a read only file.

This mode is intended to use in a self extract code or opening archive on storage without write access (e.g. CD-ROMS), If you try to modify the archive in this mode, an exception will be thrown.

zipCreate  create a new archive
zipCreateSpan  create a disk spanning archive

Definition at line 497 of file ZipArchive.h.

enum CZipArchive::Predict
 

enum values used in PredictFileNameInZip

Enumerator:
prDir  if an argument is a directory, add a separator at the end
prFile  treat the argument as a common file
prAuto  treat the argument as a directory only if it has a path separator at the end

Definition at line 1509 of file ZipArchive.h.

enum CZipArchive::Smartness
 

The levels of smartness of the adding files action (see AddNewFile).

Note:
If you wish to use zipsmCheckForEff, you should use zipsmNotCompSmall as well, because it will save you the time ( the small file will be surely larger after compression, so that we can add it not compressed straight away);the compression level is always ignored for a directory and set to 0
Enumerator:
zipsmLazy  do not bother (you know what you're doing after all)
zipsmCPassDir  clear password for directories
zipsmCPFile0  clear password for files of 0 size
zipsmNotCompSmall  do not compress files smaller than 5 bytes (they are always stored larger than uncompressed)
zipsmCheckForEff  check whether the compressed file is larger than uncompressed and if so, remove it and store without the compression; in the disk spanning mode, the temporary file is used for that: if the file compression is efficient, the data is not compressed again, but moved from the temporary file to the archive; you can use SetTempPath() to set the path where the file will be created or you can let the library figure it out (the library tries first the system default temporary directory, if it is not present or there is not enough space there, it tries the current directory, if it fails, no temporary file is created and the compression goes the usual way
zipsmMemoryFlag  combine it with zipsmCheckForEff or use zipsmCheckForEffInMem, you can also use this when replacing files see note at CZipAddNewFileInfo::m_iReplaceIndex
zipsmCheckForEffInMem  the same as zipsmCheckForEff, but the temporary file is created created in memory instead (the temporary directory set with SetTempPath() is ignored); has the meaning only with a disk-spanning archive, non-disk spanning archives don't need a temporary file
zipsmSmartPass  smart password policy (a combination of zipsmCPassDir and zipsmCPFile0)
zipsmSmartAdd  smart adding (a combination of zipsmNotCompSmall and zipsmCheckForEff)
zipsmSafeSmart  safe smart (smartest without checking for efficiency)
zipsmSmartest  smart at its best
zipsmInternal01  for internal use only

Definition at line 602 of file ZipArchive.h.


Member Function Documentation

bool CZipArchive::AddNewFile CZipMemFile mf,
LPCTSTR  lpszFileNameInZip,
int  iComprLevel = -1,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536
 

See also:
AddNewFile(CZipAddNewFileInfo& ); the parameters are equivalent to CZipAddNewFileInfo member variables

bool CZipArchive::AddNewFile LPCTSTR  lpszFilePath,
LPCTSTR  lpszFileNameInZip,
int  iComprLevel = -1,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536
 

See also:
AddNewFile(CZipAddNewFileInfo& ); the parameters are equivalent to CZipAddNewFileInfo member variables

bool CZipArchive::AddNewFile LPCTSTR  lpszFilePath,
int  iComprLevel = -1,
bool  bFullPath = true,
int  iSmartLevel = zipsmSafeSmart,
unsigned long  nBufSize = 65536
 

See also:
AddNewFile(CZipAddNewFileInfo& ); the parameters are equivalent to CZipAddNewFileInfo member variables

bool CZipArchive::AddNewFile CZipAddNewFileInfo info  ) 
 

Add a new file to the archive.

You can set the callback object with SetCallback.

Parameters:
info see CZipAddNewFileInfo
Returns:
if it returns false then the file was not added, but the internal state allows you to add other files (which is not possible after throwing an exception)
Note:
  • If you abort while adding a file in a non-disk-spanning archive, the added data will be removed from the archive
  • Throws exceptions.
See also:
SetCallback

AddNewFile(LPCTSTR, LPCTSTR, int, int, unsigned long)

AddNewFile(LPCTSTR, int, bool, int, unsigned long)

AddNewFile(CZipMemFile&, LPCTSTR, int, int, unsigned long)

void CZipArchive::CheckForError int  iErr  )  [protected]
 

If the parameter iErr signalizes a zlib library error, throw CZipException.

Parameters:
iErr a zlib library error to check
Note:
Throws exceptions.

void CZipArchive::Close int  iAfterException = afNoException,
bool  bUpdateTimeStamp = false
 

Close the archive.

Parameters:
iAfterException one of CloseAfterException enum values
bUpdateTimeStamp if true, set the modification date of the zip file to the date of the newest file in the archive; in disk-spanning mode only the last archive file will have the time stamp updated; you can use this option even without performing any additional processing on the archive, just open and close it
Note:
Throws exceptions if iAfterException is different from afAfterException

int CZipArchive::CloseFile LPCTSTR  lpszFilePath = NULL,
bool  bAfterException = false
 

Close the file opened for extraction in the archive and copy its date and attributes to the file pointed by lpszFilePath.

Parameters:
lpszFilePath Points to the path of the file to have the date and attributes information updated.
bAfterException Set to true to close the file inside archive after an exception has been thrown, to allow futher operations on the archive.
Warning:
Close the file pointed by lpszFilePath before using this method, because the system may not be able to retrieve information from it.
Returns:

  • "1" = ok
  • "-1" = some bytes left to uncompress - probably due to a bad password or corrupted archive
  • "-2" = setting extracted file date and attributes was not successful
Note:
Throws exceptions.

int CZipArchive::CloseFile CZipFile &  file  ) 
 

The same as CZipArchive::CloseFile(LPCTSTR), but additionally closes file.

Parameters:
file OPENED CZipFile structure of the extracted file
Returns:
Note:
Throws exceptions.
See also:
CZipArchive::CloseFile(LPCTSTR)

void CZipArchive::CloseFileWithNoUpdate  ) 
 

Perform the necessary cleanup after an exception was thrown while testing or extracting the archive so that next files in the archive can be tested or extracted.

Called by TestFile. Does not remove the file headers information from the central directory. You can use this method after you have extracted only part of the file (not entire file) and you wish to close it.

See also:
TestFile

CZipCentralDir::Clear

bool CZipArchive::CloseNewFile bool  bAfterException = false  ) 
 

Close the new file in the archive.

Returns:
false if there is no new file opened
Parameters:
bAfterException it will close the new file without writing anything (call it also with this parameter set to true after an exception other than CZipException::abortedSafely was thrown from one of AddNewFile functions)
Note:
Throws exceptions.
See also:
OpenNewFile

static bool CZipArchive::CompareBytes const char *  pBuffer,
const void *  pBytes,
int  iCount
[inline, static]
 

Compare iCount bytes.

Parameters:
pBuffer always little-endian ordered
pBytes byte-order depends on the machine
iCount bytes to compare

Definition at line 357 of file ZipArchive.h.

References ZipCompatibility::CompareBytesBigEndian(), ZipCompatibility::CompareBytesLittleEndian(), and ZipCompatibility::IsBigEndian().

CZipFileHeader* CZipArchive::CurrentFile  )  [protected]
 

Returns:
the currently opened for compression or decompression file inside the archive NULL if there is no file opened

void CZipArchive::DeleteFile WORD  uIndex  ) 
 

Delete the file from the archive with the given index.

You can set the callback object with SetCallback. If you plan to delete more than one file, use one of DeleteFiles functions rather than calling DeleteFile successively, because these functions are optimized for deleting multiple files

Parameters:
uIndex a zero-based index
Note:
Throws exceptions.
See also:
SetCallback

DeleteFiles(CZipWordArray&)

DeleteFiles(const CZipStringArray&)

FindMatches

void CZipArchive::DeleteFiles const CZipStringArray &  aNames  ) 
 

Delete files from the archive.

You can set the callback object with SetCallback.

Parameters:
aNames an array of filenames inside the archive;
Note:
  • Set the case-sensitivity with SetCaseSensitivity
  • Enables FindFast if not enabled
  • Throws exceptions.
See also:
SetCallback

DeleteFile

DeleteFiles(CZipWordArray&)

EnableFindFast

void CZipArchive::DeleteFiles CZipWordArray &  aIndexes  ) 
 

Delete files from the archive.

You can set the callback object with SetCallback. Sorts aIndexes array in an ascending order.

Parameters:
aIndexes an array of zero-based indexes of the files inside the archive
Note:
  • To remove files which filenames match a specified pattern, use FindMatches function
  • Throws exceptions.
See also:
SetCallback

DeleteFile

DeleteFiles(const CZipStringArray& )

FindMatches

void CZipArchive::EnableFindFast bool  bEnable = true  ) 
 

Enable fast finding by the file name of the files inside the archive.

Set CZipCentralDir::m_bFindFastEnabled to true, which is required by FindFile. It is called by FindFile if necessary. It builds CZipCentralDir::m_findarray with the default case-sensitivity (set with SetCaseSensitivity)

Note:
Call it only after opening the archive.
Parameters:
bEnable 
See also:
CZipCentralDir::m_bFindFastEnabled

FindFile

void CZipArchive::EnableOemConversion bool  enable  )  [inline]
 

Set CZipCentralDir::m_bOemConversion value.

This has only effect on the archives that are created or read under Windows platform. The default value is true. It enables or disables OEM conversion of the filenames in the archive. The OEM conversion is not desired when filenames contain e.g. Japanese or Korean characters. You need to disable the OEM conversion in this case to properly extract the filenames later. Disabling the OEM conversion and creating a new archive in this mode, will make the filenames with non-US characters not properly readable under other Windows archivers (e.g. WinRar, WinZip).

Parameters:
enable 
Note:
Use before opening the archive.
See also:
CZipCentralDir::m_bOemConversion

WideConversionUseAnsi

Definition at line 1436 of file ZipArchive.h.

bool CZipArchive::ExtractFile WORD  uIndex,
CZipMemFile mf,
bool  bRewind = true,
DWORD  nBufSize = 65536
 

The same as ExtractFile(WORD , LPCTSTR , bool , LPCTSTR , DWORD ) but instead to a physical file, this function decompress the data into CZipMemFile object.

Parameters:
uIndex the index of the file to extract
mf the memory file to receive decompressed data
bRewind if true, the current memory file pointer is positioned at the beginning of the compressed data after compression (even if it was aborted, but not if other exception than CZipException::abortedAction or CZipException::abortedSafely was thrown in the meantime)
nBufSize the size of the buffer used while file operations
Note:
  • writting decompressed file starts at the current position of the memory file; pay attention to this if you pass CZipMemFile object that already contains data (or has a buffer attached) - its contents may be overwirtten
  • if you try to extract a directory, the function will return false

bool CZipArchive::ExtractFile WORD  uIndex,
LPCTSTR  lpszPath,
bool  bFullPath = true,
LPCTSTR  lpszNewName = NULL,
DWORD  nBufSize = 65536
 

Extract the file from the archive.

You can set the callback object with SetCallback. The argument lpszNewName may point to the full path and is influenced by bFullPath argument (if lpszNewName contains drive specification then it is removed)

Parameters:
uIndex the index of the file to extract
lpszPath 
		The PATH only to extract the file to. May not be NULL. If you wish to 
		use UNC path you need to replace \\\\ at the beginning of UNC path with \\\\?\UNC\ .
	
bFullPath 
  • if true, then extract with the full path - in this case the resulting file path is lpszPath plus the path stored in the archive or plus lpszNewName if lpszNewName is not NULL.
  • if false, the destination file path is lpszPath + the filename only extracted from the path stored in the archive or from lpszNewName if lpszNewName is specified;
    if m_szRootPath is set previously with SetRootPath then to lpszPath is added the path stored in the archive (or lpszNewName if lpszNewName is specified) that has removed the beginning that equals m_szRootPath (if there is no common beginning then is behaves like m_szRootPath was empty)
lpszNewName The new name of the file after extraction. If NULL the original filename stored in the archive is used. May point to the full path but, if bFullPath is false, only the filename is extracted from this argument,
nBufSize the size of the buffer used while file operations
Returns:
true if successful
Note:
  • To extract files which filenames match a specified pattern, use FindMatches function
  • Throws exceptions.
See also:
SetCallback

ExtractFile(WORD, CZipMemFile&, DWORD)

FindMatches

int CZipArchive::FindFile LPCTSTR  lpszFileName,
int  iCaseSensitive = ffDefault,
bool  bFileNameOnly = false
 

Find the file in the archive.

If the archive wasn't opened with CZipCentralDir::m_bConvertAfterOpen set to true, this function automatically convert all the filenames with the function CZipCentralDir::ConvertAll and set CZipCentralDir::m_bConvertAfterOpen to true. This function requires FindFast feature enabled.

Parameters:
lpszFileName the name of the file to be found in the archive; must be with path unless you set bFileNameOnly to true. Use path separators the same as they are for your system ("\" for Windows and "/" for Unix/Linux)
iCaseSensitive can be one of FFCaseSens values
bFileNameOnly if true, the function tries to find a filename without a path (a less effective search is performed); if you wish to find a directory name, do not end it with the path separator, which is required if you set bFileName to false
Returns:

  • the index of the file found
  • -1 if there is no such a file in the archive
See also:
CZipCentralDir::FindFileNameIndex

EnableFindFast

CZipCentralDir::ConvertAll

SetConvertAfterOpen

void CZipArchive::FindMatches LPCTSTR  lpszPattern,
CZipWordArray &  ar,
bool  bFullPath = true
const
 

This function finds the indexes of the files, which filenames match the specified pattern and stores these indexes in the array.

The indexes can be used then e.g. in deleting (CZipArchive::DeleteFiles) or extracting files (CZipArchive::ExtractFile).

Parameters:
lpszPattern the pattern to match (see CWildcard::SetPattern on how to build the pattern). The case-sensitivity of the pattern is set to the global archive case-sensitivity (set with SetCaseSensitivity)
ar the array which will contain the indexes of the files which filenames match the pattern; the contents of the array are NOT clearead, but the indexes are appended to it
bFullPath 
  • if true, match the filename with path (if present) of the file (if the file is a directory, end it with the path separator or use a pattern that will recognize it)
  • otherwise match only the name of the file (if the file is a directory, do not end it with the path separator)

void CZipArchive::Flush  ) 
 

Write the central directory to the archive and flushes the internal buffers to the disk, so that the archive is finalized on the disk, but you can still modify it.

Use it after opening (or creating) and modifying the archive if you want to prevent the loss of the data you've compressed so far in case of the program crash.
If you use it on a disk spanning archive in creation it will not be closed, but its state will be changed from "archive in creation" to "an existing span archive". Use it when you finish adding files to the disk-spanning archive and want to begin extracting or testing it. It follows that you can call it only once in this case. However, if after finalizing the disk spanning archive it turns out that it is one disk only, it is converted to a normal archive and you can use it as such. If you want to know what is the state of the archive after using this function call GetSpanMode.

Note:
  • Cannot be used on existing disk spanning archives (they are not modifable anyway)
  • If you have an archive with a huge central directory, it'll influence the perfomance calling this function without a reason.
  • Throws exceptions.
See also:
GetSpanMode

SetAutoFlush

GetAutoFlush

CZipString CZipArchive::GetArchivePath  )  const
 

Returns:
the path of the currently opened archive volume

bool CZipArchive::GetAutoFlush  )  const [inline]
 

return the current m_bAutoFlush value

See also:
Flush

SetAutoFlush

Definition at line 1304 of file ZipArchive.h.

CZipActionCallback* CZipArchive::GetCallback CallbackType  iWhich  )  [inline]
 

Returns:
the callback iWhich set with SetCallback

Definition at line 468 of file ZipArchive.h.

void CZipArchive::GetCentralDirInfo CZipCentralDir::Info info  )  const
 

Return the central directory information.

See also:
GetCentralDirSize

DWORD CZipArchive::GetCentralDirSize bool  bWhole = true  )  const [inline]
 

Get the central directory size.

See also:
CZipCentralDir::GetSize

GetCentralDirInfo

Definition at line 1676 of file ZipArchive.h.

int CZipArchive::GetCount bool  bOnlyFiles = false  )  const [inline]
 

Parameters:
bOnlyFiles if true, the directories are not inluded in a total count; default is false
Returns:
the number of files in the archive

Definition at line 1196 of file ZipArchive.h.

static const DWORD* CZipArchive::GetCRCTable  )  [inline, static]
 

A helper for a various purposes (needed e.g.

by the program that cracks the zip archives password)

Returns:
the pointer to the static CRC table in the zlib library

Definition at line 1365 of file ZipArchive.h.

int CZipArchive::GetCurrentDisk  )  const
 

Returns:

  • a one-based number of the current disk
  • 0 if there is no current disk (the archive is closed)
Note:
Useful mostly while working with the disk-spanning archive in creation to find out how many disks were already created. To find out how many disks are in an existing disk-spanning archive, use the function GetCentralDirInfo

bool CZipArchive::GetFileInfo CZipFileHeader fhInfo,
WORD  uIndex
const
 

Get the info of the file with the given index.

Parameters:
fhInfo the structure to receive info
uIndex a zero-based index of the file inside the archive
Returns:
true if successful

int CZipArchive::GetFindFastIndex int  iFindFastIndex  )  const [inline]
 

After you enable FindFast feature with EnableFindFast, you can retrieve how the files are sorted in CZipCentralDir::m_findarray (you can use it in your own program if you need to display the sorted list and do not want to duplicate data).

Parameters:
iFindFastIndex index in CZipCentralDir::m_findarray (not necessary the same as the one you'd pass to GetFileInfo); the number of items in this array is the same as the number of files in the archive (you can retrieve it with GetCount)
Returns:
index of the file in central directory (now you can call GetFileInfo to get the information); if the value is -1 then you have not called EnableFindFast before or the archive is closed or the iFindFastIndex is out of range)

Definition at line 1477 of file ZipArchive.h.

bool CZipArchive::GetFromArchive CZipArchive zip,
CZipStringArray &  aNames,
bool  bKeepSystComp = false
[inline]
 

Acquire files with the given indexes from another archive.

Parameters:
zip another archive
aNames an array of filenames inside the zip archive;
bKeepSystComp if true, the system compatibility of the source archive will be used for copied entries, otherwise they will be converted to match the system compatibility of the current archive
See also:
GetFromArchive(CZipArchive& , WORD, int, bool)

EnableFindFast

Note:

Definition at line 850 of file ZipArchive.h.

References GetIndexes().

bool CZipArchive::GetFromArchive CZipArchive zip,
CZipWordArray &  aIndexes,
bool  bKeepSystComp = false
 

Acquire files with the given indexes from another archive.

Parameters:
zip another archive
aIndexes an array of zero-based indexes of the files inside the zip archive
bKeepSystComp if true, the system compatibility of the source archive will be used for copied entries, otherwise they will be converted to match the system compatibility of the current archive
See also:
GetFromArchive(CZipArchive& , WORD, int, bool)
Note:
  • To get files which filenames match a specified pattern, use FindMatches function

bool CZipArchive::GetFromArchive CZipArchive zip,
WORD  uIndex,
int  iReplaceIndex = -1,
bool  bKeepSystComp = false
[inline]
 

Acquire a file with the given index from another archive.

The compressed data of the file from another archive are copied without decompressing to the current archive. You can set the callback object with SetCallback.

Parameters:
zip an opened archive to get the file from (must not be multi-disk)
uIndex a zero-based index of the file to get from the zip archive
iReplaceIndex the same as CZipAddNewFileInfo::m_iReplaceIndex
bKeepSystComp if false, which is default, then the file from zip archive system compatibility is converted to the current archive system compatibility (if they differ)
Returns:
false if the operation could not be performed (either of archives is closed, a file inside either of archives is opened, zip archive is multi-disk or the current archive is an existing multi-disk archive)
Note:
Throws exceptions
(when an exception is thrown, you may need to call CloseNewFile with bAfterException set to true, to make the archive reusable).

it is safe to abort the action (by returning false from the callback call) in non-disk spanning archive and when no replacing is taking place (the file not entirely added is removed from the archive)

See also:
SetCallback

GetFromArchive(CZipArchive& , CZipWordArray &, bool)

GetFromArchive(CZipArchive& , CZipStringArray &, bool)

FindMatches

SetAdvanced

Definition at line 795 of file ZipArchive.h.

CZipString CZipArchive::GetGlobalComment  )  const
 

Returns:
the global comment or an empty string if the archive is closed

void CZipArchive::GetIndexes const CZipStringArray &  aNames,
CZipWordArray &  aIndexes
 

Get indexes of the files stored int aNames array and put them into aIndexes.

Parameters:
aNames an array of filenames inside the archive;
aIndexes an array of indexes to be build
Note:

Referenced by GetFromArchive().

int CZipArchive::GetLocalExtraField char *  pBuf,
int  iSize
const
 

Get the local extra filed of the currently opened for extraction file in the archive.

Parameters:
pBuf the buffer to receive the data
iSize the size of the buffer
Returns:
If pBuf is NULL or iSize is 0, returns the size of the local extra field. Returns -1 if there is no file opened for the extraction.

DWORD CZipArchive::GetOccupiedSpace  )  const [inline]
 

Calculates the actual size (in bytes) currently occupied by the archive.

Returns:
the sum of the lenght of the current archive volume, the number of bytes in the write buffer and the whole size of the central directory
Note:
if the archive or a volume is closed, the return value is 0

Definition at line 1215 of file ZipArchive.h.

CZipString CZipArchive::GetPassword  )  const
 

Returns:
the current archive password or an empty string if there is no password

Referenced by CZipArchive::CZipSmClrPass::ClearPasswordSmartly().

CZipString CZipArchive::GetRootPath  )  const [inline]
 

Return the current value of m_szRootPath.

Returns:
CZipString

Definition at line 588 of file ZipArchive.h.

int CZipArchive::GetSpanMode  )  const [inline]
 

Return the disk spanning mode of the current archive.

Returns:

  • -2 - existing TD mode compatible disk spanning archive
  • -1 - existing PKZIP compatible
  • 0 - no disk spanning
  • 1 - PKZIP compatible in creation
  • 2 - TD compatible in creation
See also:
PKSpan, TDSpan

Definition at line 1129 of file ZipArchive.h.

CZipStorage* CZipArchive::GetStorage  )  [inline]
 

Return the underlying archive storage medium.

Warning:
A method for a very advanced use - you normally never need it.
Returns:
the pointer to m_storage
See also:
CZipStorage

Definition at line 1376 of file ZipArchive.h.

int CZipArchive::GetSystemCompatibility  )  const [inline]
 

Return the system compatibility of the current archive.

System compatibility value for the single file in the archive (represented by CZipFileHeader) influences file attributes conversion (the file attributes are defined differently across the platforms). When opening an existing archive CZipArchive assumes the system compatibility of the whole archive to be the same as of the first file in the archive (if present). In other cases the current system value is assumed which is taken from ZipPlatform::GetSystemID during creating or opening an archive

Remarks:
If the existing archive during opening is empty, ZipPlatform::GetSystemID is assumed to be the default system for the files that will be added to the archive.
Returns:
one of the enum values defined in ZipCompatibility.h
See also:
ZipCompatibility::ZipPlatforms

ZipPlatform::GetSystemID

CZipFileHeader::GetSystemCompatibility

Definition at line 1326 of file ZipArchive.h.

CZipString CZipArchive::GetTempPath  )  const [inline]
 

Return the current value of m_szTempPath.

Returns:
CZipString

Definition at line 1613 of file ZipArchive.h.

bool CZipArchive::IsClosed bool  bArchive = true  )  const [inline]
 

Test if the archive is closed (a whole or the current volume only).

Parameters:
bArchive 
  • true: test for the whole archive
  • false: test for the volume file only
Returns:
true if closed

Definition at line 1257 of file ZipArchive.h.

void CZipArchive::MakeSpaceForReplace int  iReplaceIndex,
DWORD  uTotal,
LPCTSTR  lpszFileName
[protected]
 

Parameters:
iReplaceIndex index of file to be replaced
uTotal the size of the new file to replace existing
lpszFileName the filename for callback initialization

void CZipArchive::Open CZipAbstractFile &  af,
int  iMode = zipOpen
 

Open or create the archive in memory.

The CZipAbstractFile object is not closed after closing the archive, so that is it possible to work with it afterwards.

Parameters:
af CZipAbstractFile structure to create archive in or extract from
Note:
This is important: you shouldn't destroy CZipAbstractFile object before closing the archive, because you'll get an error;
Parameters:
iMode Open mode. The following modes are valid: zipOpen, zipOpenReadOnly, zipCreate
Note:
Throws exceptions.
See also:
Open(LPCTSTR, int, int);

void CZipArchive::Open LPCTSTR  szPathName,
int  iMode = zipOpen,
int  iVolumeSize = 0
 

Open or create a zip archive.

The archive creation mode depends on iMode and iVolumesSize values:

  • if iMode == zipCreateSpan and iVolumeSize <= 0 then create disk spanning archive in PKZIP compatible mode (pkzipSpan)
  • if iMode == zipCreateSpan and iVolumeSize > 0 then create disk spanning archive in TD compatible mode (tdSpan)
  • if iMode == zipOpen and the existing archive is a spanned archive then pkzipSpan mode is assumed if the archive is on a removable device or tdSpan otherwise;
    if you want to open tdSpan archive on a removable device, set iVolumeSize to a value different from 0
  • if iMode == zipCreate then iVolumeSize doesn't matter

Parameters:
szPathName the path to the archive
iMode one of the OpenMode values
iVolumeSize the volume size in the disk spanning archive; the size of the volume may be from 1 to INT_MAX , and the bigger - the faster is creation and extraction (no file changes between volumes) - but the size of the whole archive is the same. If you're creating disk-spanning archive in TD span compatible mode and plan later to convert it to PKZIP compatible mode (see Multi-disk archives), it is good to set this this value to about the size of the diskette (a little less just in case).
Note:
Throws exceptions.
See also:
Open(CZipMemFile&, int);

GetSpanMode

bool CZipArchive::OpenFile WORD  uIndex  ) 
 

Open the file with the given index in the archive for extracting.

Not successful opening the file doesn't lock the whole archive, so you can try to open another one (after catching an exception if it was thrown). Throw exception CZipException::badPassword if the password was not set for the encrypted file.

Parameters:
uIndex the index of the file
Returns:
true if successful
Note:
Throws exceptions.

void CZipArchive::OpenInternal int  iMode  )  [protected]
 

Open the archive in the given mode.

Called by Open(LPCTSTR, int, int) and Open(CZipAbstractFile&, int).

Parameters:
iMode an opening mode
Note:
Throws exceptions.

bool CZipArchive::OpenNewFile CZipFileHeader header,
int  iLevel = Z_DEFAULT_COMPRESSION,
LPCTSTR  lpszFilePath = NULL,
DWORD  uInternal = 0
 

Add a new file to the opened zip archive.

The zip archive cannot be an existing disk spanning archive (existing at the moment of opening archive), because modifying such an archive is not possible (at least not with this version ).

Parameters:
header The structure that provides additional information about the added file. The following fields are valid:
  • m_uMethod - file compression method; can be 0 (storing) or Z_DEFLATE (deflating) otherwise Z_DEFLATE is assumed
  • m_uModDate, m_uModTime - Use CZipFileHeader::SetTime to set them. If lpszFilePath is not NULL this fields are overwritten and updated automatically. See CZipFileHeader::SetTime
  • m_uExternalAttr - Attributes of the file. If lpszFilePath is not NULL this field is overwritten and updated automatically. Use SetFileHeaderAttr to set them. See SetFileHeaderAttr.
  • m_szFileName - A filename (may be with path) to be stored inside archive to represent this file. See CZipFileHeader::SetFileName
  • m_szComment - A file comment. See CZipFileHeader::SetComment
  • m_pExtraField - LOCAL extra field, use SetExtraField after opening a new file, but before closing it to set the not local extra field in the header in the central directory. See SetExtraField
    Other fields are ignored - they are updated automatically. If the function returns true, system compatibility for this object is set to the correct value (the same as m_iArchiveSystCompatib), additionally if lpszFilePath was not NULL, the attributes and the time fields are filled with information retrieved from the file pointed by lpszFilePath.
iLevel The level of compression (-1, 0 - 9). The are several preset values for the compression level:
  • Z_DEFAULT_COMPRESSION : -1 (equals 6)
  • Z_NO_COMPRESSION : 0
  • Z_BEST_SPEED : 1
  • Z_BEST_COMPRESSION : 9
lpszFilePath The path to the file to retrieve date stamp and attributes from. These values are stored inside the archive.
uInternal for internal use only
Returns:
false in the following cases:
  • the lpszFilePath is not NULL and the file attributes and data was not correctly retrieved
  • a file is already opened for extraction or compression
  • archive is an existing disk span archive
  • maximum file count inside archive already reached (65536)
Note:
Throws exceptions.

CZipString CZipArchive::PredictExtractedFileName LPCTSTR  lpszFileNameInZip,
LPCTSTR  lpszPath,
bool  bFullPath,
LPCTSTR  lpszNewName = NULL
const
 

Predict the full filename with path after extraction.

The parameters (except for the first) are in the form you'd pass to the ExtractFile(WORD , LPCTSTR , bool , LPCTSTR , DWORD ) function. The function takes into account the root path set with SetRootPath.

Parameters:
lpszFileNameInZip the filename of the file inside the archive (may be NULL if lpszNewName is not NULL)
lpszPath 
bFullPath 
lpszNewName 
Returns:
a predicted file path

CZipString CZipArchive::PredictFileNameInZip LPCTSTR  lpszFilePath,
bool  bFullPath,
int  iWhat = prAuto,
bool  bExactly = false
const
 

Given the file path in the form it would be passed to AddNewFile as lpszFilePath argument, the function returns the file name as it would be stored in the archive.


The function takes into account the root path set with SetRootPath. You can use this function to eliminate duplicates before adding a list of files.

Parameters:
lpszFilePath the file path as it would be passed to AddNewFile function
bFullPath the same as bFullPath in AddNewFile
iWhat one of Predict values to treat lpszFilePath correctly
bExactly if true, return the filename exactly as it would look inside the archive i.e. convert slash to backslash, and perform ANSI->OEM conversion; otherwise return the filename with the path separators that are used by default in the system
Returns:
a modified file path

DWORD CZipArchive::PredictMaximumFileSizeInArchive LPCTSTR  lpszFilePath,
bool  bFullPath
const
 

Calls CZipArchive::PredictMaximumFileSizeInArchive(CZipFileHeader&).

Before calling, fills the CZipFileHeader structure with the filename as it will appear in the archive and set the proper file size (unless lpszFilePath is a directory).

Parameters:
lpszFilePath a file you want to predict the maximum size
bFullPath the same meaning as in PredictFileNameInZip
Returns:
the maximum number of bytes the file would occupy in the archive
See also:
PredictMaximumFileSizeInArchive(CZipFileHeader&) const

DWORD CZipArchive::PredictMaximumFileSizeInArchive CZipFileHeader fh  )  const
 

Calculate the maximum number of bytes that the file represented by CZipFileHeader would occupy in the current archive.

You need to set the following in the structure:

Additionally you may set:

Parameters:
fh a pre-filled structure
Returns:
the maximum number of bytes the file would occupy in the archive
Note:
  • The method calculates the number of bytes as if the file would be stored (no compression)
  • The method takes into account if the current archive is a disk-spanning archive
  • If the archive has a password set, the method will assume that the file would be stored encrypted in the archive
  • The method does not take into account a situation when a file would be compressed, but mostly stored blocks would be emitted by the Huffman compression engine; in this case extra 5 bytes are added per single stored block; you should remove the file and store it instead in this case(see zipsmCheckForEff)
See also:
PredictMaximumFileSizeInArchive(LPCTSTR, bool) const

static void CZipArchive::ReadBytes void *  pDestination,
const char *  pSource,
int  iCount
[inline, static]
 

Read iCount bytes from pSource into pDestination.

Parameters:
pDestination byte-order depends on the machine
pSource always little-endian ordered
iCount bytes to read

Definition at line 319 of file ZipArchive.h.

References ZipCompatibility::IsBigEndian(), ZipCompatibility::ReadBytesBigEndian(), and ZipCompatibility::ReadBytesLittleEndian().

DWORD CZipArchive::ReadFile void *  pBuf,
DWORD  iSize
 

Decompress currently opened file to the buffer.

Parameters:
pBuf buffer to receive data
iSize the size of the buffer
Returns:
the number of bytes read
See also:
OpenFile
Note:
Throws exceptions.

bool CZipArchive::RemoveLast bool  bRemoveAnyway = false  )  [protected]
 

Remove recently added file (used by AddNewFile) if compressed is larger than uncompressed or if callback method return false.

Parameters:
bRemoveAnyway if true, do not check for the efficiency, but remove the file

static bool CZipArchive::RemovePathBeginning LPCTSTR  lpszBeginning,
CZipString &  szPath,
ZIPSTRINGCOMPARE  pCompareFunction
[static]
 

Remove lpszBeginning from the beginning of the szPath.

Both argument are considered to be paths so they matches up to the path separator.

Parameters:
lpszBeginning 
szPath 
pCompareFunction (see: m_pZipCompare)
Returns:
true if the path beginning was removed

bool CZipArchive::RenameFile WORD  uIndex,
LPCTSTR  lpszNewName
 

Change the name of the file with the given index.

Parameters:
uIndex zero-based index of the file
lpszNewName new name for the file
Returns:
Note:
Throws exceptions.
See also:
SetAdvanced

void CZipArchive::SetAdvanced int  iWriteBuffer = 65536,
int  iGeneralBuffer = 65536,
int  iSearchBuffer = 32768
 

Set the buffer sizes.

No buffer can be set smaller than 1024. Use this method before opening the archive. The optimal size for the write buffer in the disk spanning archive is the size of the volume.

Parameters:
iWriteBuffer the write cache size used
See also:
CZipStorage::m_iWriteBufferSize
Parameters:
iGeneralBuffer buffer used in extracting, compressing, deleting, getting (GetFromArchive) files, renaming and replacing
See also:
CZipInternalInfo::m_iBufferSize
Parameters:
iSearchBuffer the buffer used in searching for the central dir
See also:
CZipCentralDir::m_iBufferSize

GetAdvanced

void CZipArchive::SetAutoFlush bool  bAutoFlush = true  ) 
 

Set the CZipArchive object to call Flush after each operation that modifies the archive (adding a new file, deleting file(s), modifying the global or a file comment).

It is useful when we want to prevent the loss of data in case of the program crash - the zip file will be then finalized on the disk. Use it after opening the archive.

Note:
  • You can set AutoFlush only for non-disk spanning archives, however you can call Flush once for a disk-spanning archive in creation.
  • If you have an archive with a huge central directory, setting Auto-Flush will influence the performance.
See also:
Flush

GetAutoFlush

void CZipArchive::SetCallback CZipActionCallback pCallback = NULL,
int  iWhich = cbAll
 

Set callback objects for the following operations on the zip archive: adding, extracting, testing or deleting files.

See Action progress notifications (callbacks) information on how to use callback objects.

Parameters:
pCallback the address of the callback object which class is derived from CZipActionCallback (you need to override member function CZipCallback::Callback in the derived class) Set it to NULL to clear callback for the selected actions.
iWhich can be one or more (use logical OR) CallbackType values.
See also:
CZipActionCallback

GetCallback

void CZipArchive::SetCaseSensitivity bool  bCaseSensitive  )  [inline]
 

Set the default archive case-sensitivity.

Affects the following functions:

Parameters:
bCaseSensitive the default CZipArchive case-sensitivity depends on the system and is set as follows:
  • on Windows: false
  • on Linux: true
Note:
Set it before using one of the functions above or leave it as it is by default;

Definition at line 1658 of file ZipArchive.h.

void CZipArchive::SetConvertAfterOpen bool  bConvertAfterOpen  )  [inline]
 

Set CZipCentralDir::m_bConvertAfterOpen value.

The default value is true. Setting this value to false is generally not effective and is intended only for quick and short operations on archives with lots of files inside (e.g. open archive, make an operation on a file which index you already know and close the archive - using FindFile function already makes setting this value to false inefficient)

Parameters:
bConvertAfterOpen 
Note:
Use before opening the archive.
See also:
CZipCentralDir::m_bConvertAfterOpen

Definition at line 1410 of file ZipArchive.h.

void CZipArchive::SetDetectZlibMemoryLeaks bool  bDetect  )  [inline]
 

Set m_bDetectZlibMemoryLeaks value.

Parameters:
bDetect 
Note:
Use before opening a file in the archive.
See also:
m_bDetectZlibMemoryLeaks

Definition at line 1386 of file ZipArchive.h.

void CZipArchive::SetExtraField const char *  pBuf,
WORD  iSize
 

Set the extra field in the central directory of the currently opened file.

Must be used after opening a new file in the archive, but before closing it To set the local extra field, set it in the CZipFileHeader structure passed as the argument to the OpenNewFile

Parameters:
pBuf the bufer with the data to be copied
iSize the size of the extra field in the buffer
See also:
OpenNewFile

bool CZipArchive::SetFileComment WORD  uIndex,
LPCTSTR  lpszComment
 

Set the comment of the file with the given index inside the archive.

Parameters:
uIndex zero-based index of the file in the archive
lpszComment a comment to add
Returns:
false if the comment change is impossible
Note:
Throws exceptions.

void CZipArchive::SetFileHeaderAttr CZipFileHeader header,
DWORD  uAttr
const
 

Set the attributes for CZipFileHeader structure to be used in OpenNewFile method as an argument.

This special procedure is taken, because the system compatibility must be set for CZipFileHeader prior to the value, which must be identical to the return value of GetSystemCompatibility method.

Parameters:
header the structure to have attributes set
uAttr attributes to set
Note:
Throws exceptions if the archive system or the current system is not supported by the ZipArchive library.
See also:
GetSystemCompatibility

bool CZipArchive::SetGlobalComment LPCTSTR  lpszComment  ) 
 

Set the global comment in the archive.

Parameters:
lpszComment the file comment
Returns:
false if the archive is closed or if it is an existing disk spanning archive
Note:
Throws exceptions.

void CZipArchive::SetIgnoreCRC bool  bIgnore = true  )  [inline]
 

If you set bIgnore to true, CRC is not checked for the files being tested or extracted.

This method is useful when working with Java TM Archives (jar). The CRC is checked by default. You can use this function on an opened or closed archive.

Definition at line 1695 of file ZipArchive.h.

bool CZipArchive::SetPassword LPCTSTR  lpszPassword = NULL  ) 
 

Set the password for the file to be opened or created.

Use this method BEFORE opening or adding a file, but AFTER opening an archive

Parameters:
lpszPassword set it to NULL to clear password
Returns:
false if the password contains ASCII characters with values 128 or higher or the file inside archive is opened

Referenced by CZipArchive::CZipSmClrPass::ClearPasswordSmartly().

void CZipArchive::SetRootPath LPCTSTR  szPath = NULL  ) 
 

Set m_szRootPath to a specified value.

Use it if you don't want to set bFullPath argument in AddNewFile or ExtractFile to true and you don't want to strip the whole path neither, but only a specific beginning. Use it AFTER opening the archive and before using AddNewFile or ExtractFile. See the FAQ for the example of use.

Parameters:
szPath Set it to the string that you want to be omitted from the beginning of the path of the file in the archive
if NULL - clears the m_szRootPath and no path beginning will be matched against it
Note:
Set the case-sensitivity with SetCaseSensitivity
See also:
AddNewFile

ExtractFile

GetRootPath

void CZipArchive::SetSpanCallback CZipSpanCallback pCallback = NULL  )  [inline]
 

Set the callback object used during operations on a PKZIP compatible disk spanning archive to change disks.

Set it before opening the archive. If you open the archive in the PKZIP compatible mode and don't set the callback object, the exception CZipException::noCallback will be thrown.

Callback object's method CZipSpanCallback::Callback is called when there is a need for a disk change. Calling CZipArchive methods from inside this method may result in an unexpected behavior.

Parameters:
pCallback the address of the callback object which class is derived from CZipSpanCallback (you need to override member function CZipCallback::Callback in the derived class) Set it to NULL to clear the callback.
See also:
CZipSpanCallback

Definition at line 489 of file ZipArchive.h.

bool CZipArchive::SetSystemCompatibility int  iSystemComp  ) 
 

Set the system compatibility of the archive.

By default it is set to the current system value (the one returned by ZipPlatform::GetSystemID() function). Use it after opening the archive, but before adding a new file or using SetFileHeaderAttr() function

Parameters:
iSystemComp can be one of ZipCompatibility::ZipPlatforms values
Returns:
return false if the value iSystemComp is not supported (ZipCompatibility::IsPlatformSupported returns false for the value) or it is not possible to set it right now

void CZipArchive::SetTempPath LPCTSTR  lpszPath = NULL,
bool  bForce = true
 

Set a temporary path used when compressing files and zipsmCheckForEff is specified as an argument in AddNewFile and the disk spanning archive is in creation.

Parameters:
lpszPath set it to NULL to clear the temporary path and let the library figure it out (it uses the system temporary directory if possible)
bForce if lpszPath is not NULL and this parameter set to true the directory is created if it doesn't exists (if the given directory does not exists , the temporary file will not be created)
See also:
AddNewFile

Smartness

GetTempPath

void CZipArchive::SetTreatAsSingleDisk bool  bSingleDisk = true  )  [inline]
 

If you set bSingleDisk to true, no disk change will occur while reading an existing archive.

The purpose of this method is to allow reading archives that have improperly set disk numbers.

Definition at line 1701 of file ZipArchive.h.

static int CZipArchive::SingleToWide const CZipAutoBuffer szSingle,
CZipString &  szWide
[static]
 

In non-UNICODE version just copy szSingle to szWide.

In UNICODE version works the same way as ZipPlatform::SingleToWide

Parameters:
szSingle 
szWide 
Returns:
(in non-UNICODE version the number of characters copied)
See also:
ZipPlatform::SingleToWide

bool CZipArchive::TestFile WORD  uIndex,
DWORD  uBufSize = 65536
 

Test the file with the given index for the integrity.

You can set the callback object with SetCallback. The method throws exceptions but performs all the necessary cleanup before, so that the next file can be tested after catching the exception.

Parameters:
uIndex index of the file to test
uBufSize the size of the buffer used during extraction
Returns:
false if the incorrect action has been taken by the user or the programmer (it is when OpenFile or GetFileInfo returned false or uBufSize is 0). If the file didn't passed the test or there was a disk I/O error or the password supplied was incorrect, an exception is thrown.
Note:
Throws exceptions.
See also:
SetCallback

void CZipArchive::ThrowError int  err,
bool  bZlib = false
[protected]
 

Throw a CZipException error.

Parameters:
err the error code
See also:
CZipException::ZipErrors
Parameters:
bZlib if true, treat err as a zlib error code and perform the conversion to the one of CZipException codes.
See also:
CZipException::Throw

CZipString CZipArchive::TrimRootPath CZipPathComponent zpc  )  const
 

Function used in conjunction with m_szRootPath to trim paths in AddNewFile and ExtractFile.

Parameters:
zpc 
See also:
SetRootPath

bool CZipArchive::UpdateReplaceIndex int &  iReplaceIndex,
LPCTSTR  lpszNewFileName
[protected]
 

Returns:
whether the code should continue or not

static void CZipArchive::WideConversionUseAnsi bool  bUseAnsi  )  [inline, static]
 

Call it to change how the Unicode string conversion is handled.

If bUseAnsi is set to true, ANSI (CP_ACP) code page is used, otherwise translation is performed using UTF-8. Set it to false e.g. for Japanese or Korean languages. Default is true.

Parameters:
bUseAnsi if true, CP_ACP code page is used for the conversion, otherwise CP_UTF8 is used
See also:
EnableOemConversion

Definition at line 303 of file ZipArchive.h.

static int CZipArchive::WideToSingle LPCTSTR  lpWide,
CZipAutoBuffer szSingle
[static]
 

In non-UNICODE version just copy lpWide to szSingle.

In UNICODE version works the same way as ZipPlatform::WideToSingle

Parameters:
lpWide 
szSingle 
Returns:
(in non-UNICODE version the number of characters copied)
See also:
ZipPlatform::WideToSingle

int CZipArchive::WillBeDuplicated LPCTSTR  lpszFilePath,
bool  bFullPath,
bool  bFileNameOnly = false,
int  iWhat = prAuto
 

Check if the filename will be duplicted in the archive, if added to the archive in the given form.

Parameters:
lpszFilePath the file path as it would be passed to AddNewFile function
bFullPath the same as bFullPath in AddNewFile
bFileNameOnly if true, assume that the filename is duplicated if only the filename (no path) is the same (bFullPath is ignored), otherwise the whole filename with path is taken into account. Default: false
iWhat one of Predict values to treat lpszFilePath correctly
Returns:
the zero-based index of the file in the archive that the filename would be duplicated, or -1, if the filename is unique

static void CZipArchive::WriteBytes char *  pDestination,
const void *  pSource,
int  iCount
[inline, static]
 

Write iCount bytes from pSource into pDestination.

Parameters:
pDestination always little-endian ordered
pSource byte-order depends on the machine
iCount bytes to write

Definition at line 338 of file ZipArchive.h.

References ZipCompatibility::IsBigEndian(), ZipCompatibility::WriteBytesBigEndian(), and ZipCompatibility::WriteBytesLittleEndian().

bool CZipArchive::WriteNewFile const void *  pBuf,
DWORD  iSize
 

Compress the contents of the buffer and write it to a new file.

Parameters:
pBuf the buffer containing the data to be compressed and written
iSize the number of bytes to be written from the buffer
Returns:
false if the new file hasn't been opened yet
Note:
Throws exceptions.
See also:
OpenNewFile


Member Data Documentation

bool CZipArchive::g_bWideConversionUseAnsi [static, protected]
 

See also:
WideConversionUseAnsi

Definition at line 2057 of file ZipArchive.h.

bool CZipArchive::m_bAutoFlush [protected]
 

The current AutoFlush value.

See also:
Flush

SetAutoFlush

GetAutoFlush

Definition at line 2028 of file ZipArchive.h.

bool CZipArchive::m_bCaseSensitive [protected]
 

Default archive case-sensitivity.

See also:
SetCaseSensitivity

Definition at line 1978 of file ZipArchive.h.

bool CZipArchive::m_bDetectZlibMemoryLeaks [protected]
 

Specify whether to control memory allocation and freeing by the zlib library.

Default: true

Note:
Set it before opening a file (new or existing) in the archive.
See also:
SetDetectZlibMemoryLeaks

Definition at line 2154 of file ZipArchive.h.

bool CZipArchive::m_bRemoveDriveLetter
 

If true, the drive letter is removed from the filename stored inside the archive when adding a new file to the archive.

It affects AddNewFile, ExtractFile, PredictFileNameInZip, PredictExtractedFileName, WillBeDuplicated methods.

Default: true

Definition at line 1872 of file ZipArchive.h.

CZipClbckStrg CZipArchive::m_callbacks [protected]
 

See also:
CZipClbckStrg

Definition at line 1966 of file ZipArchive.h.

CZipCentralDir CZipArchive::m_centralDir [protected]
 

A central directory object.

See also:
CZipCentralDir

Definition at line 2005 of file ZipArchive.h.

int CZipArchive::m_iArchiveSystCompatib [protected]
 

The system code of the current archive.

All new files in the archive will be created regarding this value. Can be one of the enum values defined in ZipCompatibility.h

See also:
GetSystemCompatibility

Definition at line 2077 of file ZipArchive.h.

CZipInternalInfo CZipArchive::m_info [protected]
 

Internal data.

See also:
CZipInternalInfo

Definition at line 1992 of file ZipArchive.h.

CZipStorage CZipArchive::m_storage [protected]
 

Physical layer of the archive.

See also:
CZipStorage

Definition at line 1999 of file ZipArchive.h.

CZipString CZipArchive::m_szRootPath [protected]
 

The root path to be omitted in AddNewFile and ExtractFile functions from the beginning of the full file path.

Set by SetRootPath

See also:
TrimRootPath

SetRootPath

Definition at line 2043 of file ZipArchive.h.

CZipString CZipArchive::m_szTempPath [protected]
 

A temporary path set with SetTempPath function.

See also:
SetTempPath

AddNewFile

Smartness

Definition at line 2051 of file ZipArchive.h.


The documentation for this class was generated from the following file:
ZipArchive Copyright © 2000 - 2006 Tadeusz Dracz . Generated at Fri Apr 7 13:55:24 2006.