OSDN Git Service

Very Long Path and File Names (1)
authorGreyMerlin <GreyMerlin7@gmail.com>
Sun, 27 May 2018 23:12:46 +0000 (16:12 -0700)
committerGreyMerlin <GreyMerlin7@gmail.com>
Fri, 8 Jun 2018 00:21:08 +0000 (17:21 -0700)
* define MAX_PATH_FULL as 32767.  Use this to replace many instances of
MAX_PATH and _MAX_PATH

Src/Common/ClipBoard.h
Src/Common/RegOptionsMgr.cpp
Src/DirCmpReport.cpp
Src/FileOrFolderSelect.cpp
Src/Merge.cpp
Src/StdAfx.h
Src/paths.cpp
Src/paths.h

index b49ea3e..3b5960c 100644 (file)
@@ -17,8 +17,8 @@ template<class Container>
 void PutFilesToClipboard(const Container& list, HWND currentWindowHandle)
 {
        String strPaths, strPathsSepSpc;
-       strPaths.reserve(list.size() * MAX_PATH);
-       strPathsSepSpc.reserve(list.size() * MAX_PATH);
+       strPaths.reserve(list.size() * MAX_PATH_FULL);
+       strPathsSepSpc.reserve(list.size() * MAX_PATH_FULL);
 
        for (Container::const_iterator it = list.begin(); it != list.end(); ++it)
        {
index 28d275b..f32aee1 100644 (file)
@@ -12,6 +12,7 @@
 #include "varprop.h"
 #include "OptionsMgr.h"
 
+#define MAX_PATH_FULL 32767
 /**
  * @brief Split option name to path (in registry) and
  * valuename (in registry).
@@ -210,8 +211,8 @@ int CRegOptionsMgr::InitOption(const String& name, const varprop::VariantValue&
        // This just checks if the value exists, LoadValueFromReg() below actually
        // loads the value.
        DWORD type = 0;
-       BYTE dataBuf[MAX_PATH] = {0};
-       DWORD size = MAX_PATH;
+       BYTE dataBuf[MAX_PATH_FULL] = {0};
+       DWORD size = MAX_PATH_FULL;
        retValReg = RegQueryValueEx(hKey, strValueName.c_str(),
                0, &type, dataBuf, &size);
 
@@ -575,8 +576,8 @@ int CRegOptionsMgr::ImportOptions(const String& filename)
                }
                else if (value.GetType() == varprop::VT_STRING)
                {
-                       TCHAR strVal[MAX_PATH] = {0};
-                       GetPrivateProfileString(_T("WinMerge"), pKey, _T(""), strVal, MAX_PATH, filename.c_str());
+                       TCHAR strVal[MAX_PATH_FULL] = {0};
+                       GetPrivateProfileString(_T("WinMerge"), pKey, _T(""), strVal, MAX_PATH_FULL, filename.c_str());
                        value.SetString(strVal);
                        SaveOption(pKey, strVal);
                }
index 2f7c11a..62a81f2 100644 (file)
@@ -178,7 +178,7 @@ bool DirCmpReport::GenerateReport(String &errStr)
                                        "EndFragment:%09d\n";
                                static const char start[] = "<html><body>\n<!--StartFragment -->";
                                static const char end[] = "\n<!--EndFragment -->\n</body>\n</html>\n";
-                               char buffer[_MAX_PATH];
+                               char buffer[MAX_PATH_FULL];
                                int cbHeader = wsprintfA(buffer, header, 0, 0, 0, 0);
                                file.Write(buffer, cbHeader);
                                file.Write(start, sizeof start - 1);
index df95cbf..10cf7bd 100644 (file)
@@ -68,7 +68,7 @@ BOOL SelectFile(HWND parent, String& path,BOOL is_open /*=TRUE*/,
 
        // This will tell common file dialog what to show
        // and also this will hold its return value
-       TCHAR sSelectedFile[MAX_PATH] = {0};
+       TCHAR sSelectedFile[MAX_PATH_FULL] = {0};
 
        // check if specified path is a file
        if (initialPath && initialPath[0])
@@ -103,7 +103,7 @@ BOOL SelectFile(HWND parent, String& path,BOOL is_open /*=TRUE*/,
        ofn.lpstrCustomFilter = NULL;
        ofn.nFilterIndex = 1;
        ofn.lpstrFile = sSelectedFile;
-       ofn.nMaxFile = MAX_PATH;
+       ofn.nMaxFile = MAX_PATH_FULL;
        ofn.lpstrInitialDir = initialPath;
        ofn.lpstrTitle = title.c_str();
        ofn.lpstrFileTitle = NULL;
@@ -138,7 +138,7 @@ BOOL SelectFolder(String& path, LPCTSTR root_path /*=NULL*/,
 {
        BROWSEINFO bi;
        LPITEMIDLIST pidl;
-       TCHAR szPath[MAX_PATH] = {0};
+       TCHAR szPath[MAX_PATH_FULL] = {0};
        BOOL bRet = FALSE;
        String title = stitle;
        if (root_path == NULL)
@@ -218,7 +218,7 @@ BOOL SelectFileOrFolder(HWND parent, String& path, LPCTSTR initialPath /*=NULL*/
 
        // This will tell common file dialog what to show
        // and also this will hold its return value
-       TCHAR sSelectedFile[MAX_PATH];
+       TCHAR sSelectedFile[MAX_PATH_FULL];
 
        // check if specified path is a file
        if (initialPath && initialPath[0])
@@ -253,7 +253,7 @@ BOOL SelectFileOrFolder(HWND parent, String& path, LPCTSTR initialPath /*=NULL*/
        ofn.lpstrCustomFilter = NULL;
        ofn.nFilterIndex = 1;
        ofn.lpstrFile = sSelectedFile;
-       ofn.nMaxFile = MAX_PATH;
+       ofn.nMaxFile = MAX_PATH_FULL;
        ofn.lpstrInitialDir = initialPath;
        ofn.lpstrTitle = title.c_str();
        ofn.lpstrFileTitle = NULL;
index 543ac14..3885525 100644 (file)
@@ -908,7 +908,7 @@ BOOL CMergeApp::CreateBackup(BOOL bFolder, const String& pszPath)
 
                // Append filename and extension (+ optional .bak) to path
                if ((bakPath.length() + filename.length() + ext.length())
-                       < MAX_PATH)
+                       < MAX_PATH_FULL)
                {
                        success = TRUE;
                        bakPath = paths::ConcatPath(bakPath, filename);
index f411f09..3c64ea1 100644 (file)
@@ -83,6 +83,11 @@ int NTAPI LangMessageBox(UINT, UINT nType = MB_OK, UINT nIDHelp = (UINT)-1);
 #endif
 #define MAX_PATH (260 * sizeof(wchar_t) / sizeof(TCHAR))
 
+#ifdef MAX_PATH_FULL
+#  undef MAX_PATH_FULL
+#endif
+#define MAX_PATH_FULL (32767 * sizeof(wchar_t) / sizeof(TCHAR))
+
 #define WMPROFILE(x) CWinMergeProfile __wmtl__(x)
 
 class CWinMergeProfile
index 3db9165..cef8506 100644 (file)
@@ -73,12 +73,12 @@ PATH_EXISTENCE DoesPathExist(const String& szPath, bool (*IsArchiveFile)(const S
        // Expand environment variables:
        // Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
        const TCHAR *lpcszPath = szPath.c_str();
-       TCHAR expandedPath[_MAX_PATH];
+       TCHAR expandedPath[MAX_PATH_FULL];
 
        if (_tcschr(lpcszPath, '%'))
        {
-               DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, _MAX_PATH);
-               if (dwLen > 0 && dwLen < _MAX_PATH)
+               DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, MAX_PATH_FULL);
+               if (dwLen > 0 && dwLen < MAX_PATH_FULL)
                        lpcszPath = expandedPath;
        }
 
@@ -205,7 +205,8 @@ String GetLongPath(const String& szPath, bool bExpandEnvs)
        if (len < 1)
                return sPath;
 
-       TCHAR fullPath[_MAX_PATH] = {0};
+       TCHAR fullPath[MAX_PATH_FULL] = {0};
+       TCHAR *pFullPath = &fullPath[0];
        TCHAR *lpPart;
 
        //                                         GetFullPathName  GetLongPathName
@@ -220,22 +221,22 @@ String GetLongPath(const String& szPath, bool bExpandEnvs)
 
        // Expand environment variables:
        // Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
-       TCHAR expandedPath[_MAX_PATH];
+       TCHAR expandedPath[MAX_PATH_FULL];
        const TCHAR *lpcszPath = sPath.c_str();
        if (bExpandEnvs && _tcschr(lpcszPath, '%'))
        {
-               DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, _MAX_PATH);
-               if (dwLen > 0 && dwLen < _MAX_PATH)
+               DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, MAX_PATH_FULL);
+               if (dwLen > 0 && dwLen < MAX_PATH_FULL)
                        lpcszPath = expandedPath;
        }
 
-       DWORD dwLen = GetFullPathName(lpcszPath, _MAX_PATH, fullPath, &lpPart);
-       if (dwLen == 0 || dwLen >= _MAX_PATH)
+       DWORD dwLen = GetFullPathName(lpcszPath, MAX_PATH_FULL, fullPath, &lpPart);
+       if (dwLen == 0 || dwLen >= MAX_PATH_FULL)
                _tcscpy_safe(fullPath, lpcszPath);
 
        // We are done if this is not a short name.
-       if (_tcschr(fullPath, _T('~')) == NULL)
-               return fullPath;
+       if (_tcschr(pFullPath, _T('~')) == NULL)
+               return pFullPath;
 
        // We have to do it the hard way because GetLongPathName is not
        // available on Win9x and some WinNT 4
@@ -314,16 +315,16 @@ bool CreateIfNeeded(const String& szPath)
        if (GetDirName(szPath, sTemp))
                return true;
 
-       if (szPath.length() >= _MAX_PATH)
+       if (szPath.length() >= MAX_PATH_FULL)
                return false;
 
        // Expand environment variables:
        // Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
-       TCHAR fullPath[_MAX_PATH];
+       TCHAR fullPath[MAX_PATH_FULL];
        if (_tcschr(szPath.c_str(), '%'))
        {
-               DWORD dwLen = ExpandEnvironmentStrings(szPath.c_str(), fullPath, _MAX_PATH);
-               if (dwLen == 0 || dwLen >= _MAX_PATH)
+               DWORD dwLen = ExpandEnvironmentStrings(szPath.c_str(), fullPath, MAX_PATH_FULL);
+               if (dwLen == 0 || dwLen >= MAX_PATH_FULL)
                        _tcscpy_safe(fullPath, szPath.c_str());
        }
        else
@@ -478,11 +479,11 @@ String ExpandShortcut(const String &inFile)
                hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*) &ppf);
                if (SUCCEEDED(hres))
                {
-                       WCHAR wsz[MAX_PATH];
+                       WCHAR wsz[MAX_PATH_FULL];
 #ifdef _UNICODE
                        _tcscpy_safe(wsz, inFile.c_str());
 #else
-                       ::MultiByteToWideChar(CP_ACP, 0, inFile.c_str(), -1, wsz, MAX_PATH);
+                       ::MultiByteToWideChar(CP_ACP, 0, inFile.c_str(), -1, wsz, MAX_PATH_FULL);
 #endif
 
                        // Load shortcut
@@ -491,8 +492,8 @@ String ExpandShortcut(const String &inFile)
                        if (SUCCEEDED(hres))
                        {
                                // find the path from that
-                               TCHAR buf[MAX_PATH] = {0};
-                               psl->GetPath(buf, MAX_PATH, NULL, SLGP_UNCPRIORITY);
+                               TCHAR buf[MAX_PATH_FULL] = {0};
+                               psl->GetPath(buf, MAX_PATH_FULL, NULL, SLGP_UNCPRIORITY);
                                outFile = buf;
                        }
                        ppf->Release();
index 80ab7b4..4492dce 100644 (file)
@@ -8,6 +8,10 @@
 #include "PathContext.h"
 #include "UnicodeString.h"
 
+#ifndef MAX_PATH_FULL
+#  define MAX_PATH_FULL 32767
+#endif
+
 namespace paths
 {