Skip to content

Commit

Permalink
Fix for Everything v1.5(a). Supports both v1.4 and v1.5. Turning off …
Browse files Browse the repository at this point in the history
…alpha_instance is no longer necessary. Also fixes a bug which crashes QuickLook when the path returned by client program is quoted.
  • Loading branch information
Shaan committed Sep 22, 2024
1 parent e2f1fdd commit 28ed388
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
41 changes: 32 additions & 9 deletions QuickLook.Native/QuickLook.Native32/Everything.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 Paddy Xu
// Copyright © 2017 Paddy Xu
//
// This file is part of QuickLook program.
//
Expand All @@ -18,17 +18,40 @@
#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))
HWND hWin = FindWindowW(EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW, NULL);
HWND hWin15 = FindWindowW(EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW_15, NULL);
WPARAM wParam = MAKEWPARAM(EVERYTHING_IPC_ID_FILE_COPY_FULL_PATH_AND_NAME, 0);

if (hWin15 != nullptr) {
// Everything v1.5 IPC via hidden window.
HWND hWinI = FindWindowExW(hWin15, NULL, EVERYTHING_IPC_HIDDEN_WIN, 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.
}

// Everything v1.5 IPC Clipboard
SendMessage(
hWin,
WM_COMMAND,
wParam, 0);
} else if(hWin != nullptr) {
// Everything v1.4 IPC Clipboard
SendMessage(
hWin,
WM_COMMAND,
wParam, 0);
}
else {
// Neither matched
return;
}

if (!OpenClipboard(nullptr))
return;
Expand Down
5 changes: 5 additions & 0 deletions QuickLook.Native/QuickLook.Native32/Everything.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#define EVERYTHING_IPC_HIDDEN_WIN L"EVERYTHING_RESULT_LIST_FOCUS"
#define EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW L"EVERYTHING"
#define EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW_15 L"EVERYTHING_(1.5a)"
#define EVERYTHING_IPC_ID_FILE_COPY_FULL_PATH_AND_NAME 41007

#pragma once
class Everything
{
Expand Down
4 changes: 3 additions & 1 deletion QuickLook.Native/QuickLook.Native32/Shell32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
{
return DOPUS;
}
if (wcscmp(classBuffer, L"EVERYTHING") == 0 || wcscmp(classBuffer, L"EVERYTHING_SHELL_EXECUTE") == 0)
if (wcscmp(classBuffer, EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW_15) == 0 ||
wcscmp(classBuffer, EVERYTHING_IPC_SEARCH_CLIENT_WNDCLASSW) == 0 ||
wcscmp(classBuffer, EVERYTHING_IPC_HIDDEN_WIN) == 0)
{
return EVERYTHING;
}
Expand Down
7 changes: 6 additions & 1 deletion QuickLook/NativeMethods/QuickLook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 28ed388

Please sign in to comment.