CZipCentralDir Class Reference

A class representing the central directory record in the archive. More...

#include <ZipCentralDir.h>

List of all members.

Public Member Functions

void Init ()
 Called by CZipArchive::OpenInternal.
void Read ()
 Read the central directory from the archive.
void OpenFile (WORD uIndex)
 Open the file.
CZipFileHeaderUpdateLocal (WORD uIndex)
 Update local header info.
bool IsValidIndex (int uIndex) const
 Test if the given file header index is valid.
void RemoveFile (CZipFileHeader *pHeader, int iIndex=-1, bool bShift=true)
 Remove the file header from the central directory.
void RemoveLastFile (CZipFileHeader *pHeader=NULL, int iIndex=-1)
 Remove last file from the central directory.
void RemoveAll ()
 Remove all files.
void Clear (bool bEverything=true)
 Cleanup the structure.
CZipFileHeaderAddNewFile (const CZipFileHeader &header, int iReplaceIndex=-1)
 Add a new file to the central directory.
CZipString GetProperHeaderFileName (const CZipFileHeader *pHeader) const
 return the header filename, converted if needed
void RemoveFromDisk ()
 Remove physically the central directory from the archive.
DWORD GetSize (bool bWhole=false) const
 Get the central directory size.
void CloseFile (bool bAfterException=false)
 Close a file inside archive opened for reading.
void CloseNewFile ()
 Close a file inside archive opened for reading.
void Write (CZipActionCallback *pCallback)
 Write the central directory to the archive.
void EnableFindFast (bool bEnable, bool bCaseSensitive)
int FindFile (LPCTSTR lpszFileName, bool bCaseSensitive, bool bSporadically, bool bFileNameOnly)
int GetFindFastIndex (int iFindFastIndex) const
CZipFileHeaderoperator[] (int iIndex)
const CZipFileHeaderoperator[] (int iIndex) const
void ConvertFileName (bool bFromZip, bool bAfterOpen, CZipFileHeader *pHeader=NULL) const
 Convert the filename of the CZipFileHeader depending on the current system and the system the zip file was created on (change slash to backslash or vice versa, perform ANSI-OEM conversion if necessary).
void ConvertAll ()
 Convert all the filenames to the system form.
int FindFileNameIndex (LPCTSTR lpszFileName) const
DWORD GetBytesBefore () const
void GetInfo (Info &info) const
 Get the information about the central directory.
bool IsFindFastEnabled ()
void RenameFile (WORD uIndex, LPCTSTR lpszNewName)
 Called by CZipArchive::RenameFile.

Public Attributes

char m_szSignature [4]
 end of central dir signature (must be 0x06054b50)
CZipAutoBuffer m_pszComment
 the archive comment
CZipAutoBuffer m_pLocalExtraField
 a local extra field
CZipFileHeaderm_pOpenedFile
 points to a currently opened file or NULL if no file is opened
CZipStoragem_pStorage
 Points to CZipArchive::m_storage.
int m_iBufferSize
 The size of the buffer used in searching for the central dir.
CZipArray< CZipFileHeader * > m_headers
 Holds all the files inside archive info.
bool m_bConvertAfterOpen
 
  • If true, the conversion of the filenames takes place after opening the archive (after reading the central directory from the file), and before writing the central directory back to the archive.

bool m_bOemConversion
 If true, the OEM conversion is performed under Windows platform on the filenames of the files inside an archive (there is the Ansi-to-Oem conversion performed when storing the filename in the archive, and Oem-to-Ansi when reading the filename from the archive).

Static Public Attributes

static char m_gszSignature []
 central dir signature

Protected Member Functions

void SortHeaders ()
 Sort the files inside the archive headers by the order in the archive.
void BuildFindFastArray (bool bCaseSensitive)
 Build m_findarray.
int CompareElement (LPCTSTR lpszFileName, WORD uIndex) const
 The lpszFileName and bCaseSensitive arguments are the same as in the FindFileNameIndex.
void InsertFindFastElement (CZipFileHeader *pHeader, WORD uIndex)
 Insert a new CZipFindFast element to the m_findarray.
DWORD Locate ()
void ReadHeaders ()
 Read the file headers from the file.
void RemoveHeaders ()
 Free the memory allocated for the CZipFileHeader structures.
bool RemoveDataDescr (bool bFromBuffer)
 Remove data descriptors from the write buffer in the disk spanning volume that turned out to be one-disk only.
void WriteHeaders (CZipActionCallback *pCallback, bool bOneDisk)
 Write the file headers to the archive.
DWORD WriteCentralEnd ()
 Write the central directory end record.
void ThrowError (int err) const
 Throw an exception with the given code.

Static Protected Member Functions

static int CompareHeaders (const void *pArg1, const void *pArg2)

Protected Attributes

CZipArray< CZipFindFastm_findarray
 Used in fast finding files by the filename.
bool m_bFindFastEnabled
 If true, the there is an additional array build, to speed up the finding process CZipArchive::FindFile uses this array to perform a binary search.
ZIPSTRINGCOMPARE m_pCompare
 A compare function (Collate or CollateNoCase) set once so as not to check every time which one to use
ZIPSTRINGCOMPARE is defined in CZipString.h as:
typedef int (CZipString::*ZIPSTRINGCOMPARE)( LPCTSTR ) const; .
bool m_bCaseSensitive
 The way the m_findarray is sorted.
Info m_info

Classes

struct  CZipFindFast
 Used in fast finding files by the filename. More...
struct  Info
 Stores general information about the central directory record. More...


Detailed Description

A class representing the central directory record in the archive.

Definition at line 45 of file ZipCentralDir.h.


Member Function Documentation

CZipFileHeader* CZipCentralDir::AddNewFile const CZipFileHeader header,
int  iReplaceIndex = -1
 

Add a new file to the central directory.

Parameters:
header copy data from it to the new file header
iReplaceIndex if different from -1, the index of the file to be replaced
Returns:
the pointer to the new header
Note:
Throws exceptions.

void CZipCentralDir::Clear bool  bEverything = true  ) 
 

Cleanup the structure.

Parameters:
bEverything 
  • true - clear some attributes and remove all the file headers from memory
  • false - do not remove the file headers. It is called in that manner from CZipArchive::CloseFileWithNoUpdate so that the next file can be tested for the integrity
See also:
CZipArchive::CloseFileWithNoUpdate

void CZipCentralDir::CloseFile bool  bAfterException = false  ) 
 

Close a file inside archive opened for reading.

Parameters:
bAfterException true if closing after exception
Note:
Throws exceptions.

void CZipCentralDir::CloseNewFile  ) 
 

Close a file inside archive opened for reading.

Note:
Throws exceptions.

int CZipCentralDir::CompareElement LPCTSTR  lpszFileName,
WORD  uIndex
const [inline, protected]
 

The lpszFileName and bCaseSensitive arguments are the same as in the FindFileNameIndex.

The function get CZipFindFast structure pointed by uIndex and compares the filename of CZipFileHeader class stored in this structure with lpszFileName.

Parameters:
lpszFileName 
uIndex the index from m_findarray
Returns:
  • 0 if the filenames are the same
  • < 0 if the filename stored in the array is less than lpszFileName
  • > 0 if the filename stored in the array is greater than lpszFileName

Definition at line 493 of file ZipCentralDir.h.

References m_findarray, and m_pCompare.

void CZipCentralDir::ConvertAll  ) 
 

Convert all the filenames to the system form.

Called by CZipArchive::FindFile

See also:
CZipArchive::FindFile

void CZipCentralDir::ConvertFileName bool  bFromZip,
bool  bAfterOpen,
CZipFileHeader pHeader = NULL
const [inline]
 

Convert the filename of the CZipFileHeader depending on the current system and the system the zip file was created on (change slash to backslash or vice versa, perform ANSI-OEM conversion if necessary).

Parameters:
bFromZip if true, convert from archive format
bAfterOpen if true, called after opening the archive or before closing
pHeader the header to have filename converted; if NULL convert the currently opened file
See also:
ZipCompatibility::FileNameUpdate

m_bConvertAfterOpen

Definition at line 386 of file ZipCentralDir.h.

References ZipCompatibility::FileNameUpdate(), m_bConvertAfterOpen, m_bOemConversion, and m_pOpenedFile.

Referenced by GetProperHeaderFileName().

void CZipCentralDir::EnableFindFast bool  bEnable,
bool  bCaseSensitive
 

See also:
CZipArchive::EnableFindFast

int CZipCentralDir::FindFile LPCTSTR  lpszFileName,
bool  bCaseSensitive,
bool  bSporadically,
bool  bFileNameOnly
 

See also:
CZipArchive::FindFile
Note:
bSporadically set to false rebuilds m_findarray if necessary

int CZipCentralDir::FindFileNameIndex LPCTSTR  lpszFileName  )  const
 

Parameters:
lpszFileName the name of the file to find, must be exactly the same (apart from case) as it appears in the archive
Returns:
the index in m_findarray with the appropriate CZipFindFast structure or -1 if there is no file with the given name
See also:
CZipArchive::FindFile

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

See also:
CZipArchive::GetFindFastIndex

Definition at line 295 of file ZipCentralDir.h.

References IsValidIndex(), m_bFindFastEnabled, and m_findarray.

DWORD CZipCentralDir::GetSize bool  bWhole = false  )  const
 

Get the central directory size.

Parameters:
bWhole if true, include the size of the file headers
Returns:
the size of the central directory
See also:
CZipArchive::GetCentralDirSize

void CZipCentralDir::InsertFindFastElement CZipFileHeader pHeader,
WORD  uIndex
[protected]
 

Insert a new CZipFindFast element to the m_findarray.

Initialize CZipFindFast object with pHeader and uIndex values.

bool CZipCentralDir::IsFindFastEnabled  )  [inline]
 

Returns:
the value of m_bFindFastEnabled

Definition at line 423 of file ZipCentralDir.h.

References m_bFindFastEnabled.

bool CZipCentralDir::IsValidIndex int  uIndex  )  const
 

Test if the given file header index is valid.

Parameters:
uIndex a zero-based index
Returns:
true if the file with the given index exists inside the archive; otherwise false;

Referenced by GetFindFastIndex().

DWORD CZipCentralDir::Locate  )  [protected]
 

Returns:
the location of the beginning of the central dir end record in the archive
Note:
Throws exceptions.

void CZipCentralDir::OpenFile WORD  uIndex  ) 
 

Open the file.

Parameters:
uIndex zero-based index of the file to open
Note:
Throws exceptions.

void CZipCentralDir::Read  ) 
 

Read the central directory from the archive.

Note:
Throws exceptions.

void CZipCentralDir::ReadHeaders  )  [protected]
 

Read the file headers from the file.

Note:
Throws exceptions.

void CZipCentralDir::RemoveAll  ) 
 

Remove all files.

Note:
Throws exceptions.

bool CZipCentralDir::RemoveDataDescr bool  bFromBuffer  )  [protected]
 

Remove data descriptors from the write buffer in the disk spanning volume that turned out to be one-disk only.

We do not remove them from password encrypted files.

Parameters:
bFromBuffer if true, remove from the buffer in memory otherwise from the file on a disk
Returns:
false if the file mapping to memory was not successful Can happen only when bFormBuffer is false.
Note:
Throws exceptions.

void CZipCentralDir::RemoveFile CZipFileHeader pHeader,
int  iIndex = -1,
bool  bShift = true
 

Remove the file header from the central directory.

Parameters:
pHeader the header to remove
iIndex if index is not known set it to -1
bShift 
Note:
Throws exceptions.

Referenced by RemoveLastFile().

void CZipCentralDir::RemoveFromDisk  ) 
 

Remove physically the central directory from the archive.

Called during adding or deleting files.

Note:
Throws exceptions.

void CZipCentralDir::ThrowError int  err  )  const [protected]
 

Throw an exception with the given code.

Parameters:
err 
See also:
CZipException::Throw

CZipFileHeader* CZipCentralDir::UpdateLocal WORD  uIndex  ) 
 

Update local header info.

Parameters:
uIndex zero-based index of the file to update info
Returns:
the pointer to the header at the given index
Note:
Throws exceptions.

void CZipCentralDir::Write CZipActionCallback pCallback  ) 
 

Write the central directory to the archive.

Note:
Throws exceptions.

DWORD CZipCentralDir::WriteCentralEnd  )  [protected]
 

Write the central directory end record.

Returns:
the size of the record
Note:
Throws exceptions.

void CZipCentralDir::WriteHeaders CZipActionCallback pCallback,
bool  bOneDisk
[protected]
 

Write the file headers to the archive.

Note:
Throws exceptions.


Member Data Documentation

bool CZipCentralDir::m_bConvertAfterOpen
 

  • If true, the conversion of the filenames takes place after opening the archive (after reading the central directory from the file), and before writing the central directory back to the archive.

Change is value with CZipArchive::SetConvertAfterOpen.

Set it to true when you plan to use CZipArchive::FindFile or get the stored files information.
Set it to false when you plan mostly to modify the archive.

Default: true

Note:
Set it before opening the archive.
See also:
CZipArchive::SetConvertAfterOpen

ConvertFileName

Definition at line 357 of file ZipCentralDir.h.

Referenced by ConvertFileName(), and GetProperHeaderFileName().

bool CZipCentralDir::m_bFindFastEnabled [protected]
 

If true, the there is an additional array build, to speed up the finding process CZipArchive::FindFile uses this array to perform a binary search.

Default: false

See also:
CZipArchive::EnableFindFast

CZipArchive::FindFile

CZipCentralDir::m_findarray

Definition at line 476 of file ZipCentralDir.h.

Referenced by GetFindFastIndex(), and IsFindFastEnabled().

bool CZipCentralDir::m_bOemConversion
 

If true, the OEM conversion is performed under Windows platform on the filenames of the files inside an archive (there is the Ansi-to-Oem conversion performed when storing the filename in the archive, and Oem-to-Ansi when reading the filename from the archive).

Set it to false only if you have a good reason to do so.

See also:
CZipArchive::EnableOemConversion

Definition at line 367 of file ZipCentralDir.h.

Referenced by ConvertFileName().

CZipArray<CZipFindFast> CZipCentralDir::m_findarray [protected]
 

Used in fast finding files by the filename.

See also:
CZipFindFast

m_bFindFastEnabled

CZipArchive::FindFile

Definition at line 464 of file ZipCentralDir.h.

Referenced by CompareElement(), and GetFindFastIndex().

CZipArray<CZipFileHeader*> CZipCentralDir::m_headers
 

Holds all the files inside archive info.

See also:
CZipFileHeader

Definition at line 328 of file ZipCentralDir.h.

Referenced by operator[](), and RemoveLastFile().

int CZipCentralDir::m_iBufferSize
 

The size of the buffer used in searching for the central dir.

Set before opening the archive. It is usually set with CZipArchive::SetAdvanced (specify this value as the third argument).

See also:
CZipArchive::SetAdvanced

Definition at line 319 of file ZipCentralDir.h.

Info CZipCentralDir::m_info [protected]
 

See also:
Info

Definition at line 521 of file ZipCentralDir.h.

Referenced by GetBytesBefore(), GetInfo(), and RemoveLastFile().


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