Fix for Everything v1.5(a) and later. Supports both v1.4 and v1.5. Turning off alpha_instance is no longer necessary. Also fixes a bug which crashes QuickLook when the path returned by client program is quoted.

This commit is contained in:
Shaan
2024-09-22 16:22:27 +06:00
parent e2f1fddb09
commit 6c800b1379
4 changed files with 59 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
// Copyright © 2017 Paddy Xu // Copyright © 2017 Paddy Xu
// //
// This file is part of QuickLook program. // This file is part of QuickLook program.
// //
@@ -18,17 +18,32 @@
#include "stdafx.h" #include "stdafx.h"
#include "Everything.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) void Everything::GetSelected(PWCHAR buffer)
{ {
if (SendMessage( auto hWinFG = GetForegroundWindow();
FindWindow(EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW, nullptr),
// 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.
}
HWND hWin = FindWindowW(EVERYTHING_IPC_WINDOW_CLASS, NULL);
if (hWin != nullptr) {
// Everything IPC Clipboard
SendMessageW(
hWin,
WM_COMMAND, WM_COMMAND,
MAKEWPARAM(EVERYTHING_IPC_ID_FILE_COPY_FULL_PATH_AND_NAME, 0), MAKEWPARAM(EVERYTHING_IPC_COPY_TO_CLIPBOARD, 0),
0)) 0);
return;
Sleep(100);
if (!OpenClipboard(nullptr)) if (!OpenClipboard(nullptr))
return; return;
@@ -46,9 +61,18 @@ void Everything::GetSelected(PWCHAR buffer)
wcsncpy_s(buffer, MAX_PATH_EX, pText, l); // Everything supports Long Path wcsncpy_s(buffer, MAX_PATH_EX, pText, l); // Everything supports Long Path
GlobalUnlock(hData); 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() void Everything::backupClipboard()
{ {

View File

@@ -15,11 +15,16 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#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 #pragma once
class Everything class Everything
{ {
public: public:
static void GetSelected(PWCHAR buffer); static void GetSelected(PWCHAR buffer);
static bool MatchClass(PWCHAR classBuffer);
private: private:
static void backupClipboard(); static void backupClipboard();

View File

@@ -40,7 +40,7 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
{ {
return DOPUS; return DOPUS;
} }
if (wcscmp(classBuffer, L"EVERYTHING") == 0 || wcscmp(classBuffer, L"EVERYTHING_SHELL_EXECUTE") == 0) if (Everything::MatchClass(classBuffer))
{ {
return EVERYTHING; return EVERYTHING;
} }

View File

@@ -103,7 +103,12 @@ namespace QuickLook.NativeMethods
thread.SetApartmentState(ApartmentState.STA); thread.SetApartmentState(ApartmentState.STA);
thread.Start(); thread.Start();
thread.Join(); 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) private static string ResolveShortcut(string path)