From 0befd9ce5c28517cb6ef18694f0a0a7173ad8fbe Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Tue, 20 May 2025 18:06:56 +0100 Subject: [PATCH] Disable mutex in shell extension. Instead, we confirm that key deletion or insertion during enumeration produces weird behaviour, but should not crash. Fixes #115 --- src/pyshellext/shellext.cpp | 39 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/pyshellext/shellext.cpp b/src/pyshellext/shellext.cpp index 67edb80..3d360e1 100644 --- a/src/pyshellext/shellext.cpp +++ b/src/pyshellext/shellext.cpp @@ -373,7 +373,6 @@ class PyManagerOperationInProgress class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand : public RuntimeClass, IExplorerCommand, IObjectWithSite> { - PyManagerOperationInProgress busy; std::vector idles; std::wstring iconPath; std::wstring title; @@ -392,21 +391,19 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand iconPath += L",-4"; } - if (!busy) { - hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_32KEY); - if (SUCCEEDED(hr)) { - hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_64KEY); - } - if (SUCCEEDED(hr)) { - hr = ReadAllIdleInstalls(idles, HKEY_CURRENT_USER, L"Software\\Python", 0); - } + hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_32KEY); + if (SUCCEEDED(hr)) { + hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_64KEY); + } + if (SUCCEEDED(hr)) { + hr = ReadAllIdleInstalls(idles, HKEY_CURRENT_USER, L"Software\\Python", 0); + } - if (FAILED(hr)) { - wchar_t buffer[512]; - swprintf_s(buffer, L"IdleCommand error 0x%08X", (DWORD)hr); - OutputDebugStringW(buffer); - idles.clear(); - } + if (FAILED(hr)) { + wchar_t buffer[512]; + swprintf_s(buffer, L"IdleCommand error 0x%08X", (DWORD)hr); + OutputDebugStringW(buffer); + idles.clear(); } } @@ -425,12 +422,10 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand iconPath += L",-4"; } - if (!busy) { - hr = ReadAllIdleInstalls(idles, hive, root, 0); + hr = ReadAllIdleInstalls(idles, hive, root, 0); - if (FAILED(hr)) { - idles.clear(); - } + if (FAILED(hr)) { + idles.clear(); } } #endif @@ -469,6 +464,10 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand IFACEMETHODIMP GetState(IShellItemArray *psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE *pCmdState) { + if (title.empty()) { + *pCmdState = ECS_HIDDEN; + return S_OK; + } *pCmdState = idles.size() ? ECS_ENABLED : ECS_DISABLED; return S_OK; }