Skip to content

Commit

Permalink
Fix for Everything v1.5(a) and later. Supports both v1.4 and v1.5. Tu…
Browse files Browse the repository at this point in the history
…rning off 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 24, 2024
1 parent e2f1fdd commit 6c800b1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 25 deletions.
70 changes: 47 additions & 23 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,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<PWCHAR>(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<PWCHAR>(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()
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,11 +15,16 @@
// 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_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();
Expand Down
2 changes: 1 addition & 1 deletion QuickLook.Native/QuickLook.Native32/Shell32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
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 6c800b1

Please sign in to comment.