[ImageResizer]Fix silent context menu crash (#22503)

This commit is contained in:
Jaime Bernardo
2022-12-05 23:53:59 +00:00
committed by GitHub
parent ba9e2449f3
commit d300b007f2

View File

@@ -79,6 +79,12 @@ public:
IFACEMETHODIMP GetState(_In_opt_ IShellItemArray* selection, _In_ BOOL okToBeSlow, _Out_ EXPCMDSTATE* cmdState)
{
if (nullptr == selection) {
// We've observed that it's possible that a null gets passed instead of an empty array. Just don't show the context menu in this case.
*cmdState = ECS_HIDDEN;
return S_OK;
}
if (!CSettingsInstance().GetEnabled())
{
*cmdState = ECS_HIDDEN;
@@ -90,9 +96,14 @@ public:
#pragma warning(suppress : 26812)
PERCEIVED type;
PERCEIVEDFLAG flag;
IShellItem* shellItem;
IShellItem* shellItem=nullptr;
//Check extension of first item in the list (the item which is right-clicked on)
selection->GetItemAt(0, &shellItem);
HRESULT getItemResult = selection->GetItemAt(0, &shellItem);
if (S_OK != getItemResult || nullptr == shellItem) {
// Some safeguards to avoid runtime errors.
*cmdState = ECS_HIDDEN;
return S_OK;
}
LPTSTR pszPath;
// Retrieves the entire file system path of the file from its shell item
shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);