diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2023-12-17 21:23:58 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2023-12-17 21:23:58 +0100 |
| commit | 02d6107c97b48888362e7c6a70dcac323c89d741 (patch) | |
| tree | 5069a77adaf73f7249ac79b6c49a47168a647ef8 /zip/ZipArchive/ZipCompatibility.cpp | |
| parent | 4e17c2527b106f1b493a3ac77c89858d14f834e2 (diff) | |
| download | tuxcmd-modules-02d6107c97b48888362e7c6a70dcac323c89d741.tar.xz | |
ZipArchive: Update to the 4.6.9 release
Diffstat (limited to 'zip/ZipArchive/ZipCompatibility.cpp')
| -rw-r--r-- | zip/ZipArchive/ZipCompatibility.cpp | 104 |
1 files changed, 83 insertions, 21 deletions
diff --git a/zip/ZipArchive/ZipCompatibility.cpp b/zip/ZipArchive/ZipCompatibility.cpp index e25cb31..2b34077 100644 --- a/zip/ZipArchive/ZipCompatibility.cpp +++ b/zip/ZipArchive/ZipCompatibility.cpp @@ -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
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
@@ -18,16 +18,9 @@ #include "ZipException.h"
#include "ZipAutoBuffer.h"
#include "ZipFileHeader.h"
+#include "ZipArchive.h"
-enum iInternalAttr
-{
- attROnly = 0x01,
- attHidd = 0x02,
- attSys = 0x04,
- attDir = 0x10,
- attArch = 0x20
-};
// *********************** WINDOWS **************************
#ifndef _WIN32
#define FILE_ATTRIBUTE_READONLY 0x00000001
@@ -43,10 +36,12 @@ enum iInternalAttr #define CREATE_USER_PERMISSIONS(x) ((x & 0x0007) << 6)
#define GROUP_PERMISSIONS_MASK 0x0038
+#define EXTRACT_GROUP_PERMISSIONS(x) ((x & GROUP_PERMISSIONS_MASK) >> 3)
#define CREATE_GROUP_PERMISSIONS(x) ((x & 0x0007) << 3)
#define OTHER_PERMISSIONS_MASK 0x0007
+#define EXTRACT_OTHER_PERMISSIONS(x) ((x & OTHER_PERMISSIONS_MASK))
#define CREATE_OTHER_PERMISSIONS(x) (x & 0x0007)
#define UNIX_DIRECTORY_ATTRIBUTE 0x4000
@@ -64,7 +59,7 @@ DWORD AttrDos(DWORD , bool ); DWORD AttrUnix(DWORD, bool);
DWORD AttrMac(DWORD , bool );
-conv_func conv_funcs[11] = {AttrDos,
+conv_func conv_funcs[21] = {AttrDos,
NULL,
NULL,
AttrUnix,
@@ -74,14 +69,24 @@ conv_func conv_funcs[11] = {AttrDos, AttrMac,
NULL,
NULL,
- AttrDos
+ NULL,
+ AttrDos,
+ NULL,
+ NULL,
+ NULL,
+ AttrDos,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ AttrMac,
};
DWORD ZipCompatibility::ConvertToSystem(DWORD uAttr, int iFromSystem, int iToSystem)
{
- if (iToSystem != iFromSystem && iFromSystem < 11 && iToSystem < 11)
+ if (iToSystem != iFromSystem && iFromSystem < zcLast && iToSystem < zcLast)
{
conv_func p = conv_funcs[iFromSystem], q = conv_funcs[iToSystem];
if (p && q)
@@ -92,14 +97,27 @@ DWORD ZipCompatibility::ConvertToSystem(DWORD uAttr, int iFromSystem, int iToSys return uAttr;
}
+DWORD ZipCompatibility::GetAsInternalAttributes(DWORD uAttr, int iFromSystem)
+{
+ if (iFromSystem < zcLast)
+ {
+ conv_func f = conv_funcs[iFromSystem];
+ if (!f)
+ {
+ CZipException::Throw(CZipException::platfNotSupp);
+ return 0; // for Code Analysis
+ }
+ return f(uAttr, true);
+ }
+ return uAttr;
+}
+
DWORD AttrDos(DWORD uAttr, bool )
{
return uAttr;
}
-
-
DWORD AttrUnix(DWORD uAttr, bool bFrom)
{
DWORD uNewAttr = 0;
@@ -109,7 +127,10 @@ DWORD AttrUnix(DWORD uAttr, bool bFrom) if (isDir)
uNewAttr = attDir;
+ DWORD uGroupAttr = EXTRACT_GROUP_PERMISSIONS(uAttr);
+ DWORD uOtherAttr = EXTRACT_OTHER_PERMISSIONS(uAttr);
uAttr = EXTRACT_USER_PERMISSIONS (uAttr);
+
// we may set archive attribute if the file hasn't got the execute permissions
// and is not a directory
@@ -119,20 +140,19 @@ DWORD AttrUnix(DWORD uAttr, bool bFrom) if (!(uAttr & UNIX_WRITE))
uNewAttr |= attROnly;
- if (!(uAttr & UNIX_READ))
+ if (!(uGroupAttr & UNIX_READ) && !(uOtherAttr & UNIX_READ))
uNewAttr |= attHidd;
}
else
{
- uNewAttr = 0;
+ uNewAttr = CREATE_USER_PERMISSIONS (UNIX_READ);
// we cannot assume that if the file hasn't the archive attribute set
// then it is executable and set execute permissions
if (!(uAttr & attHidd))
- uNewAttr |= (CREATE_OTHER_PERMISSIONS (UNIX_READ) | CREATE_GROUP_PERMISSIONS (UNIX_READ)) |
- CREATE_USER_PERMISSIONS (UNIX_READ);
+ uNewAttr |= (CREATE_OTHER_PERMISSIONS (UNIX_READ) | CREATE_GROUP_PERMISSIONS (UNIX_READ));
if (!(uAttr & attROnly))
@@ -161,7 +181,7 @@ DWORD AttrMac(DWORD uAttr, bool ) ZIPINLINE bool ZipCompatibility::IsPlatformSupported(int iCode)
{
return iCode == zcDosFat || iCode == zcUnix || iCode == zcMacintosh
- || iCode == zcNtfs || iCode == zcOs2Hpfs;
+ || iCode == zcNtfs || iCode == zcOs2Hpfs || iCode == zcVfat || iCode == zcMacDarwin;
}
void ZipCompatibility::ConvertBufferToString(CZipString& szString, const CZipAutoBuffer& buffer, UINT uCodePage)
@@ -217,3 +237,45 @@ void ZipCompatibility::SlashBackslashChg(CZipString& szFileName, bool bReplaceSl }
szFileName.Replace(c2, c1);
}
+
+void ZipCompatibility::NormalizePathSeparators(CZipString& szFileName)
+{
+ int iPlatform = ZipPlatform::GetSystemID();
+ ZipCompatibility::SlashBackslashChg(szFileName, iPlatform == ZipCompatibility::zcDosFat || iPlatform == ZipCompatibility::zcNtfs);
+}
+
+UINT ZipCompatibility::GetDefaultNameCodePage(int iPlatform)
+{
+ if (iPlatform == ZipCompatibility::zcDosFat || iPlatform == ZipCompatibility::zcNtfs)
+ return CP_OEMCP;
+ else if (iPlatform == ZipCompatibility::zcUnix || iPlatform == ZipCompatibility::zcMacintosh || iPlatform == zcMacDarwin)
+ return CP_UTF8;
+ else
+ return CP_ACP;
+}
+
+UINT ZipCompatibility::GetDefaultNameCodePage()
+{
+ return GetDefaultNameCodePage(ZipPlatform::GetSystemID());
+}
+
+UINT ZipCompatibility::GetDefaultCommentCodePage(int iPlatform)
+{
+ if (iPlatform == ZipCompatibility::zcUnix || iPlatform == ZipCompatibility::zcMacintosh || iPlatform == zcMacDarwin)
+ return CP_UTF8;
+ else
+ return CP_ACP;
+}
+
+UINT ZipCompatibility::GetDefaultPasswordCodePage(int iPlatform)
+{
+ if (iPlatform == ZipCompatibility::zcUnix || iPlatform == ZipCompatibility::zcMacintosh || iPlatform == zcMacDarwin)
+ return CP_UTF8;
+ else
+ return CP_ACP;
+}
+
+UINT ZipCompatibility::GetDefaultCommentCodePage()
+{
+ return GetDefaultCommentCodePage(ZipPlatform::GetSystemID());
+}
|
