Skip to content

Commit

Permalink
code: Create mutexes to prevent Windows (un)installer from continuing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Xaymar committed May 20, 2023
1 parent 07182d2 commit 9d0233a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion source/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
18 changes: 17 additions & 1 deletion source/windll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 9d0233a

Please sign in to comment.