From 9d0233a740940ad0e9ae219788c7008e98f341d4 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 20 May 2023 16:57:08 +0200 Subject: [PATCH] code: Create mutexes to prevent Windows (un)installer from continuing Might fix the problem where people uninstall StreamFX while they still have OBS Studio open with StreamFX loaded. InnoSetup appears to ignore this in /VERYSILENT, so this is an additional guard against that. --- source/plugin.cpp | 1 - source/windll.cpp | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/source/plugin.cpp b/source/plugin.cpp index 00e363cf..ea304a2e 100644 --- a/source/plugin.cpp +++ b/source/plugin.cpp @@ -136,7 +136,6 @@ MODULE_EXPORT void obs_module_unload(void) _streamfx_gfx_opengl.reset(); } - DLOG_INFO("Unloaded Version %s", STREAMFX_VERSION_STRING); } catch (std::exception const& ex) { DLOG_ERROR("Unexpected exception in function '%s': %s", __FUNCTION_NAME__, ex.what()); diff --git a/source/windll.cpp b/source/windll.cpp index 14fefe71..0d561d49 100644 --- a/source/windll.cpp +++ b/source/windll.cpp @@ -4,9 +4,25 @@ #include "warning-disable.hpp" #include +#include #include "warning-enable.hpp" -BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) +std::shared_ptr local_mutex; +std::shared_ptr global_mutex; + +BOOL WINAPI DllMain(HINSTANCE, DWORD dwReason, LPVOID) { + if (dwReason == DLL_PROCESS_ATTACH) { + // Prevent installer from progressing while StreamFX is still active. + local_mutex = std::shared_ptr(CreateMutexW(NULL, TRUE, L"Local\\StreamFX-Setup"), [](HANDLE p) { + ReleaseMutex(p); + CloseHandle(p); + }); + global_mutex = std::shared_ptr(CreateMutexW(NULL, TRUE, L"Global\\StreamFX-Setup"), [](HANDLE p) { + ReleaseMutex(p); + CloseHandle(p); + }); + } + return TRUE; }