diff options
Diffstat (limited to 'zip/ZipArchive/ZipPathComponent_win.cpp')
| -rw-r--r-- | zip/ZipArchive/ZipPathComponent_win.cpp | 107 |
1 files changed, 84 insertions, 23 deletions
diff --git a/zip/ZipArchive/ZipPathComponent_win.cpp b/zip/ZipArchive/ZipPathComponent_win.cpp index 3a8ba8b..31cb623 100644 --- a/zip/ZipArchive/ZipPathComponent_win.cpp +++ b/zip/ZipArchive/ZipPathComponent_win.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,43 +9,102 @@ //
// 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 "_platform.h"
+#include "stdafx.h"
-#ifdef ZIP_ARCHIVE_WIN
+#ifdef _ZIP_SYSTEM_WIN
-#include "stdafx.h"
#include "ZipPathComponent.h"
+#include "ZipAutoBuffer.h"
+
+const CZipString CZipPathComponent::PathPrefix = _T("\\\\?\\unc\\");
CZipPathComponent::~CZipPathComponent()
{
}
-void CZipPathComponent::SetFullPath(LPCTSTR lpszFullPath)
+int CZipPathComponent::IsPrefixed(const CZipString& path)
{
+ int i = -1, iLen = PathPrefix.GetLength();
+ int pathLen = path.GetLength();
+ if (iLen > pathLen)
+ iLen = pathLen;
+ CZipString szPossiblePrefix = path.Left(iLen);
+ szPossiblePrefix.MakeLower(); // must perform case insensitive comparison
+ while (++i < iLen && szPossiblePrefix[i] == PathPrefix[i]);
+ return i;
+}
+
+#if defined _UNICODE && _MSC_VER >= 1400
+
+CZipString CZipPathComponent::AddPrefix(LPCTSTR path, bool isFolder)
+{
+
+ CZipString ret = path;
+ AddPrefix(ret, isFolder);
+ return ret;
+}
+
+void CZipPathComponent::AddPrefix(CZipString& path, bool isFolder)
+{
+
+ if (path.GetLength() >= (isFolder ? 248 : MAX_PATH))
+ {
+ int prefixLength = IsPrefixed(path);
+ if (prefixLength < ptUnicode)
+ {
+ if (prefixLength == ptUnc)
+ {
+ path = path.Mid(prefixLength);
+ // long UNC
+ path.Insert(0, PathPrefix.Left(CZipPathComponent::ptUncWin));
+ }
+ else
+ {
+ path.Insert(0, PathPrefix.Left(CZipPathComponent::ptUnicode));
+ }
+ }
+ }
+}
+
+#else
+
+CZipString CZipPathComponent::AddPrefix(LPCTSTR path, bool)
+{
+ return path;
+}
+
+void CZipPathComponent::AddPrefix(CZipString&, bool)
+{
+
+}
+
+#endif
+
+void CZipPathComponent::SetFullPath(LPCTSTR lpszFullPath)
+{
TCHAR szDrive[_MAX_DRIVE];
+ // moving to heap to avoid C6262
+ CZipAutoBuffer szDirBuffer;
+
#if defined _UNICODE && _MSC_VER >= 1400
- TCHAR szDir[32767];
+ const int dirBufferLength = 32767;
#else
- TCHAR szDir[_MAX_DIR];
+ const int dirBufferLength = _MAX_DIR;
#endif
+ szDirBuffer.Allocate(dirBufferLength * sizeof (TCHAR), true);
+ TCHAR* szDir = (TCHAR*)(char*)szDirBuffer;
TCHAR szFname[_MAX_FNAME];
TCHAR szExt[_MAX_EXT];
CZipString szTempPath(lpszFullPath);
- const CZipString szPrefix = _T("\\\\?\\unc\\");
- int i = -1, iLen = szPrefix.GetLength();
- if (iLen > szTempPath.GetLength())
- iLen = szTempPath.GetLength();
- CZipString szPossiblePrefix = szTempPath.Left(iLen);
- szPossiblePrefix.MakeLower(); // must perform case insensitive comparison
- while (++i < iLen && szPossiblePrefix[i] == szPrefix[i]);
- if (i == 2 || i == 4 || i == 8) // unc path, unicode path or unc path meeting windows file name conventions
+ int i = IsPrefixed(szTempPath);
+ if (i == ptUnc || i == ptUnicode || i == ptUncWin) // unc path, Unicode path or unc path meeting windows file name conventions
{
m_szPrefix = szTempPath.Left(i);
szTempPath = szTempPath.Mid(i);
@@ -53,16 +112,18 @@ void CZipPathComponent::SetFullPath(LPCTSTR lpszFullPath) else
m_szPrefix.Empty();
#if _MSC_VER >= 1400
- _tsplitpath_s(szTempPath, szDrive , szDir, szFname, szExt);
-#else
- _tsplitpath(szTempPath, szDrive , szDir, szFname, szExt);
+ _tsplitpath_s(szTempPath, szDrive, _MAX_DRIVE, szDir, dirBufferLength, szFname, _MAX_FNAME, szExt, _MAX_EXT);
+#elif defined __MINGW32__ || _MSC_VER >= 1200
+ _tsplitpath(szTempPath, szDrive, szDir, szFname, szExt);
+#else
+ _tsplitpath(szTempPath, szDrive, _MAX_DRIVE, szDir, dirBufferLength, szFname, _MAX_FNAME, szExt, _MAX_EXT);
#endif
m_szDrive = szDrive;
m_szDirectory = szDir;
- m_szDirectory.TrimLeft(m_cSeparator);
- m_szDirectory.TrimRight(m_cSeparator);
+ RemoveSeparatorsLeft(m_szDirectory);
+ RemoveSeparators(m_szDirectory);
SetExtension(szExt);
m_szFileTitle = szFname;
}
@@ -79,4 +140,4 @@ CZipString CZipPathComponent::GetNoDrive() const return szPath;
}
-#endif // ZIP_ARCHIVE_WIN
+#endif // _ZIP_SYSTEM_WIN
|
