From c890eb95cac1640bafb034f8c29cfd2859fdc2fa Mon Sep 17 00:00:00 2001 From: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:04:07 +0200 Subject: [PATCH] [FileLocksmith]Fix triggering FileLocksmith unexpectedly through verbs (#34905) --- .../FileLocksmithExt/ExplorerCommand.cpp | 81 ++++++++++--------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp index e0eee3d781..bc4ab945ca 100644 --- a/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp +++ b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp @@ -166,51 +166,58 @@ IFACEMETHODIMP ExplorerCommand::QueryContextMenu(HMENU hmenu, UINT indexMenu, UI IFACEMETHODIMP ExplorerCommand::InvokeCommand(CMINVOKECOMMANDINFO* pici) { - Trace::Invoked(); - ipc::Writer writer; + HRESULT hr = E_FAIL; - if (HRESULT result = writer.start(); FAILED(result)) + if (FileLocksmithSettingsInstance().GetEnabled() && + pici && (IS_INTRESOURCE(pici->lpVerb)) && + (LOWORD(pici->lpVerb) == 0)) { - Trace::InvokedRet(result); - return result; - } + Trace::Invoked(); + ipc::Writer writer; - if (HRESULT result = LaunchUI(pici, &writer); FAILED(result)) - { - Trace::InvokedRet(result); - return result; - } - - IShellItemArray* shell_item_array; - HRESULT result = SHCreateShellItemArrayFromDataObject(m_data_obj, __uuidof(IShellItemArray), reinterpret_cast(&shell_item_array)); - if (SUCCEEDED(result)) - { - DWORD num_items; - shell_item_array->GetCount(&num_items); - for (DWORD i = 0; i < num_items; i++) + if (HRESULT result = writer.start(); FAILED(result)) { - IShellItem* item; - result = shell_item_array->GetItemAt(i, &item); - if (SUCCEEDED(result)) - { - LPWSTR file_path; - result = item->GetDisplayName(SIGDN_FILESYSPATH, &file_path); - if (SUCCEEDED(result)) - { - // TODO Aggregate items and send to UI - writer.add_path(file_path); - CoTaskMemFree(file_path); - } - - item->Release(); - } + Trace::InvokedRet(result); + return result; } - shell_item_array->Release(); + if (HRESULT result = LaunchUI(pici, &writer); FAILED(result)) + { + Trace::InvokedRet(result); + return result; + } + + IShellItemArray* shell_item_array; + hr = SHCreateShellItemArrayFromDataObject(m_data_obj, __uuidof(IShellItemArray), reinterpret_cast(&shell_item_array)); + if (SUCCEEDED(hr)) + { + DWORD num_items; + shell_item_array->GetCount(&num_items); + for (DWORD i = 0; i < num_items; i++) + { + IShellItem* item; + hr = shell_item_array->GetItemAt(i, &item); + if (SUCCEEDED(hr)) + { + LPWSTR file_path; + hr = item->GetDisplayName(SIGDN_FILESYSPATH, &file_path); + if (SUCCEEDED(hr)) + { + // TODO Aggregate items and send to UI + writer.add_path(file_path); + CoTaskMemFree(file_path); + } + + item->Release(); + } + } + + shell_item_array->Release(); + } } - Trace::InvokedRet(S_OK); - return S_OK; + Trace::InvokedRet(hr); + return hr; } IFACEMETHODIMP ExplorerCommand::GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pReserved, CHAR* pszName, UINT cchMax)