diff --git a/QuickLook.Native/QuickLook.Native32/Everything.cpp b/QuickLook.Native/QuickLook.Native32/Everything.cpp index 0fb41dba..7dd4291d 100644 --- a/QuickLook.Native/QuickLook.Native32/Everything.cpp +++ b/QuickLook.Native/QuickLook.Native32/Everything.cpp @@ -1,4 +1,4 @@ -// Copyright © 2017 Paddy Xu +// Copyright © 2017 Paddy Xu // // This file is part of QuickLook program. // @@ -18,36 +18,60 @@ #include "stdafx.h" #include "Everything.h" -#define EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW L"EVERYTHING" -#define EVERYTHING_IPC_ID_FILE_COPY_FULL_PATH_AND_NAME 41007 - void Everything::GetSelected(PWCHAR buffer) { - if (SendMessage( - FindWindow(EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW, nullptr), - WM_COMMAND, - MAKEWPARAM(EVERYTHING_IPC_ID_FILE_COPY_FULL_PATH_AND_NAME, 0), - 0)) - return; + auto hWinFG = GetForegroundWindow(); + + // Everything v1.5 IPC via hidden window. + HWND hWinI = FindWindowExW(hWinFG, NULL, EVERYTHING_IPC_HIDDEN_WIN_CLASS, NULL); + + if (hWinI != nullptr) { + int pLength = GetWindowTextLength(hWinI); + wchar_t* pText = new wchar_t[pLength + 1]; + GetWindowText(hWinI, pText, pLength + 1); + wcsncpy_s(buffer, MAX_PATH_EX, pText, pLength); + return; // Success. Clipboard access unnecessary. + } - if (!OpenClipboard(nullptr)) - return; + HWND hWin = FindWindowW(EVERYTHING_IPC_WINDOW_CLASS, NULL); - auto hData = GetClipboardData(CF_UNICODETEXT); - if (hData == nullptr) - return; + if (hWin != nullptr) { + // Everything IPC Clipboard + SendMessageW( + hWin, + WM_COMMAND, + MAKEWPARAM(EVERYTHING_IPC_COPY_TO_CLIPBOARD, 0), + 0); - auto pText = static_cast(GlobalLock(hData)); - if (pText == nullptr) - return; + Sleep(100); + + if (!OpenClipboard(nullptr)) + return; + + auto hData = GetClipboardData(CF_UNICODETEXT); + if (hData == nullptr) + return; - auto p = wcsstr(pText, L"\r\n"); - auto l = p == nullptr ? wcslen(pText) : p - pText; - wcsncpy_s(buffer, MAX_PATH_EX, pText, l); // Everything supports Long Path + auto pText = static_cast(GlobalLock(hData)); + if (pText == nullptr) + return; - GlobalUnlock(hData); + auto p = wcsstr(pText, L"\r\n"); + auto l = p == nullptr ? wcslen(pText) : p - pText; + wcsncpy_s(buffer, MAX_PATH_EX, pText, l); // Everything supports Long Path + + GlobalUnlock(hData); + CloseClipboard(); + } +} - CloseClipboard(); +bool Everything::MatchClass(PWCHAR classBuffer) +{ + WCHAR sMatchC[256] = { '\0' }; + WCHAR sMatchS[256] = EVERYTHING_IPC_WINDOW_CLASS; + int iLen = wcslen(sMatchS); + wcsncpy_s(sMatchC, classBuffer, iLen); + return (0 == wcscmp(sMatchC, sMatchS)); } void Everything::backupClipboard() diff --git a/QuickLook.Native/QuickLook.Native32/Everything.h b/QuickLook.Native/QuickLook.Native32/Everything.h index fcf3e4c4..6e4b4bec 100644 --- a/QuickLook.Native/QuickLook.Native32/Everything.h +++ b/QuickLook.Native/QuickLook.Native32/Everything.h @@ -15,11 +15,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#define EVERYTHING_IPC_HIDDEN_WIN_CLASS L"EVERYTHING_RESULT_LIST_FOCUS" +#define EVERYTHING_IPC_WINDOW_CLASS L"EVERYTHING" +#define EVERYTHING_IPC_COPY_TO_CLIPBOARD 41007 + #pragma once class Everything { public: static void GetSelected(PWCHAR buffer); + static bool MatchClass(PWCHAR classBuffer); private: static void backupClipboard(); diff --git a/QuickLook.Native/QuickLook.Native32/Shell32.cpp b/QuickLook.Native/QuickLook.Native32/Shell32.cpp index 7ddf5053..db3963ab 100644 --- a/QuickLook.Native/QuickLook.Native32/Shell32.cpp +++ b/QuickLook.Native/QuickLook.Native32/Shell32.cpp @@ -40,7 +40,7 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType() { return DOPUS; } - if (wcscmp(classBuffer, L"EVERYTHING") == 0 || wcscmp(classBuffer, L"EVERYTHING_SHELL_EXECUTE") == 0) + if (Everything::MatchClass(classBuffer)) { return EVERYTHING; } diff --git a/QuickLook/NativeMethods/QuickLook.cs b/QuickLook/NativeMethods/QuickLook.cs index 9d52c897..7a5830be 100644 --- a/QuickLook/NativeMethods/QuickLook.cs +++ b/QuickLook/NativeMethods/QuickLook.cs @@ -103,7 +103,12 @@ internal static string GetCurrentSelection() thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); - return ResolveShortcut(sb?.ToString() ?? string.Empty); + if(sb.Length > 2 && sb[0].Equals('"') && sb[sb.Length-1].Equals('"')) + { + // We got a quoted string which breaks ResolveShortcut + sb = sb.Replace("\"", "", 0, 1).Replace("\"", "", sb.Length-1, 1); + } + return ResolveShortcut(sb?.ToString() ?? String.Empty); } private static string ResolveShortcut(string path)