diff --git a/QuickLook.Native/QuickLook.Native32/DOpus.cpp b/QuickLook.Native/QuickLook.Native32/DOpus.cpp index dae2360..982fe03 100644 --- a/QuickLook.Native/QuickLook.Native32/DOpus.cpp +++ b/QuickLook.Native/QuickLook.Native32/DOpus.cpp @@ -103,7 +103,7 @@ void DOpus::ParseXmlBuffer(PWCHAR buffer) auto b = new WCHAR[size]; MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, -1, b, size); - wcscpy_s(buffer, MAX_PATH, b); + wcscpy_s(buffer, MAX_PATH_EX, b); // DOpus supports Long Path delete[] b; return; // we now cares only the first result diff --git a/QuickLook.Native/QuickLook.Native32/DialogHook.cpp b/QuickLook.Native/QuickLook.Native32/DialogHook.cpp index a0bbc41..7feb7e2 100644 --- a/QuickLook.Native/QuickLook.Native32/DialogHook.cpp +++ b/QuickLook.Native/QuickLook.Native32/DialogHook.cpp @@ -58,9 +58,9 @@ void DialogHook::GetSelected(PWCHAR buffer) if (!IsWow64Process(GetCurrentProcess(), &isSelfWoW64)) return; + // if QuickLook is 64bit and target is 32bit, obtain result from the helper if (isTargetWoW64 && !isSelfWoW64) { - // if self is 64bit and target is 32bit, do this GetSelectedFromWoW64HookHelper(buffer); } else @@ -72,7 +72,8 @@ void DialogHook::GetSelected(PWCHAR buffer) return; SendMessage(hwndfg, WM_HOOK_NOTIFY, 0, 0); - wcscpy_s(buffer, MAX_PATH, filePathBuffer); + + GetLongPathName(filePathBuffer, buffer, MAX_PATH_EX); } } @@ -114,7 +115,7 @@ void DialogHook::GetSelectedFromWoW64HookHelper(PWCHAR buffer) SendMessage(hHelperWnd, WM_HOOK_NOTIFY, 0, 0); // the sharedBuffer should now ready - wcscpy_s(buffer, MAX_PATH, sharedBuffer); + GetLongPathName(sharedBuffer, buffer, MAX_PATH_EX); UnmapViewOfFile(sharedBuffer); CloseHandle(hMapFile); diff --git a/QuickLook.Native/QuickLook.Native32/Everything.cpp b/QuickLook.Native/QuickLook.Native32/Everything.cpp index 4a96f30..0fb41db 100644 --- a/QuickLook.Native/QuickLook.Native32/Everything.cpp +++ b/QuickLook.Native/QuickLook.Native32/Everything.cpp @@ -43,7 +43,7 @@ void Everything::GetSelected(PWCHAR buffer) auto p = wcsstr(pText, L"\r\n"); auto l = p == nullptr ? wcslen(pText) : p - pText; - wcsncpy_s(buffer, MAX_PATH, pText, l); + wcsncpy_s(buffer, MAX_PATH_EX, pText, l); // Everything supports Long Path GlobalUnlock(hData); diff --git a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp index 891189d..53248a8 100644 --- a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp +++ b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp @@ -60,7 +60,10 @@ void HelperMethods::ObtainFirstItem(CComPtr dao, PWCHAR buffer) if (n < 1) return; - DragQueryFile(HDROP(medium.hGlobal), 0, buffer, MAX_PATH - 1); + WCHAR localBuffer[MAX_PATH] = { '\0' }; + DragQueryFile(HDROP(medium.hGlobal), 0, localBuffer, MAX_PATH); + + GetLongPathName(localBuffer, buffer, MAX_PATH_EX); } bool HelperMethods::IsListaryToolbarVisible() diff --git a/QuickLook.Native/QuickLook.Native32/stdafx.h b/QuickLook.Native/QuickLook.Native32/stdafx.h index 0e9de54..d11dc51 100644 --- a/QuickLook.Native/QuickLook.Native32/stdafx.h +++ b/QuickLook.Native/QuickLook.Native32/stdafx.h @@ -33,3 +33,5 @@ #include #include #include + +#define MAX_PATH_EX 32767 diff --git a/QuickLook.Native/QuickLook.WoW64HookHelper/QuickLook.WoW64HookHelper.cpp b/QuickLook.Native/QuickLook.WoW64HookHelper/QuickLook.WoW64HookHelper.cpp index 61630a6..367f709 100644 --- a/QuickLook.Native/QuickLook.WoW64HookHelper/QuickLook.WoW64HookHelper.cpp +++ b/QuickLook.Native/QuickLook.WoW64HookHelper/QuickLook.WoW64HookHelper.cpp @@ -81,7 +81,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) void GetCurrentSelection() { - WCHAR dllBuffer[MAX_PATH] = {'\0'}; + // This function runs inside the target process. Some of them may already support Long Path. + // Therefore, we must assume all of them support Long Path to avoid buffer overflow. + WCHAR dllBuffer[MAX_PATH_EX] = {'\0'}; pGCS(dllBuffer); auto hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, SHARED_MEM_NAME); @@ -95,7 +97,7 @@ void GetCurrentSelection() return; } - wcscpy_s(buffer, MAX_PATH, dllBuffer); + wcscpy_s(buffer, MAX_PATH_EX, dllBuffer); UnmapViewOfFile(buffer); CloseHandle(hMapFile); diff --git a/QuickLook.Native/QuickLook.WoW64HookHelper/stdafx.h b/QuickLook.Native/QuickLook.WoW64HookHelper/stdafx.h index 3e49547..7118b5d 100644 --- a/QuickLook.Native/QuickLook.WoW64HookHelper/stdafx.h +++ b/QuickLook.Native/QuickLook.WoW64HookHelper/stdafx.h @@ -31,3 +31,4 @@ // TODO: reference additional headers your program requires here +#define MAX_PATH_EX 32767 diff --git a/QuickLook/App.config b/QuickLook/App.config index 7030e0b..4ae4955 100644 --- a/QuickLook/App.config +++ b/QuickLook/App.config @@ -5,7 +5,8 @@ - + + diff --git a/QuickLook/NativeMethods/QuickLook.cs b/QuickLook/NativeMethods/QuickLook.cs index ed0122c..43a8954 100644 --- a/QuickLook/NativeMethods/QuickLook.cs +++ b/QuickLook/NativeMethods/QuickLook.cs @@ -27,7 +27,7 @@ namespace QuickLook.NativeMethods { internal static class QuickLook { - private const int MaxPath = 8192; + private const int MaxPath = 32767; [DllImport("QuickLook.Native32.dll", EntryPoint = "Init", CallingConvention = CallingConvention.Cdecl)] diff --git a/QuickLook/Plugin/InfoPanel/WindowsThumbnailProvider.cs b/QuickLook/Plugin/InfoPanel/WindowsThumbnailProvider.cs index e0dd06f..bad6123 100644 --- a/QuickLook/Plugin/InfoPanel/WindowsThumbnailProvider.cs +++ b/QuickLook/Plugin/InfoPanel/WindowsThumbnailProvider.cs @@ -122,7 +122,7 @@ namespace QuickLook.Plugin.InfoPanel SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out var nativeShellItem); if (retCode != 0) - throw Marshal.GetExceptionForHR(retCode); + return IntPtr.Zero; var nativeSize = new NativeSize { diff --git a/QuickLook/app.manifest b/QuickLook/app.manifest index 37036a7..464897c 100644 --- a/QuickLook/app.manifest +++ b/QuickLook/app.manifest @@ -1,6 +1,7 @@  + - + @@ -53,12 +54,9 @@ - - PerMonitor - - - true - + PerMonitor + true + true @@ -79,4 +77,4 @@ --> - + \ No newline at end of file