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.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-05-20 16:57:08 +02:00 committed by Xaymar
parent 07182d2f89
commit 9d0233a740
2 changed files with 17 additions and 2 deletions

View file

@ -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());

View file

@ -4,9 +4,25 @@
#include "warning-disable.hpp"
#include <Windows.h>
#include <mutex>
#include "warning-enable.hpp"
BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID)
std::shared_ptr<void> local_mutex;
std::shared_ptr<void> 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<void>(CreateMutexW(NULL, TRUE, L"Local\\StreamFX-Setup"), [](HANDLE p) {
ReleaseMutex(p);
CloseHandle(p);
});
global_mutex = std::shared_ptr<void>(CreateMutexW(NULL, TRUE, L"Global\\StreamFX-Setup"), [](HANDLE p) {
ReleaseMutex(p);
CloseHandle(p);
});
}
return TRUE;
}