summaryrefslogtreecommitdiff
path: root/zip/ZipArchive/ZipCentralDir.h
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2023-12-17 21:23:58 +0100
committerTomas Bzatek <tbzatek@redhat.com>2023-12-17 21:23:58 +0100
commit02d6107c97b48888362e7c6a70dcac323c89d741 (patch)
tree5069a77adaf73f7249ac79b6c49a47168a647ef8 /zip/ZipArchive/ZipCentralDir.h
parent4e17c2527b106f1b493a3ac77c89858d14f834e2 (diff)
downloadtuxcmd-modules-02d6107c97b48888362e7c6a70dcac323c89d741.tar.xz
ZipArchive: Update to the 4.6.9 release
Diffstat (limited to 'zip/ZipArchive/ZipCentralDir.h')
-rw-r--r--zip/ZipArchive/ZipCentralDir.h355
1 files changed, 196 insertions, 159 deletions
diff --git a/zip/ZipArchive/ZipCentralDir.h b/zip/ZipArchive/ZipCentralDir.h
index 043e49f..041f403 100644
--- a/zip/ZipArchive/ZipCentralDir.h
+++ b/zip/ZipArchive/ZipCentralDir.h
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////
-// This source file is part of the ZipArchive library source distribution and
-// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
+// This source file is part of the ZipArchive Library Open Source distribution
+// and is Copyrighted 2000 - 2022 by Artpol Software - Tadeusz Dracz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@@ -9,7 +9,7 @@
//
// For the licensing details refer to the License.txt file.
//
-// Web Site: http://www.artpol-software.com
+// Web Site: https://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
/**
@@ -40,8 +40,10 @@
#include "ZipMutex.h"
+class CZipArchive;
+
/**
- Represents the central directory record in the archive.
+ Represents the central directory record in an archive.
*/
class ZIP_API CZipCentralDir
{
@@ -50,6 +52,7 @@ public:
/**
Used in fast finding files by the filename.
A structure for the internal use only.
+
\see
CZipCentralDir::m_pFindArray
\see
@@ -80,12 +83,15 @@ public:
/**
Stores general information about the central directory.
- \see
- CZipArchive::GetCentralDirInfo
+ Request this information with CZipArchive::GetCentralDirInfo.
*/
struct ZIP_API CInfo
{
-
+#pragma warning(suppress: 26495)
+ CInfo()
+ {
+ Init();
+ }
/**
The position of the End of Central Directory Record.
In the Zip64 it points to the Zip64 counterpart.
@@ -93,8 +99,8 @@ public:
ZIP_SIZE_TYPE m_uEndOffset;
/**
- The zero-based number of the volume with the End of Central Directory Record. To determine the total number of segments in an archive,
- add one to this value. Request this information with CZipArchive::GetCentralDirInfo.
+ The zero-based number of the volume with the End of Central Directory Record. To determine the total number of segments in the archive,
+ add one to this value.
*/
ZIP_VOLUME_TYPE m_uLastVolume;
ZIP_VOLUME_TYPE m_uVolumeWithCD; ///< The number of the volume with the start of the central directory.
@@ -125,7 +131,7 @@ public:
void Init()
{
m_iReference = 1;
-#ifdef ZIP_ARCHIVE_USE_LOCKING
+#ifdef _ZIP_USE_LOCKING
m_mutex.Open();
#endif
m_pCompare = GetCZipStrCompFunc(ZipPlatform::GetSystemCaseSensitivity());
@@ -141,6 +147,7 @@ public:
m_uEntriesNumber = 0;
m_uSize = 0;
m_uOffset = 0;
+ m_iLastIndexAdded = ZIP_FILE_INDEX_UNSPECIFIED;
}
bool CheckIfOK_1()
{
@@ -154,22 +161,9 @@ public:
{
return (m_uSize || !m_uEntriesNumber) && (m_uEntriesNumber || !m_uSize);
}
- void DiskChange(ZIP_VOLUME_TYPE uCurrentVolume)
- {
- m_uLastVolume = uCurrentVolume;
- if (m_uEntriesNumber)
- {
- m_uVolumeEntriesNo = 0;
- }
- else
- {
- m_uVolumeWithCD = m_uLastVolume;
- m_uOffset = 0;
- }
- }
/**
- Gets a value indicating if the current archive properties requires the Zip64 format.
+ Returns a value indicating if the current archive properties requires the Zip64 format.
\return
\c true, if the Zip64 is needed; \c false otherwise.
@@ -194,13 +188,18 @@ public:
*/
bool m_bFindFastEnabled;
+ /**
+ The index of the recently added file.
+ */
+ ZIP_INDEX_TYPE m_iLastIndexAdded;
+
private:
/**
The method used in string comparisons. It is set depending on the current case-sensitivity.
*/
ZIPSTRINGCOMPARE m_pCompare;
int m_iReference;
-#ifdef ZIP_ARCHIVE_USE_LOCKING
+#ifdef _ZIP_USE_LOCKING
ZipArchiveLib::CZipMutex m_mutex;
#endif
};
@@ -213,39 +212,28 @@ public:
CZipFileHeader* m_pOpenedFile; ///< It points to the currently opened file or it is \c NULL, if no file is opened.
/**
- Initializes the object.
+ Initializes the central directory during construction.
- \param pStorage
- The current storage to use.
+ \param pArchive
+ The archive that creates the object.
- \param pCallbacks
- The current callbacks provider.
+ */
+ void InitOnCreate(CZipArchive* pArchive);
- \param pStringSettings
- The current string settings.
+ /**
+ Initializes the object.
\param pSource
- If not \c NULL, then it specifies the central directory for sharing.
+ If not \c NULL, it specifies the central directory for sharing.
- \note
- Throws exceptions.
-
+
*/
- void Init(CZipStorage* pStorage, ZipArchiveLib::CZipCallbackProvider* pCallbacks, CZipStringStoreSettings* pStringSettings, CZipCentralDir* pSource = NULL);
+ void Init(CZipCentralDir* pSource = NULL);
/**
Reads the central directory from the archive.
-
- \param bExhaustiveRead
- \c true, if the exhaustive read should be performed, \c false otherwise.
-
- \note
- Throws exceptions.
-
- \see
- CZipArchive::SetExhaustiveRead
*/
- void Read(bool bExhaustiveRead);
+ void Read();
/**
Opens the file with the given index.
@@ -253,8 +241,6 @@ public:
\param uIndex
A zero-based index of the file to open.
- \note
- Throws exceptions.
*/
void OpenFile(ZIP_INDEX_TYPE uIndex);
@@ -270,20 +256,18 @@ public:
bool IsValidIndex(ZIP_INDEX_TYPE uIndex)const;
/**
- Removes the file header from the central directory.
+ Removes a file header from the central directory.
\param pHeader
The header to remove.
\param uIndex
- The index of the header to remove. Use \c ZIP_FILE_INDEX_UNSPECIFIED, if the index is not known.
+ The index of the header to remove. Use \c ZIP_FILE_INDEX_UNSPECIFIED, if the index is unknown.
\param bShift
If \c true, the data inside the archive is moved over the hole created after removing the file.
If \c false, the unused area inside the archive remains.
- \note
- Throws exceptions.
*/
void RemoveFile(CZipFileHeader* pHeader, ZIP_INDEX_TYPE uIndex = ZIP_FILE_INDEX_UNSPECIFIED, bool bShift = true);
@@ -295,7 +279,7 @@ public:
The header to remove.
\param uIndex
- The index of the header to remove. Use \c ZIP_FILE_INDEX_UNSPECIFIED, if the index is not known.
+ The index of the header to remove. Use \c ZIP_FILE_INDEX_UNSPECIFIED, if the index is unknown.
*/
void RemoveLastFile(CZipFileHeader* pHeader = NULL, ZIP_INDEX_TYPE uIndex = ZIP_FILE_INDEX_UNSPECIFIED);
@@ -303,8 +287,6 @@ public:
/**
Removes all files.
- \note
- Throws exceptions.
*/
void RemoveAll();
@@ -320,7 +302,7 @@ public:
Used as a template for the data stored inside the archive.
\param uReplaceIndex
- The index of the file to be replaced. Use \c ZIP_FILE_INDEX_UNSPECIFIED, if the index is not known.
+ The index of the file to be replaced or \c ZIP_FILE_INDEX_UNSPECIFIED, if the index is unknown.
\param iLevel
The compression level.
@@ -331,21 +313,28 @@ public:
\return
The new header.
- \note
- Throws exceptions.
*/
CZipFileHeader* AddNewFile(const CZipFileHeader & header, ZIP_INDEX_TYPE uReplaceIndex, int iLevel, bool bRichHeaderTemplateCopy = false);
+ /**
+ Returns the index of the recently added file (if any).
+
+ \return
+ The index of the recently added file or \c ZIP_FILE_INDEX_UNSPECIFIED if the index is unknown.
+ */
+ ZIP_INDEX_TYPE GetLastIndexAdded() const
+ {
+ return m_pInfo ? m_pInfo->m_iLastIndexAdded : ZIP_FILE_INDEX_UNSPECIFIED;
+ }
+
/**
Removes physically the central directory from the archive.
- \note
- Throws exceptions.
*/
void RemoveFromDisk();
/**
- Gets the central directory size.
+ Returns the central directory size.
\param bWhole
If \c true, include the size of the file headers.
If \c false, the size of the file headers is not included.
@@ -364,24 +353,18 @@ public:
If \c true, the data descriptor that is located after the compressed data in the archive is checked for validity.
Set this value to \c false after closing the file after an exception was thrown.
- \note
- Throws exceptions.
*/
void CloseFile(bool skipCheckingDataDescriptor = false);
/**
Closes a file opened for reading inside the archive.
- \note
- Throws exceptions.
*/
void CloseNewFile();
/**
Writes the central directory to the archive.
- \note
- Throws exceptions.
*/
void Write();
@@ -403,7 +386,7 @@ public:
/**
- Gets the Find Fast index.
+ Returns the Find Fast index.
\see
CZipArchive::GetFindFastIndex
@@ -416,18 +399,9 @@ public:
return (*m_pFindArray)[(ZIP_ARRAY_SIZE_TYPE)uFindFastIndex]->m_uIndex;
}
- /**
- Points to CZipArchive::m_storage.
- */
- CZipStorage* m_pStorage;
/**
- Points to the current callback provider.
- */
- ZipArchiveLib::CZipCallbackProvider* m_pCallbacks;
-
- /**
- Gets the information about the file with the given index.
+ Returns the information about the file with the given index.
\see
CZipArchive::operator[](ZIP_INDEX_TYPE)
@@ -438,7 +412,7 @@ public:
}
/**
- Gets the information about the file with the given index.
+ Returns the information about the file with the given index.
\see
CZipArchive::operator[](ZIP_INDEX_TYPE) const
@@ -449,7 +423,7 @@ public:
}
/**
- Gets the number of files in the archive.
+ Returns the number of files in the archive.
\return
The number of files in the archive.
@@ -466,27 +440,17 @@ public:
\see
CZipArchive::SetGlobalComment
*/
- void SetComment(LPCTSTR lpszComment);
+ void SetComment(LPCTSTR lpszComment, UINT codePage);
/**
- Gets the global comment.
+ Returns the global comment.
\see
CZipArchive::GetGlobalComment
*/
- void GetComment(CZipString& szComment) const
- {
- ZipCompatibility::ConvertBufferToString(szComment, m_pInfo->m_pszComment, m_pStringSettings->m_uCommentCodePage);
- }
-
- /**
- Sets the file comment.
-
- \see
- CZipArchive::SetFileComment
- */
- bool SetFileComment(ZIP_INDEX_TYPE uIndex, LPCTSTR lpszComment);
+ void GetComment(CZipString& szComment) const;
+
/**
Finds the index of the file with the given name.
@@ -504,7 +468,7 @@ public:
ZIP_INDEX_TYPE FindFileNameIndex(LPCTSTR lpszFileName) const;
/**
- Gets the information about the central directory.
+ Returns the information about the central directory.
\see
CZipArchive::GetCentralDirInfo
@@ -512,7 +476,7 @@ public:
void GetInfo(CInfo& info) const {info = *m_pInfo;}
/**
- Gets a value indicating whether the Find Fast feature is enabled or not.
+ Returns the value indicating whether the Find Fast feature is enabled.
\return
The value of CInfo::m_bFindFastEnabled.
@@ -529,24 +493,26 @@ public:
}
/**
- The current string store settings.
+ Consistency checks to ignore. It can be one or more of the CZipArchive::ConsistencyCheck values.
- \see
- SetStringStoreSettings
- */
- CZipStringStoreSettings* m_pStringSettings;
-
- /**
- Consistency checks to ignore. Can be one or more of the CZipArchive::ConsistencyCheck values.
\see
CZipArchive::SetIgnoredConsistencyChecks
*/
int m_iIgnoredChecks;
/**
- Checks if the specified consistency check should be performed or not.
+ The currently set special flags.
+
+ \see
+ CZipArchive::SetSpecialFlags
+ */
+ ZipArchiveLib::CBitFlag m_specialFlags;
+
+ /**
+ Returns the value indicating whether the specified consistency check should be performed.
+
\param iLevel
- The level to check. Can be one or more of CZipArchive::ConsistencyCheck values.
+ The level to check. It can be one or more of the CZipArchive::ConsistencyCheck values.
\return
\c true, if the specified check should be performed; \c false otherwise.
@@ -560,42 +526,128 @@ public:
return (m_iIgnoredChecks & iLevel) == 0;
}
+ /**
+ Returns the current storage.
+
+ \return
+ The current storage.
+ */
+ CZipStorage* GetStorage() {return m_pStorage;}
+#ifdef _ZIP_UNICODE_CUSTOM
+ /**
+ Returns the current string store settings.
+
+ \see
+ CZipArchive::GetStringStoreSettings
+ */
+ const CZipStringStoreSettings& GetStringStoreSettings() const;
+#endif
+ /**
+ Called when a filename of a file in the archive changes.
+
+ \return
+ \c true, if the change is permitted; \c false otherwise.
+
+ */
+ bool OnFileNameChange(CZipFileHeader* pHeader, bool bInCentralOnly);
+
+ /**
+ Called when data of a file changes in a central directory file header.
+
+ \return
+ \c true, if the change is permitted; \c false otherwise.
+
+ */
+ bool OnFileCentralChange();
+
+ /**
+ Sets the current Unicode mode.
+
+ \see
+ CZipArchive::SetUnicodeMode
+ */
+ void SetUnicodeMode(int iMode) {m_iUnicodeMode = iMode;}
+
+ /**
+ Returns the current Unicode mode.
+
+ \see
+ CZipArchive::GetUnicodeMode
+ */
+ int GetUnicodeMode() const {return m_iUnicodeMode;}
+
+ /**
+ Examines whether any file is modified.
+ \return
+ \c true, if there are modified files; \c false otherwise.
+
+ \see
+ CZipArchive::IsModified
+ */
+ bool IsAnyFileModified() const;
+
+ /**
+ Throws an exception with the given code.
+ */
+ void ThrowError(int err) const;
+
+ CZipArchive* GetArchive()
+ {
+ return m_pArchive;
+ }
+
+ ZIP_FILE_USIZE LocateSignature() ;
protected:
+ /**
+ The reference to the main CZipArchive object.
+ */
+ CZipArchive* m_pArchive;
+
+ /**
+ Points to CZipArchive::m_storage.
+ */
+ CZipStorage* m_pStorage;
+
#if _MSC_VER > 1000
#pragma warning( push )
#pragma warning (disable : 4702) // unreachable code
#endif
+
+ /**
+ The current Unicode mode.
+ */
+ int m_iUnicodeMode;
+
/**
The method used in comparison when sorting headers.
*/
static int CompareHeaders(const void *pArg1, const void *pArg2)
- {
- CZipFileHeader* pw1 = *(CZipFileHeader**)pArg1;
- CZipFileHeader* pw2 = *(CZipFileHeader**)pArg2;
- if (pw1 == pw2)
+ {
+ CZipFileHeader* pHeader1 = *(CZipFileHeader**)pArg1;
+ CZipFileHeader* pHeader2 = *(CZipFileHeader**)pArg2;
+
+ if (pHeader1 == pHeader2)
return 0;
- if (pw1->m_uVolumeStart == pw2->m_uVolumeStart)
+ if (pHeader1->m_uVolumeStart == pHeader2->m_uVolumeStart)
{
- if (pw1->m_uOffset < pw2->m_uOffset)
+ if (pHeader1->m_uOffset < pHeader2->m_uOffset)
return -1;
- else if (pw1->m_uOffset > pw2->m_uOffset)
+ else if (pHeader1->m_uOffset > pHeader2->m_uOffset)
return 1;
- ASSERT(FALSE);
-
-
- // two files with the same offsets in the same volume???
- CZipException::Throw(CZipException::badZipFile);
- return 0; // just for the compiler comfort (and discomfort of another)
+ // if we have two headers with the same offset on the same volume,
+ // we want them to be next to each other so that we can throw an exception while verifying headers after sorting
+ else
+ return 0;
}
- else if (pw1->m_uVolumeStart < pw2->m_uVolumeStart)
+ else if (pHeader1->m_uVolumeStart < pHeader2->m_uVolumeStart)
return -1;
- else // if (pw1->m_uVolumeStart > pw2->m_uVolumeStart)
- return 1;
+ else // if (pHeader1->m_uVolumeStart > pHeader2->m_uVolumeStart)
+ return 1;
}
#if _MSC_VER > 1000
@@ -617,7 +669,7 @@ protected:
}
/**
- Holds the information about all the files inside the archive.
+ Holds the information about all files inside the archive.
\see
CZipFileHeader
@@ -672,7 +724,7 @@ protected:
}
/**
- Inserts a new CZipFindFast element to the CZipCentralDir::m_pFindArray array
+ Inserts a new CZipFindFast element to the CZipCentralDir::m_pFindArray array.
Initializes the CZipFindFast object with \a pHeader and \a uIndex values.
\param pHeader
@@ -687,6 +739,16 @@ protected:
*/
ZIP_INDEX_TYPE InsertFindFastElement(CZipFileHeader* pHeader, ZIP_INDEX_TYPE uIndex);
+ /**
+ Removes a CZipFindFast element from the CZipCentralDir::m_pFindArray array.
+
+ \param pHeader
+ The element associated with this object will be removed.
+
+ \param bShift
+ If \c true, the affected indexes will be shifted; \c false otherwise.
+ */
+ ZIP_INDEX_TYPE RemoveFindFastElement(CZipFileHeader* pHeader, bool bShift);
/**
The central directory information.
@@ -698,17 +760,8 @@ protected:
/**
Reads file headers from the archive.
-
- \param bExhaustiveRead
- \c true, if the exhaustive read should be performed, \c false otherwise.
-
- \note
- Throws exceptions.
-
- \see
- CZipArchive::SetExhaustiveRead
*/
- void ReadHeaders(bool bExhaustiveRead);
+ void ReadHeaders();
/**
Frees the memory allocated for the CZipFileHeader structures.
@@ -716,25 +769,21 @@ protected:
void RemoveHeaders();
/**
- Removes data descriptors from a segmented archive that turned out to be one-segment only.
+ Removes data descriptors from a segmented archive that turned out to be single-segment only.
It is not called for encrypted files.
\param bFromBuffer
- If \c true, removes from the write buffer in memory otherwise from the file on the disk.
+ If \c true, removes the descriptors from the write buffer in memory otherwise from the file on the disk.
\return
\c false, if the file mapping to memory was not successful
(can happen only when \a bFromBuffer is \c false); \c true otherwise.
- \note
- Throws exceptions.
*/
bool RemoveDataDescr(bool bFromBuffer);
/**
Writes the file headers to the archive.
- \note
- Throws exceptions.
*/
void WriteHeaders(bool bOneDisk);
@@ -744,18 +793,11 @@ protected:
\return
The size of the record.
- \note
- Throws exceptions.
*/
void WriteCentralEnd();
/**
- Throws an exception with the given code.
- */
- void ThrowError(int err) const;
-
- /**
Creates data that can be shared between different archive objects.
\see
@@ -767,21 +809,17 @@ protected:
Destroys data shared between different archive objects, if the usage reference count
of the data is zero.
- \note
- Throws exceptions.
-
+
\see
CreateSharedData
*/
void DestroySharedData();
-#ifdef ZIP_ARCHIVE_USE_LOCKING
+#ifdef _ZIP_USE_LOCKING
/**
Locks the access to the shared data.
- \note
- Throws exceptions.
-
+
\see
UnlockAccess
\see
@@ -797,9 +835,7 @@ protected:
/**
Unlocks the access to the shared data.
- \note
- Throws exceptions.
-
+
\see
LockAccess
\see
@@ -811,7 +847,8 @@ protected:
m_pInfo->m_mutex.Unlock();
}
#endif
-
+private:
+ void InitUnicode();
};
#if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)