diff --git a/src/manage/install_command.py b/src/manage/install_command.py index 7d728d5..a1a8e60 100644 --- a/src/manage/install_command.py +++ b/src/manage/install_command.py @@ -554,6 +554,8 @@ def _fatal_install_error(cmd, ex): def execute(cmd): LOGGER.debug("BEGIN install_command.execute: %r", cmd.args) + cmd.tags = [] + if cmd.refresh: if cmd.args: LOGGER.warn("Ignoring arguments; --refresh always refreshes all installs.") @@ -580,7 +582,6 @@ def execute(cmd): download_index = {"versions": []} if not cmd.by_id: - cmd.tags = [] for arg in cmd.args: if arg.casefold() == "default".casefold(): LOGGER.debug("Replacing 'default' with '%s'", cmd.default_tag) diff --git a/src/pyshellext/shellext.cpp b/src/pyshellext/shellext.cpp index 974bf92..67edb80 100644 --- a/src/pyshellext/shellext.cpp +++ b/src/pyshellext/shellext.cpp @@ -335,9 +335,45 @@ class DECLSPEC_UUID(CLSID_COMMAND_ENUMERATOR) CommandEnumerator }; +class PyManagerOperationInProgress +{ + HANDLE hGlobalSem; + bool busy; + + bool _create() { + hGlobalSem = CreateSemaphoreExW(NULL, 0, 1, + L"PyManager-OperationInProgress", 0, SEMAPHORE_MODIFY_STATE | SYNCHRONIZE); + + return (hGlobalSem && GetLastError() != ERROR_ALREADY_EXISTS); + } + +public: + PyManagerOperationInProgress() + { + busy = _create(); + } + + ~PyManagerOperationInProgress() + { + if (hGlobalSem) { + if (!busy) { + ReleaseSemaphore(hGlobalSem, 1, NULL); + } + CloseHandle(hGlobalSem); + } + } + + operator bool() + { + return hGlobalSem && !busy; + } +}; + + class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand : public RuntimeClass, IExplorerCommand, IObjectWithSite> { + PyManagerOperationInProgress busy; std::vector idles; std::wstring iconPath; std::wstring title; @@ -356,19 +392,21 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand iconPath += L",-4"; } - 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 (!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); + } - 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(); + } } } @@ -387,10 +425,12 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand iconPath += L",-4"; } - hr = ReadAllIdleInstalls(idles, hive, root, 0); + if (!busy) { + hr = ReadAllIdleInstalls(idles, hive, root, 0); - if (FAILED(hr)) { - idles.clear(); + if (FAILED(hr)) { + idles.clear(); + } } } #endif @@ -429,7 +469,7 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand IFACEMETHODIMP GetState(IShellItemArray *psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE *pCmdState) { - *pCmdState = idles.size() ? ECS_ENABLED : ECS_HIDDEN; + *pCmdState = idles.size() ? ECS_ENABLED : ECS_DISABLED; return S_OK; }