From e2308f3108b8a891cd6d25cfec9ba501cf9bddf2 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Mon, 3 Feb 2020 13:20:19 -0800 Subject: [PATCH 1/6] Removed ImageResizer.exe location registry key --- installer/PowerToysSetup/Product.wxs | 1 - .../imageresizer/dll/ContextMenuHandler.cpp | 23 +++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index 8a215025608e..4bac15ca379c 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -261,7 +261,6 @@ - diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index 7ccac3393051..09d36ecdc294 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -35,6 +35,11 @@ HRESULT CContextMenuHandler::Initialize(_In_opt_ PCIDLIST_ABSOLUTE pidlFolder, _ { Uninitialize(); + if (!CSettings::GetEnabled()) + { + return E_FAIL; + } + if (pidlFolder) { m_pidlFolder = ILClone(pidlFolder); @@ -198,15 +203,14 @@ HRESULT CContextMenuHandler::InvokeCommand(_In_ CMINVOKECOMMANDINFO* pici) // TODO: Error handling and memory management HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici) { - // Set the application path from the registry - LPTSTR lpApplicationName = new TCHAR[MAX_PATH]; - ULONG nChars = MAX_PATH; - CRegKey regKey; - // Open registry key saved by installer under HKLM - regKey.Open(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\ImageResizer"), KEY_READ | KEY_WOW64_64KEY); - regKey.QueryStringValue(NULL, lpApplicationName, &nChars); - regKey.Close(); - + // Set the application path based on the location of the dll + LPTSTR buffer = new TCHAR[MAX_PATH]; + GetModuleFileName(g_hInst_imageResizer, buffer, MAX_PATH); + std::wstring::size_type pos = std::wstring(buffer).find_last_of(L"\\/"); + std::wstring path = std::wstring(buffer).substr(0, pos); + path = path + L"\\ImageResizer.exe"; + LPTSTR lpApplicationName = (LPTSTR)path.c_str(); + delete[] buffer; // Create an anonymous pipe to stream filenames SECURITY_ATTRIBUTES sa; HANDLE hReadPipe; @@ -220,7 +224,6 @@ HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici) CString commandLine; commandLine.Format(_T("\"%s\""), lpApplicationName); - delete[] lpApplicationName; // Set the output directory if (m_pidlFolder) From 43975ca1f1f5e69bf11bde8355f20b4a8f701846 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 5 Feb 2020 11:23:59 -0800 Subject: [PATCH 2/6] Added working resize pictures to MSIX context menu without icon --- .../imageresizer/dll/ContextMenuHandler.cpp | 134 ++++++++++++++++-- .../imageresizer/dll/ContextMenuHandler.h | 19 ++- src/modules/imageresizer/dll/stdafx.h | 2 + 3 files changed, 141 insertions(+), 14 deletions(-) diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index 09d36ecdc294..2458bba28909 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -5,6 +5,7 @@ #include "HDropIterator.h" #include "Settings.h" #include "common/icon_helpers.h" +#include extern HINSTANCE g_hInst_imageResizer; @@ -12,6 +13,7 @@ CContextMenuHandler::CContextMenuHandler() { m_pidlFolder = NULL; m_pdtobj = NULL; + app_name = GET_RESOURCE_STRING(IDS_RESIZE_PICTURES); } CContextMenuHandler::~CContextMenuHandler() @@ -189,19 +191,19 @@ HRESULT CContextMenuHandler::InvokeCommand(_In_ CMINVOKECOMMANDINFO* pici) { if (wcscmp(((CMINVOKECOMMANDINFOEX*)pici)->lpVerbW, RESIZE_PICTURES_VERBW) == 0) { - return ResizePictures(pici); + return ResizePictures(pici, nullptr); } } else if (LOWORD(pici->lpVerb) == ID_RESIZE_PICTURES) { - return ResizePictures(pici); + return ResizePictures(pici, nullptr); } return E_FAIL; } -// TODO: Error handling and memory management -HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici) +// This function is used for both MSI and MSIX. If pici is null and psiItemArray is not null then this is called by Invoke(MSIX). If pici is not null and psiItemArray is null then this is called by InvokeCommand(MSI). +HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici, IShellItemArray* psiItemArray) { // Set the application path based on the location of the dll LPTSTR buffer = new TCHAR[MAX_PATH]; @@ -243,7 +245,14 @@ HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici) startupInfo.cb = sizeof(STARTUPINFO); startupInfo.hStdInput = hReadPipe; startupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; - startupInfo.wShowWindow = pici->nShow; + if (pici) + { + startupInfo.wShowWindow = pici->nShow; + } + else + { + startupInfo.wShowWindow = SW_SHOWNORMAL; + } PROCESS_INFORMATION processInformation; @@ -263,17 +272,120 @@ HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici) CloseHandle(processInformation.hProcess); CloseHandle(processInformation.hThread); - // Stream the input files - HDropIterator i(m_pdtobj); - for (i.First(); !i.IsDone(); i.Next()) + // psiItemArray is NULL if called from InvokeCommand. This part is used for the MSI installer. It is not NULL if it is called from Invoke (MSIX). + if (!psiItemArray) { - CString fileName(i.CurrentItem()); - fileName.Append(_T("\r\n")); + // Stream the input files + HDropIterator i(m_pdtobj); + for (i.First(); !i.IsDone(); i.Next()) + { + CString fileName(i.CurrentItem()); + fileName.Append(_T("\r\n")); - writePipe.Write(fileName, fileName.GetLength() * sizeof(TCHAR)); + writePipe.Write(fileName, fileName.GetLength() * sizeof(TCHAR)); + } + } + else + { + //m_pdtobj will be NULL when invoked from the MSIX build as Initialize is never called (IShellExtInit functions aren't called in case of MSIX). + DWORD fileCount = 0; + // Gets the list of files currently selected using the IShellItemArray + psiItemArray->GetCount(&fileCount); + + std::ofstream logFile("D:\\arjunlog.txt"); + if (logFile.is_open()) + { + logFile << fileCount << std::endl; + } + // Iterate over the list of files + for (DWORD i = 0; i < fileCount; i++) + { + IShellItem* shellItem; + psiItemArray->GetItemAt(i, &shellItem); + LPWSTR itemName; + // Retrieves the entire file system path of the file from its shell item + shellItem->GetDisplayName(SIGDN_FILESYSPATH, &itemName); + CString fileName(itemName); + fileName.Append(_T("\r\n")); + // Write the file path into the input stream for image resizer + writePipe.Write(fileName, fileName.GetLength() * sizeof(TCHAR)); + LPSTR result = NULL; + + int len = WideCharToMultiByte(CP_UTF8, 0, itemName, -1, NULL, 0, 0, 0); + + if (len > 0) + { + result = new char[len + 1]; + if (result) + { + int resLen = WideCharToMultiByte(CP_UTF8, 0, itemName, -1, &result[0], len, 0, 0); + + if (resLen == len) + { + logFile.write(result, len); + } + + delete[] result; + } + } + logFile << std::endl; + } + + logFile.close(); } writePipe.Close(); return S_OK; } + +HRESULT __stdcall CContextMenuHandler::GetTitle(IShellItemArray* /*psiItemArray*/, LPWSTR* ppszName) +{ + return SHStrDup(app_name.c_str(), ppszName); +} + +HRESULT __stdcall CContextMenuHandler::GetIcon(IShellItemArray* /*psiItemArray*/, LPWSTR* ppszIcon) +{ + /*std::wstring iconResourcePath = get_module_filename(); + iconResourcePath += L",-"; + iconResourcePath += std::to_wstring(IDI_RESIZE_PICTURES); + return SHStrDup(iconResourcePath.c_str(), ppszIcon);*/ + *ppszIcon = nullptr; + return E_NOTIMPL; +} + +HRESULT __stdcall CContextMenuHandler::GetToolTip(IShellItemArray* /*psiItemArray*/, LPWSTR* ppszInfotip) +{ + *ppszInfotip = nullptr; + return E_NOTIMPL; +} + +HRESULT __stdcall CContextMenuHandler::GetCanonicalName(GUID* pguidCommandName) +{ + *pguidCommandName = __uuidof(this); + return S_OK; +} + +HRESULT __stdcall CContextMenuHandler::GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) +{ + *pCmdState = CSettings::GetEnabled() ? ECS_ENABLED : ECS_HIDDEN; + return S_OK; +} + +HRESULT __stdcall CContextMenuHandler::GetFlags(EXPCMDFLAGS* pFlags) +{ + *pFlags = ECF_DEFAULT; + return S_OK; +} + +HRESULT __stdcall CContextMenuHandler::EnumSubCommands(IEnumExplorerCommand** ppEnum) +{ + *ppEnum = nullptr; + return E_NOTIMPL; +} + +// psiItemArray contains the list of files that have been selected when the context menu entry is invoked +HRESULT __stdcall CContextMenuHandler::Invoke(IShellItemArray* psiItemArray, IBindCtx* /*pbc*/) +{ + return ResizePictures(nullptr, psiItemArray); +} diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.h b/src/modules/imageresizer/dll/ContextMenuHandler.h index 41bbd2612f8a..975ef17497c5 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.h +++ b/src/modules/imageresizer/dll/ContextMenuHandler.h @@ -12,15 +12,17 @@ using namespace ATL; -class ATL_NO_VTABLE CContextMenuHandler : +class ATL_NO_VTABLE __declspec(uuid("51B4D7E5-7568-4234-B4BB-47FB3C016A69")) CContextMenuHandler : public CComObjectRootEx, public CComCoClass, public IShellExtInit, - public IContextMenu + public IContextMenu, + public IExplorerCommand { BEGIN_COM_MAP(CContextMenuHandler) COM_INTERFACE_ENTRY(IShellExtInit) COM_INTERFACE_ENTRY(IContextMenu) + COM_INTERFACE_ENTRY(IExplorerCommand) END_COM_MAP() DECLARE_REGISTRY_RESOURCEID(IDR_CONTEXTMENUHANDLER) DECLARE_NOT_AGGREGATABLE(CContextMenuHandler) @@ -33,12 +35,23 @@ class ATL_NO_VTABLE CContextMenuHandler : HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, _In_ UINT* pReserved, LPSTR pszName, UINT cchMax); HRESULT STDMETHODCALLTYPE InvokeCommand(_In_ CMINVOKECOMMANDINFO* pici); + // Inherited via IExplorerCommand + virtual HRESULT __stdcall GetTitle(IShellItemArray* psiItemArray, LPWSTR* ppszName) override; + virtual HRESULT __stdcall GetIcon(IShellItemArray* psiItemArray, LPWSTR* ppszIcon) override; + virtual HRESULT __stdcall GetToolTip(IShellItemArray* psiItemArray, LPWSTR* ppszInfotip) override; + virtual HRESULT __stdcall GetCanonicalName(GUID* pguidCommandName) override; + virtual HRESULT __stdcall GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) override; + virtual HRESULT __stdcall Invoke(IShellItemArray* psiItemArray, IBindCtx* pbc) override; + virtual HRESULT __stdcall GetFlags(EXPCMDFLAGS* pFlags) override; + virtual HRESULT __stdcall EnumSubCommands(IEnumExplorerCommand** ppEnum) override; + private: void Uninitialize(); - HRESULT ResizePictures(CMINVOKECOMMANDINFO* pici); + HRESULT ResizePictures(CMINVOKECOMMANDINFO* pici, IShellItemArray* psiItemArray); PCIDLIST_ABSOLUTE m_pidlFolder; IDataObject* m_pdtobj; HBITMAP m_hbmpIcon = nullptr; + std::wstring app_name; }; OBJECT_ENTRY_AUTO(__uuidof(ContextMenuHandler), CContextMenuHandler) \ No newline at end of file diff --git a/src/modules/imageresizer/dll/stdafx.h b/src/modules/imageresizer/dll/stdafx.h index fc538545f7bd..48086c6e254e 100644 --- a/src/modules/imageresizer/dll/stdafx.h +++ b/src/modules/imageresizer/dll/stdafx.h @@ -12,9 +12,11 @@ #include "targetver.h" #include "resource.h" +#include #include #include #include #include +#include #include From a6fba977bafd144bddbb446766cffd86fa199173 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 5 Feb 2020 12:01:11 -0800 Subject: [PATCH 3/6] Fixed missing icon on MSIX build --- installer/MSIX/PackagingLayout.xml | 6 +++ installer/MSIX/appxmanifest.xml | 42 +++++++++++++++++++ .../imageresizer/dll/ContextMenuHandler.cpp | 36 ++-------------- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/installer/MSIX/PackagingLayout.xml b/installer/MSIX/PackagingLayout.xml index ef63b8396443..01cf7d103646 100644 --- a/installer/MSIX/PackagingLayout.xml +++ b/installer/MSIX/PackagingLayout.xml @@ -16,6 +16,12 @@ + + + + + + diff --git a/installer/MSIX/appxmanifest.xml b/installer/MSIX/appxmanifest.xml index d15bbeca3324..139566bb0992 100644 --- a/installer/MSIX/appxmanifest.xml +++ b/installer/MSIX/appxmanifest.xml @@ -36,6 +36,9 @@ + + + @@ -46,6 +49,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index 2458bba28909..7f187aadcdd4 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -5,7 +5,6 @@ #include "HDropIterator.h" #include "Settings.h" #include "common/icon_helpers.h" -#include extern HINSTANCE g_hInst_imageResizer; @@ -291,12 +290,6 @@ HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici, IShellIte DWORD fileCount = 0; // Gets the list of files currently selected using the IShellItemArray psiItemArray->GetCount(&fileCount); - - std::ofstream logFile("D:\\arjunlog.txt"); - if (logFile.is_open()) - { - logFile << fileCount << std::endl; - } // Iterate over the list of files for (DWORD i = 0; i < fileCount; i++) { @@ -309,29 +302,7 @@ HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici, IShellIte fileName.Append(_T("\r\n")); // Write the file path into the input stream for image resizer writePipe.Write(fileName, fileName.GetLength() * sizeof(TCHAR)); - LPSTR result = NULL; - - int len = WideCharToMultiByte(CP_UTF8, 0, itemName, -1, NULL, 0, 0, 0); - - if (len > 0) - { - result = new char[len + 1]; - if (result) - { - int resLen = WideCharToMultiByte(CP_UTF8, 0, itemName, -1, &result[0], len, 0, 0); - - if (resLen == len) - { - logFile.write(result, len); - } - - delete[] result; - } - } - logFile << std::endl; } - - logFile.close(); } writePipe.Close(); @@ -346,12 +317,11 @@ HRESULT __stdcall CContextMenuHandler::GetTitle(IShellItemArray* /*psiItemArray* HRESULT __stdcall CContextMenuHandler::GetIcon(IShellItemArray* /*psiItemArray*/, LPWSTR* ppszIcon) { - /*std::wstring iconResourcePath = get_module_filename(); + // Since ImageResizer is registered as a COM SurrogateServer the current module filename would be dllhost.exe. To get the icon we need the path of ImageResizerExt.dll, which can be obtained by passing the HINSTANCE of the dll + std::wstring iconResourcePath = get_module_filename(g_hInst_imageResizer); iconResourcePath += L",-"; iconResourcePath += std::to_wstring(IDI_RESIZE_PICTURES); - return SHStrDup(iconResourcePath.c_str(), ppszIcon);*/ - *ppszIcon = nullptr; - return E_NOTIMPL; + return SHStrDup(iconResourcePath.c_str(), ppszIcon); } HRESULT __stdcall CContextMenuHandler::GetToolTip(IShellItemArray* /*psiItemArray*/, LPWSTR* ppszInfotip) From d71f8c3235ab21767bd52edd62942fab0ca201fc Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 5 Feb 2020 12:33:34 -0800 Subject: [PATCH 4/6] Added comments --- installer/MSIX/appxmanifest.xml | 1 + installer/README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/installer/MSIX/appxmanifest.xml b/installer/MSIX/appxmanifest.xml index 139566bb0992..9cf9a1f6519e 100644 --- a/installer/MSIX/appxmanifest.xml +++ b/installer/MSIX/appxmanifest.xml @@ -49,6 +49,7 @@ + diff --git a/installer/README.md b/installer/README.md index a3d4006884fb..2d05361cae20 100644 --- a/installer/README.md +++ b/installer/README.md @@ -22,7 +22,7 @@ For the first-time installation, you'll need to generate a self-signed certifica 4. Run `.\msix_reinstall.ps1` from the devenv powershell #### What msix_reinstall.ps1 does -`msix_reinstall.ps1` removes the current PowerToys installation, restarts explorer.exe (to update PowerRename shell extension), builds `PowerToys-x64.msix` package, signs it with a PowerToys_TemporaryKey.pfx, and finally installs it. +`msix_reinstall.ps1` removes the current PowerToys installation, restarts explorer.exe (to update PowerRename and ImageResizer shell extension), builds `PowerToys-x64.msix` package, signs it with a PowerToys_TemporaryKey.pfx, and finally installs it. #### Removing all .msi/.msix PowerToys installations ```ps From e133de58de1e919fab2aeb1c81a527d674494f47 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 5 Feb 2020 13:49:22 -0800 Subject: [PATCH 5/6] Changed to single context handler entry --- installer/MSIX/appxmanifest.xml | 41 +------------------ .../imageresizer/dll/ContextMenuHandler.cpp | 24 ++++++++++- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/installer/MSIX/appxmanifest.xml b/installer/MSIX/appxmanifest.xml index 9cf9a1f6519e..ac430d596611 100644 --- a/installer/MSIX/appxmanifest.xml +++ b/installer/MSIX/appxmanifest.xml @@ -49,45 +49,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index 7f187aadcdd4..9ab6d38ee56a 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -338,7 +338,29 @@ HRESULT __stdcall CContextMenuHandler::GetCanonicalName(GUID* pguidCommandName) HRESULT __stdcall CContextMenuHandler::GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) { - *pCmdState = CSettings::GetEnabled() ? ECS_ENABLED : ECS_HIDDEN; + // Hide if the file is not an image + *pCmdState = ECS_HIDDEN; + // Suppressing C26812 warning as the issue is in the shtypes.h library +#pragma warning(suppress : 26812) + PERCEIVED type; + PERCEIVEDFLAG flag; + IShellItem* shellItem; + //Check extension of first item in the list (the item which is right-clicked on) + psiItemArray->GetItemAt(0, &shellItem); + LPTSTR pszPath; + // Retrieves the entire file system path of the file from its shell item + shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); + LPTSTR pszExt = PathFindExtension(pszPath); + + // TODO: Instead, detect whether there's a WIC codec installed that can handle this file + AssocGetPerceivedType(pszExt, &type, &flag, NULL); + + free(pszPath); + // If selected file is an image... + if (type == PERCEIVED_TYPE_IMAGE) + { + *pCmdState = CSettings::GetEnabled() ? ECS_ENABLED : ECS_HIDDEN; + } return S_OK; } From fe3124c6bf550ff345fe5122913d021650a0056d Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Thu, 6 Feb 2020 09:08:18 -0800 Subject: [PATCH 6/6] Made changes as per PR comments --- installer/MSIX/appxmanifest.xml | 2 +- src/modules/imageresizer/dll/ContextMenuHandler.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/installer/MSIX/appxmanifest.xml b/installer/MSIX/appxmanifest.xml index ac430d596611..0970fb4bb28d 100644 --- a/installer/MSIX/appxmanifest.xml +++ b/installer/MSIX/appxmanifest.xml @@ -36,7 +36,7 @@ - + diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index 9ab6d38ee56a..ffa669e1e482 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -205,13 +205,9 @@ HRESULT CContextMenuHandler::InvokeCommand(_In_ CMINVOKECOMMANDINFO* pici) HRESULT CContextMenuHandler::ResizePictures(CMINVOKECOMMANDINFO* pici, IShellItemArray* psiItemArray) { // Set the application path based on the location of the dll - LPTSTR buffer = new TCHAR[MAX_PATH]; - GetModuleFileName(g_hInst_imageResizer, buffer, MAX_PATH); - std::wstring::size_type pos = std::wstring(buffer).find_last_of(L"\\/"); - std::wstring path = std::wstring(buffer).substr(0, pos); + std::wstring path = get_module_folderpath(g_hInst_imageResizer); path = path + L"\\ImageResizer.exe"; LPTSTR lpApplicationName = (LPTSTR)path.c_str(); - delete[] buffer; // Create an anonymous pipe to stream filenames SECURITY_ATTRIBUTES sa; HANDLE hReadPipe; @@ -338,6 +334,11 @@ HRESULT __stdcall CContextMenuHandler::GetCanonicalName(GUID* pguidCommandName) HRESULT __stdcall CContextMenuHandler::GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) { + if (!CSettings::GetEnabled()) + { + *pCmdState = ECS_HIDDEN; + return S_OK; + } // Hide if the file is not an image *pCmdState = ECS_HIDDEN; // Suppressing C26812 warning as the issue is in the shtypes.h library @@ -359,7 +360,7 @@ HRESULT __stdcall CContextMenuHandler::GetState(IShellItemArray* psiItemArray, B // If selected file is an image... if (type == PERCEIVED_TYPE_IMAGE) { - *pCmdState = CSettings::GetEnabled() ? ECS_ENABLED : ECS_HIDDEN; + *pCmdState = ECS_ENABLED; } return S_OK; }