Skip Navigation Links
Skip Navigation LinksHome > ZipArchive > How to Use > API Documentation
The ZipArchive Library

#include <ZipCentralDir.h>

Classes

struct  CInfo
struct  CZipFindFast

Public Member Functions

CZipFileHeaderAddNewFile (const CZipFileHeader &header, ZIP_INDEX_TYPE uReplaceIndex, int iLevel, bool bRichHeaderTemplateCopy=false)
void Close ()
void CloseFile (bool skipCheckingDataDescriptor=false)
void CloseNewFile ()
void EnableFindFast (bool bEnable, bool bCaseSensitive)
ZIP_INDEX_TYPE FindFile (LPCTSTR lpszFileName, bool bCaseSensitive, bool bSporadically, bool bFileNameOnly)
ZIP_INDEX_TYPE FindFileNameIndex (LPCTSTR lpszFileName) const
CZipArchiveGetArchive ()
void GetComment (CZipString &szComment) const
ZIP_ARRAY_SIZE_TYPE GetCount () const
ZIP_INDEX_TYPE GetFindFastIndex (ZIP_INDEX_TYPE uFindFastIndex) const
void GetInfo (CInfo &info) const
ZIP_INDEX_TYPE GetLastIndexAdded () const
ZIP_SIZE_TYPE GetSize (bool bWhole=false) const
CZipStorageGetStorage ()
const CZipStringStoreSettingsGetStringStoreSettings () const
time_t GetTimeZoneOffset ()
int GetUnicodeMode () const
void Init (CZipCentralDir *pSource=NULL)
void InitOnCreate (CZipArchive *pArchive)
bool IsAnyFileModified () const
bool IsConsistencyCheckOn (int iLevel)
bool IsFindFastEnabled ()
bool IsValidIndex (ZIP_INDEX_TYPE uIndex) const
ZIP_FILE_USIZE LocateSignature ()
bool OnFileCentralChange ()
bool OnFileNameChange (CZipFileHeader *pHeader, bool bInCentralOnly)
void OpenFile (ZIP_INDEX_TYPE uIndex)
CZipFileHeaderoperator[] (ZIP_INDEX_TYPE uIndex)
const CZipFileHeaderoperator[] (ZIP_INDEX_TYPE uIndex) const
void Read ()
void RebuildFindFastArray ()
void RemoveAll ()
void RemoveFile (CZipFileHeader *pHeader, ZIP_INDEX_TYPE uIndex=ZIP_FILE_INDEX_UNSPECIFIED, bool bShift=true)
void RemoveFromDisk ()
void RemoveLastFile (CZipFileHeader *pHeader=NULL, ZIP_INDEX_TYPE uIndex=ZIP_FILE_INDEX_UNSPECIFIED)
void SetComment (LPCTSTR lpszComment, UINT codePage)
void SetUnicodeMode (int iMode)
void ThrowError (int err) const
void Write ()

Public Attributes

int m_iIgnoredChecks
CZipFileHeaderm_pOpenedFile
 It points to the currently opened file or it is NULL, if no file is opened.
ZipArchiveLib::CBitFlag m_specialFlags

Static Public Attributes

static char m_gszSignature []
 The End of Central Directory Record signature.
static char m_gszSignature64 []
 The Zip64 End of Central Directory Record signature.
static char m_gszSignature64Locator []
 The Zip64 End of Central Directory Locator signature.

Protected Member Functions

void BuildFindFastArray (bool bCaseSensitive)
void ClearFindFastArray ()
int CompareElement (LPCTSTR lpszFileName, ZIP_INDEX_TYPE uIndex) const
void CreateSharedData ()
void DestroySharedData ()
ZIP_INDEX_TYPE InsertFindFastElement (CZipFileHeader *pHeader, ZIP_INDEX_TYPE uIndex)
void LockAccess ()
void ReadHeaders ()
void ReadZip64Info ()
bool RemoveDataDescr (bool bFromBuffer)
ZIP_INDEX_TYPE RemoveFindFastElement (CZipFileHeader *pHeader, bool bShift)
void RemoveHeaders ()
void UnlockAccess ()
void WriteCentralEnd ()
void WriteCentralEnd64 ()
void WriteHeaders (bool bOneDisk)

Static Protected Member Functions

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

Protected Attributes

int m_iUnicodeMode
CZipArchivem_pArchive
CZipArray< CZipFindFast * > * m_pFindArray
CZipArray< CZipFileHeader * > * m_pHeaders
CInfom_pInfo
CZipStoragem_pStorage

Detailed Description

Represents the central directory record in an archive.

Member Function Documentation

◆ AddNewFile()

CZipFileHeader * CZipCentralDir::AddNewFile ( const CZipFileHeader & header,
ZIP_INDEX_TYPE uReplaceIndex,
int iLevel,
bool bRichHeaderTemplateCopy = false )

Adds a new file to the central directory.

Parameters
headerUsed as a template for the data stored inside the archive.
uReplaceIndexThe index of the file to be replaced or ZIP_FILE_INDEX_UNSPECIFIED, if the index is unknown.
iLevelThe compression level. Use direct numeric values here, not CZipCompressor::CompressionLevel values.
bRichHeaderTemplateCopytrue, if copy crc and sizes values from header; false otherwise.
Returns
The new header.

◆ BuildFindFastArray()

void CZipCentralDir::BuildFindFastArray ( bool bCaseSensitive)
protected

Builds the CZipCentralDir::m_pFindArray array.

◆ ClearFindFastArray()

void CZipCentralDir::ClearFindFastArray ( )
inlineprotected

Clears the Find Fast array and frees memory.

◆ Close()

void CZipCentralDir::Close ( )

Closes the central directory.

◆ CloseFile()

void CZipCentralDir::CloseFile ( bool skipCheckingDataDescriptor = false)

Closes a file opened for reading inside the archive.

Parameters
skipCheckingDataDescriptorIf true, the data descriptor that is located after the compressed data in the archive is checked for validity. Set this value to false after closing the file after an exception was thrown.

◆ CloseNewFile()

void CZipCentralDir::CloseNewFile ( )

Closes a file opened for reading inside the archive.

◆ CompareElement()

int CZipCentralDir::CompareElement ( LPCTSTR lpszFileName,
ZIP_INDEX_TYPE uIndex ) const
inlineprotected

The method used in comparison involving the Find Fast feature.

Parameters
lpszFileNameThe name of the file.
uIndexThe index from the CZipCentralDir::m_pFindArray array.
Returns
The return value has the following meaning:
  • 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

◆ CompareFindFastCollate()

int CZipCentralDir::CompareFindFastCollate ( const void * pArg1,
const void * pArg2 )
inlinestaticprotected

Comparison function for sorting Find Fast array (case-sensitive).

Parameters
pArg1First element to compare.
pArg2Second element to compare.
Returns
Comparison result.

◆ CompareFindFastCollateNoCase()

int CZipCentralDir::CompareFindFastCollateNoCase ( const void * pArg1,
const void * pArg2 )
inlinestaticprotected

Comparison function for sorting Find Fast array (case-insensitive).

Parameters
pArg1First element to compare.
pArg2Second element to compare.
Returns
Comparison result.

◆ CompareHeaders()

int CZipCentralDir::CompareHeaders ( const void * pArg1,
const void * pArg2 )
inlinestaticprotected

The method used in comparison when sorting headers.

◆ CreateSharedData()

void CZipCentralDir::CreateSharedData ( )
protected

Creates data that can be shared between different archive objects.

See also
DestroySharedData

◆ DestroySharedData()

void CZipCentralDir::DestroySharedData ( )
protected

Destroys data shared between different archive objects, if the usage reference count of the data is zero.

See also
CreateSharedData

◆ EnableFindFast()

void CZipCentralDir::EnableFindFast ( bool bEnable,
bool bCaseSensitive )

Enables Find Fast.

See also
CZipArchive::EnableFindFast

◆ FindFile()

ZIP_INDEX_TYPE CZipCentralDir::FindFile ( LPCTSTR lpszFileName,
bool bCaseSensitive,
bool bSporadically,
bool bFileNameOnly )

Searches for the file.

See also
CZipArchive::FindFile

◆ FindFileNameIndex()

ZIP_INDEX_TYPE CZipCentralDir::FindFileNameIndex ( LPCTSTR lpszFileName) const

Finds the index of the file with the given name.

Parameters
lpszFileNameThe name of the file to find.
Returns
The index in CZipCentralDir::m_pFindArray with the corresponding CZipFindFast structure or ZIP_FILE_INDEX_NOT_FOUND, if there is no such file with the given name.
See also
CZipArchive::FindFile

◆ GetArchive()

CZipArchive * CZipCentralDir::GetArchive ( )
inline

Gets the associated CZipArchive object.

Returns
Pointer to the CZipArchive object.

◆ GetComment()

void CZipCentralDir::GetComment ( CZipString & szComment) const

Returns the global comment.

See also
CZipArchive::GetGlobalComment

◆ GetCount()

ZIP_ARRAY_SIZE_TYPE CZipCentralDir::GetCount ( ) const
inline

Returns the number of files in the archive.

Returns
The number of files in the archive.

◆ GetFindFastIndex()

ZIP_INDEX_TYPE CZipCentralDir::GetFindFastIndex ( ZIP_INDEX_TYPE uFindFastIndex) const
inline

Returns the Find Fast index.

See also
CZipArchive::GetFindFastIndex

◆ GetInfo()

void CZipCentralDir::GetInfo ( CInfo & info) const
inline

Returns the information about the central directory.

See also
CZipArchive::GetCentralDirInfo

◆ GetLastIndexAdded()

ZIP_INDEX_TYPE CZipCentralDir::GetLastIndexAdded ( ) const
inline

Returns the index of the recently added file (if any).

Returns
The index of the recently added file or ZIP_FILE_INDEX_UNSPECIFIED if the index is unknown.

◆ GetSize()

ZIP_SIZE_TYPE CZipCentralDir::GetSize ( bool bWhole = false) const

Returns the central directory size.

Parameters
bWholeIf true, include the size of the file headers. If false, the size of the file headers is not included.
Returns
The size of the central directory.
See also
CZipArchive::GetCentralDirSize

◆ GetStorage()

CZipStorage * CZipCentralDir::GetStorage ( )
inline

Returns the current storage.

Returns
The current storage.

◆ GetStringStoreSettings()

const CZipStringStoreSettings & CZipCentralDir::GetStringStoreSettings ( ) const

Returns the current string store settings.

See also
CZipArchive::GetStringStoreSettings

◆ GetTimeZoneOffset()

time_t CZipCentralDir::GetTimeZoneOffset ( )

Returns the time zone offset used when reading/writing file times. The value is cached for the duration of the archive being opened.

◆ GetUnicodeMode()

int CZipCentralDir::GetUnicodeMode ( ) const
inline

Returns the current Unicode mode.

See also
CZipArchive::GetUnicodeMode

◆ Init()

void CZipCentralDir::Init ( CZipCentralDir * pSource = NULL)

Initializes the object.

Parameters
pSourceIf not NULL, it specifies the central directory for sharing.

◆ InitOnCreate()

void CZipCentralDir::InitOnCreate ( CZipArchive * pArchive)

Initializes the central directory during construction.

Parameters
pArchiveThe archive that creates the object.

◆ InsertFindFastElement()

ZIP_INDEX_TYPE CZipCentralDir::InsertFindFastElement ( CZipFileHeader * pHeader,
ZIP_INDEX_TYPE uIndex )
protected

Inserts a new CZipFindFast element to the CZipCentralDir::m_pFindArray array. Initializes the CZipFindFast object with pHeader and uIndex values.

Parameters
pHeaderThe element to insert.
uIndexThe original index of pHeader in the central directory. If set to ZIP_FILE_INDEX_UNSPECIFIED, it is assumed to be the last element.
Returns
The index in the CZipCentralDir::m_pFindArray array.

◆ IsAnyFileModified()

bool CZipCentralDir::IsAnyFileModified ( ) const

Examines whether any file is modified.

Returns
true, if there are modified files; false otherwise.
See also
CZipArchive::IsModified

◆ IsConsistencyCheckOn()

bool CZipCentralDir::IsConsistencyCheckOn ( int iLevel)
inline

Returns the value indicating whether the specified consistency check should be performed.

Parameters
iLevelThe level to check. It can be one or more of the CZipArchive::ConsistencyCheck values.
Returns
true, if the specified check should be performed; false otherwise.
See also
m_iIgnoredChecks

◆ IsFindFastEnabled()

bool CZipCentralDir::IsFindFastEnabled ( )
inline

Returns the value indicating whether the Find Fast feature is enabled.

Returns
The value of CInfo::m_bFindFastEnabled.

◆ IsValidIndex()

bool CZipCentralDir::IsValidIndex ( ZIP_INDEX_TYPE uIndex) const

Tests if the given file index is valid.

Parameters
uIndexA zero-based index to test.
Returns
true, if the file with the given index exists inside the archive; false otherwise.

◆ LocateSignature()

ZIP_FILE_USIZE CZipCentralDir::LocateSignature ( )

Locates the central directory signature in the archive.

Returns
The position of the signature.

◆ LockAccess()

void CZipCentralDir::LockAccess ( )
inlineprotected

Locks the access to the shared data.

See also
UnlockAccess
CreateSharedData

◆ OnFileCentralChange()

bool CZipCentralDir::OnFileCentralChange ( )

Called when data of a file changes in a central directory file header.

Returns
true, if the change is permitted; false otherwise.

◆ OnFileNameChange()

bool CZipCentralDir::OnFileNameChange ( CZipFileHeader * pHeader,
bool bInCentralOnly )

Called when a filename of a file in the archive changes.

Returns
true, if the change is permitted; false otherwise.

◆ OpenFile()

void CZipCentralDir::OpenFile ( ZIP_INDEX_TYPE uIndex)

Opens the file with the given index.

Parameters
uIndexA zero-based index of the file to open.

◆ operator[]() [1/2]

CZipFileHeader * CZipCentralDir::operator[] ( ZIP_INDEX_TYPE uIndex)
inline

Returns the information about the file with the given index.

See also
CZipArchive::operator[](ZIP_INDEX_TYPE)

◆ operator[]() [2/2]

const CZipFileHeader * CZipCentralDir::operator[] ( ZIP_INDEX_TYPE uIndex) const
inline

Returns the information about the file with the given index.

See also
CZipArchive::operator[](ZIP_INDEX_TYPE) const

◆ Read()

void CZipCentralDir::Read ( )

Reads the central directory from the archive.

◆ ReadHeaders()

void CZipCentralDir::ReadHeaders ( )
protected

Reads file headers from the archive.

◆ ReadZip64Info()

void CZipCentralDir::ReadZip64Info ( )
protected

Reads the Zip64 central directory information.

◆ RebuildFindFastArray()

void CZipCentralDir::RebuildFindFastArray ( )
inline

Rebuilds the CZipCentralDir::m_pFindArray array.

◆ RemoveAll()

void CZipCentralDir::RemoveAll ( )

Removes all files.

◆ RemoveDataDescr()

bool CZipCentralDir::RemoveDataDescr ( bool bFromBuffer)
protected

Removes data descriptors from a segmented archive that turned out to be single-segment only. It is not called for encrypted files.

Parameters
bFromBufferIf true, removes the descriptors from the write buffer in memory otherwise from the file on the disk.
Returns
false, if the file mapping to memory was not successful (can happen only when bFromBuffer is false); true otherwise.

◆ RemoveFile()

void CZipCentralDir::RemoveFile ( CZipFileHeader * pHeader,
ZIP_INDEX_TYPE uIndex = ZIP_FILE_INDEX_UNSPECIFIED,
bool bShift = true )

Removes a file header from the central directory.

Parameters
pHeaderThe header to remove.
uIndexThe index of the header to remove. Use ZIP_FILE_INDEX_UNSPECIFIED, if the index is unknown.
bShiftIf true, the data inside the archive is moved over the hole created after removing the file. If false, the unused area inside the archive remains.

◆ RemoveFindFastElement()

ZIP_INDEX_TYPE CZipCentralDir::RemoveFindFastElement ( CZipFileHeader * pHeader,
bool bShift )
protected

Removes a CZipFindFast element from the CZipCentralDir::m_pFindArray array.

Parameters
pHeaderThe element associated with this object will be removed.
bShiftIf true, the affected indexes will be shifted; false otherwise.

◆ RemoveFromDisk()

void CZipCentralDir::RemoveFromDisk ( )

Removes physically the central directory from the archive.

◆ RemoveHeaders()

void CZipCentralDir::RemoveHeaders ( )
protected

Frees the memory allocated for the CZipFileHeader structures.

◆ RemoveLastFile()

void CZipCentralDir::RemoveLastFile ( CZipFileHeader * pHeader = NULL,
ZIP_INDEX_TYPE uIndex = ZIP_FILE_INDEX_UNSPECIFIED )
Removes last file from the central directory.       
Parameters
pHeaderThe header to remove.
uIndexThe index of the header to remove. Use ZIP_FILE_INDEX_UNSPECIFIED, if the index is unknown.

◆ SetComment()

void CZipCentralDir::SetComment ( LPCTSTR lpszComment,
UINT codePage )

Sets the global comment.

See also
CZipArchive::SetGlobalComment

◆ SetUnicodeMode()

void CZipCentralDir::SetUnicodeMode ( int iMode)
inline

Sets the current Unicode mode.

See also
CZipArchive::SetUnicodeMode

◆ ThrowError()

void CZipCentralDir::ThrowError ( int err) const

Throws an exception with the given code.

◆ UnlockAccess()

void CZipCentralDir::UnlockAccess ( )
inlineprotected

Unlocks the access to the shared data.

See also
LockAccess
CreateSharedData

◆ Write()

void CZipCentralDir::Write ( )

Writes the central directory to the archive.

◆ WriteCentralEnd()

void CZipCentralDir::WriteCentralEnd ( )
protected

Writes the End of Central Directory Record.

◆ WriteCentralEnd64()

void CZipCentralDir::WriteCentralEnd64 ( )
protected

Writes the Zip64 End of Central Directory Record.

◆ WriteHeaders()

void CZipCentralDir::WriteHeaders ( bool bOneDisk)
protected

Writes the file headers to the archive.

Member Data Documentation

◆ m_gszSignature

char CZipCentralDir::m_gszSignature[]
static

The End of Central Directory Record signature.

◆ m_gszSignature64

char CZipCentralDir::m_gszSignature64[]
static

The Zip64 End of Central Directory Record signature.

◆ m_gszSignature64Locator

char CZipCentralDir::m_gszSignature64Locator[]
static

The Zip64 End of Central Directory Locator signature.

◆ m_iIgnoredChecks

int CZipCentralDir::m_iIgnoredChecks

Consistency checks to ignore. It can be one or more of the CZipArchive::ConsistencyCheck values.

See also
CZipArchive::SetIgnoredConsistencyChecks

◆ m_iUnicodeMode

int CZipCentralDir::m_iUnicodeMode
protected

The current Unicode mode.

◆ m_pArchive

CZipArchive* CZipCentralDir::m_pArchive
protected

The reference to the main CZipArchive object.

◆ m_pFindArray

CZipArray<CZipFindFast*>* CZipCentralDir::m_pFindArray
protected

The Find Fast array.

See also
CZipFindFast
CInfo::m_bFindFastEnabled
CZipArchive::FindFile

◆ m_pHeaders

CZipArray<CZipFileHeader*>* CZipCentralDir::m_pHeaders
protected

Holds the information about all files inside the archive.

See also
CZipFileHeader

◆ m_pInfo

CInfo* CZipCentralDir::m_pInfo
protected

The central directory information.

See also
CInfo

◆ m_pOpenedFile

CZipFileHeader* CZipCentralDir::m_pOpenedFile

It points to the currently opened file or it is NULL, if no file is opened.

◆ m_pStorage

CZipStorage* CZipCentralDir::m_pStorage
protected

◆ m_specialFlags

ZipArchiveLib::CBitFlag CZipCentralDir::m_specialFlags

The currently set special flags.

See also
CZipArchive::SetSpecialFlags

The documentation for this class was generated from the following file:
Back To Top Up