[FileLocksmith]Fix triggering FileLocksmith unexpectedly through verbs (#34905)

This commit is contained in:
Stefan Markovic 2024-09-24 12:04:07 +02:00 committed by GitHub
parent cc586a0357
commit c890eb95ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<void**>(&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<void**>(&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)