This commit is contained in:
Paddy Xu
2020-08-16 00:45:22 +02:00
parent a41a7bd24d
commit 7fc6e03ffa
11 changed files with 27 additions and 19 deletions

View File

@@ -103,7 +103,7 @@ void DOpus::ParseXmlBuffer(PWCHAR buffer)
auto b = new WCHAR[size]; auto b = new WCHAR[size];
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, -1, b, 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; delete[] b;
return; // we now cares only the first result return; // we now cares only the first result

View File

@@ -58,9 +58,9 @@ void DialogHook::GetSelected(PWCHAR buffer)
if (!IsWow64Process(GetCurrentProcess(), &isSelfWoW64)) if (!IsWow64Process(GetCurrentProcess(), &isSelfWoW64))
return; return;
// if QuickLook is 64bit and target is 32bit, obtain result from the helper
if (isTargetWoW64 && !isSelfWoW64) if (isTargetWoW64 && !isSelfWoW64)
{ {
// if self is 64bit and target is 32bit, do this
GetSelectedFromWoW64HookHelper(buffer); GetSelectedFromWoW64HookHelper(buffer);
} }
else else
@@ -72,7 +72,8 @@ void DialogHook::GetSelected(PWCHAR buffer)
return; return;
SendMessage(hwndfg, WM_HOOK_NOTIFY, 0, 0); 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); SendMessage(hHelperWnd, WM_HOOK_NOTIFY, 0, 0);
// the sharedBuffer should now ready // the sharedBuffer should now ready
wcscpy_s(buffer, MAX_PATH, sharedBuffer); GetLongPathName(sharedBuffer, buffer, MAX_PATH_EX);
UnmapViewOfFile(sharedBuffer); UnmapViewOfFile(sharedBuffer);
CloseHandle(hMapFile); CloseHandle(hMapFile);

View File

@@ -43,7 +43,7 @@ void Everything::GetSelected(PWCHAR buffer)
auto p = wcsstr(pText, L"\r\n"); auto p = wcsstr(pText, L"\r\n");
auto l = p == nullptr ? wcslen(pText) : p - pText; 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); GlobalUnlock(hData);

View File

@@ -60,7 +60,10 @@ void HelperMethods::ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer)
if (n < 1) if (n < 1)
return; 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() bool HelperMethods::IsListaryToolbarVisible()

View File

@@ -33,3 +33,5 @@
#include<Shellapi.h> #include<Shellapi.h>
#include<Psapi.h> #include<Psapi.h>
#include<AppModel.h> #include<AppModel.h>
#define MAX_PATH_EX 32767

View File

@@ -81,7 +81,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
void GetCurrentSelection() 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); pGCS(dllBuffer);
auto hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, SHARED_MEM_NAME); auto hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, SHARED_MEM_NAME);
@@ -95,7 +97,7 @@ void GetCurrentSelection()
return; return;
} }
wcscpy_s(buffer, MAX_PATH, dllBuffer); wcscpy_s(buffer, MAX_PATH_EX, dllBuffer);
UnmapViewOfFile(buffer); UnmapViewOfFile(buffer);
CloseHandle(hMapFile); CloseHandle(hMapFile);

View File

@@ -31,3 +31,4 @@
// TODO: reference additional headers your program requires here // TODO: reference additional headers your program requires here
#define MAX_PATH_EX 32767

View File

@@ -5,7 +5,8 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup> </startup>
<runtime> <runtime>
<AppContextSwitchOverrides value = " Switch.System.Windows.DoNotScaleForDpiChanges=false"/> <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
<AppContextSwitchOverrides value="Switch.System.Windows.DoNotScaleForDpiChanges=false" />
<legacyCorruptedStateExceptionsPolicy enabled="true" /> <legacyCorruptedStateExceptionsPolicy enabled="true" />
<legacyUnhandledExceptionPolicy enabled="1" /> <legacyUnhandledExceptionPolicy enabled="1" />
</runtime> </runtime>

View File

@@ -27,7 +27,7 @@ namespace QuickLook.NativeMethods
{ {
internal static class QuickLook internal static class QuickLook
{ {
private const int MaxPath = 8192; private const int MaxPath = 32767;
[DllImport("QuickLook.Native32.dll", EntryPoint = "Init", [DllImport("QuickLook.Native32.dll", EntryPoint = "Init",
CallingConvention = CallingConvention.Cdecl)] CallingConvention = CallingConvention.Cdecl)]

View File

@@ -122,7 +122,7 @@ namespace QuickLook.Plugin.InfoPanel
SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out var nativeShellItem); SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out var nativeShellItem);
if (retCode != 0) if (retCode != 0)
throw Marshal.GetExceptionForHR(retCode); return IntPtr.Zero;
var nativeSize = new NativeSize var nativeSize = new NativeSize
{ {

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security> <security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
@@ -53,12 +54,9 @@
<application xmlns="urn:schemas-microsoft-com:asm.v3"> <application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings> <windowsSettings>
<!-- The combination of below two tags have the following effect : 1) Per-Monitor for >= Windows 10 Anniversary Update 2) System < Windows 10 Anniversary Update --> <!-- The combination of below two tags have the following effect : 1) Per-Monitor for >= Windows 10 Anniversary Update 2) System < Windows 10 Anniversary Update -->
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor</dpiAwareness>
PerMonitor <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</dpiAwareness> <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
true
</dpiAware>
</windowsSettings> </windowsSettings>
</application> </application>