Skip to content
Browse files

Merge pull request #397 from adobe/jeff/fix-5270

Update all path buffers to accept long UNC paths
  • Loading branch information...
2 parents fb08bc8 + 55f9549 commit 08ff9ab20905ea009147c323bab995d469b263ef @redmunds redmunds committed Dec 6, 2013
View
37 appshell/appshell_extensions_win.cpp
@@ -40,11 +40,6 @@
#define UNICODE_LEFT_ARROW 0x2190
#define UNICODE_DOWN_ARROW 0x2193
-// Arbitrarily large size for path name buffers. Paths *could* contain
-// up to 32768 characters, but this buffer should be large enough to handle
-// any reasonable path.
-#define PATH_BUFFER_SIZE 4096
-
// Forward declarations for functions at the bottom of this file
void ConvertToNativePath(ExtensionString& filename);
void ConvertToUnixPath(ExtensionString& filename);
@@ -144,8 +139,8 @@ bool LiveBrowserMgrWin::IsChromeWindow(HWND hwnd)
return false;
}
- DWORD modulePathBufSize = _MAX_PATH+1;
- WCHAR modulePathBuf[_MAX_PATH+1];
+ DWORD modulePathBufSize = MAX_UNC_PATH+1;
+ WCHAR modulePathBuf[MAX_UNC_PATH+1];
DWORD modulePathSize = ::GetModuleFileNameEx(processHandle, NULL, modulePathBuf, modulePathBufSize );
::CloseHandle(processHandle);
processHandle = NULL;
@@ -298,9 +293,9 @@ static std::wstring GetPathToLiveBrowser()
HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe",
0, KEY_READ, &hKey)) {
- wchar_t wpath[MAX_PATH] = {0};
+ wchar_t wpath[MAX_UNC_PATH] = {0};
- DWORD length = MAX_PATH;
+ DWORD length = MAX_UNC_PATH;
RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)wpath, &length);
RegCloseKey(hKey);
@@ -310,7 +305,7 @@ static std::wstring GetPathToLiveBrowser()
// We didn't get an "App Paths" entry. This could be because Chrome was only installed for
// the current user, or because Chrome isn't installed at all.
// Look for Chrome.exe at C:\Users\{USERNAME}\AppData\Local\Google\Chrome\Application\chrome.exe
- TCHAR localAppPath[MAX_PATH] = {0};
+ TCHAR localAppPath[MAX_UNC_PATH] = {0};
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, localAppPath);
std::wstring appPath(localAppPath);
appPath += L"\\Google\\Chrome\\Application\\chrome.exe";
@@ -320,8 +315,8 @@ static std::wstring GetPathToLiveBrowser()
static bool ConvertToShortPathName(std::wstring & path)
{
- DWORD shortPathBufSize = _MAX_PATH+1;
- WCHAR shortPathBuf[_MAX_PATH+1];
+ DWORD shortPathBufSize = MAX_UNC_PATH+1;
+ WCHAR shortPathBuf[MAX_UNC_PATH+1];
DWORD finalShortPathSize = ::GetShortPathName(path.c_str(), shortPathBuf, shortPathBufSize);
if( finalShortPathSize == 0 ) {
return false;
@@ -413,7 +408,7 @@ int32 ShowOpenDialog(bool allowMultipleSelection,
ExtensionString fileTypes,
CefRefPtr<CefListValue>& selectedFiles)
{
- wchar_t szFile[MAX_PATH];
+ wchar_t szFile[MAX_UNC_PATH];
szFile[0] = 0;
// Windows common file dialogs can handle Windows path only, not Unix path.
@@ -489,7 +484,7 @@ int32 ShowOpenDialog(bool allowMultipleSelection,
ofn.hwndOwner = GetActiveWindow();
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = szFile;
- ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFile = MAX_UNC_PATH;
ofn.lpstrTitle = title.c_str();
// TODO (issue #65) - Use passed in file types. Note, when fileTypesStr is null, all files should be shown
@@ -519,7 +514,7 @@ int32 ShowOpenDialog(bool allowMultipleSelection,
selectedFiles->SetString(0, filePath);
} else {
// Multiple files are selected
- wchar_t fullPath[MAX_PATH];
+ wchar_t fullPath[MAX_UNC_PATH];
for (int i = (dir.length() + 1), fileIndex = 0; ; fileIndex++) {
// Get the next file name
std::wstring file(&szFile[i]);
@@ -563,10 +558,10 @@ int32 ShowSaveDialog(ExtensionString title,
ZeroMemory(&ofn, sizeof(ofn));
ofn.hwndOwner = GetActiveWindow();
ofn.lStructSize = sizeof(ofn);
- wchar_t szFile[MAX_PATH];
+ wchar_t szFile[MAX_UNC_PATH];
wcscpy(szFile, proposedNewFilename.c_str());
ofn.lpstrFile = szFile;
- ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFile = MAX_UNC_PATH;
ofn.lpstrFilter = L"All Files\0*.*\0Web Files\0*.js;*.css;*.htm;*.html\0Text Files\0*.txt\0\0";
ofn.lpstrInitialDir = initialDirectory.c_str();
ofn.Flags = OFN_ENABLESIZING | OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_EXPLORER;
@@ -694,11 +689,11 @@ int32 GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double
hFile = ::CreateFileW(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
- wchar_t pathBuffer[PATH_BUFFER_SIZE + 1];
+ wchar_t pathBuffer[MAX_UNC_PATH + 1];
DWORD nChars;
- nChars = (*pfn)(hFile, pathBuffer, PATH_BUFFER_SIZE, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
- if (nChars && nChars <= PATH_BUFFER_SIZE) {
+ nChars = (*pfn)(hFile, pathBuffer, MAX_UNC_PATH, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
+ if (nChars && nChars <= MAX_UNC_PATH) {
// Path returned by GetFilePathNameByHandle starts with "\\?\". Remove from returned value.
realPath = &pathBuffer[4];
@@ -819,7 +814,7 @@ int32 ShellDeleteFileOrDirectory(ExtensionString filename, bool allowUndo)
// that end with a trailing slash so remove it
RemoveTrailingSlash(filename);
- WCHAR filepath[MAX_PATH+1] = {0};
+ WCHAR filepath[MAX_UNC_PATH+1] = {0};
wcscpy(filepath, filename.c_str());
SHFILEOPSTRUCT operation = {0};
View
10 appshell/appshell_node_process_win.cpp
@@ -116,24 +116,24 @@ DWORD WINAPI NodeThread(LPVOID lpParam) {
nodeStartTime = timeGetTime();
HMODULE module = GetModuleHandle(NULL);
- TCHAR executablePath[MAX_PATH];
- TCHAR scriptPath[MAX_PATH];
+ TCHAR executablePath[MAX_UNC_PATH];
+ TCHAR scriptPath[MAX_UNC_PATH];
TCHAR commandLine[BRACKETS_NODE_BUFFER_SIZE];
- DWORD dwFLen = GetModuleFileName(module, executablePath, MAX_PATH);
+ DWORD dwFLen = GetModuleFileName(module, executablePath, MAX_UNC_PATH);
if (dwFLen == 0) {
fprintf(stderr, "[Node] Could not get module path");
ReleaseMutex(hNodeMutex);
restartNode(false);
return 0;
- } else if (dwFLen == MAX_PATH) {
+ } else if (dwFLen == MAX_UNC_PATH) {
fprintf(stderr, "[Node] Path to module exceede max path length");
ReleaseMutex(hNodeMutex);
restartNode(false);
return 0;
}
PathRemoveFileSpec(executablePath);
- StringCchCopy(scriptPath, MAX_PATH, executablePath);
+ StringCchCopy(scriptPath, MAX_UNC_PATH, executablePath);
PathAppend(executablePath, TEXT(NODE_EXECUTABLE_PATH));
PathAppend(scriptPath, TEXT(NODE_CORE_PATH));
View
2 appshell/cef_registry.cpp
@@ -82,7 +82,7 @@ bool GetRegistryInt(LPCWSTR pFolder, LPCWSTR pEntry, int* pDefault, int& ret)
HKEY hKey;
bool result = false;
- wchar_t key[MAX_PATH];
+ wchar_t key[MAX_UNC_PATH];
key[0] = '\0';
GetKey(g_szSoftwareFolder, GROUP_NAME, APP_NAME, pFolder, (LPWSTR)&key);
View
16 appshell/cefclient_win.cpp
@@ -37,8 +37,8 @@ std::wstring gFilesToOpen; // Filenames passed as arguments to
cef_main_window* gMainWnd = NULL;
// static variables (not exported)
-static char szWorkingDir[MAX_PATH]; // The current working directory
-static wchar_t szInitialUrl[MAX_PATH] = {0};
+static char szWorkingDir[MAX_UNC_PATH]; // The current working directory
+static wchar_t szInitialUrl[MAX_UNC_PATH] = {0};
// Forward declarations of functions included in this code module:
@@ -131,7 +131,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
return exit_code;
// Retrieve the current working directory.
- if (_getcwd(szWorkingDir, MAX_PATH) == NULL)
+ if (_getcwd(szWorkingDir, MAX_UNC_PATH) == NULL)
szWorkingDir[0] = 0;
// Parse command line arguments. The passed in values are ignored on Windows.
@@ -191,9 +191,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
if (GetAsyncKeyState(VK_SHIFT) == 0) {
// Get the full pathname for the app. We look for the index.html
// file relative to this location.
- wchar_t appPath[MAX_PATH];
+ wchar_t appPath[MAX_UNC_PATH];
wchar_t *pathRoot;
- GetModuleFileName(NULL, appPath, MAX_PATH);
+ GetModuleFileName(NULL, appPath, MAX_UNC_PATH);
// Strip the .exe filename (and preceding "\") from the appPath
// and store in pathRoot
@@ -223,7 +223,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = szInitialUrl;
- ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFile = MAX_UNC_PATH;
ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0";
ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file.";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER;
@@ -318,8 +318,8 @@ void GetFileVersionString(std::wstring &retVersion) {
UINT pLenFileInfo = 0;
HMODULE module = GetModuleHandle(NULL);
- TCHAR executablePath[MAX_PATH];
- GetModuleFileName(module, executablePath, MAX_PATH);
+ TCHAR executablePath[MAX_UNC_PATH];
+ GetModuleFileName(module, executablePath, MAX_UNC_PATH);
dwSize = GetFileVersionInfoSize(executablePath, NULL);
if (dwSize == 0) {
View
4 appshell/client_app_win.cpp
@@ -92,7 +92,7 @@ double ClientApp::GetElapsedMilliseconds()
CefString ClientApp::AppGetSupportDirectory()
{
- wchar_t dataPath[MAX_PATH];
+ wchar_t dataPath[MAX_UNC_PATH];
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dataPath);
std::wstring appSupportPath = dataPath;
@@ -107,7 +107,7 @@ CefString ClientApp::AppGetSupportDirectory()
CefString ClientApp::AppGetDocumentsDirectory()
{
- wchar_t dataPath[MAX_PATH] = {0};
+ wchar_t dataPath[MAX_UNC_PATH] = {0};
SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dataPath);
std::wstring appUserDocuments = dataPath;
View
3 appshell/config.h
@@ -26,6 +26,9 @@
// Application name used in native code. This name is *not* used in resources.
#ifdef OS_WIN
+// MAX_PATH is only 260 chars which really isn't big enough for really long unc pathnames
+// so use this constant instead which accounts for some really long pathnames
+#define MAX_UNC_PATH 4096
// Name of group (if any) that application prefs/settings/etc. are stored under
// This must be an empty string (for no group), or a string that ends with "\\"
#define GROUP_NAME L""

0 comments on commit 08ff9ab

Please sign in to comment.
Something went wrong with that request. Please try again.