From afaa1e420951743d8239e88bd194a889109fed5e Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Mon, 9 Jun 2014 12:47:15 +0100 Subject: [PATCH] Implemented single-instance checking. --- src/gui/main_win.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/gui/main_win.cpp b/src/gui/main_win.cpp index 448adff9..32adab05 100644 --- a/src/gui/main_win.cpp +++ b/src/gui/main_win.cpp @@ -50,8 +50,8 @@ using boost::format; int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { - // First do application loading. - //------------------------------ + // Do application init + //-------------------- string initError; YAML::Node settings; @@ -148,6 +148,23 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd return exit_code; } + + // Check if LOOT is already running + //--------------------------------- + + HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, L"LOOT.Shell.Instance"); + if (hMutex != NULL) { + // An instance of LOOT is already running, so quit. + return 0; + } + else { + //Create the mutex so that future instances will not run. + hMutex = ::CreateMutex(NULL, FALSE, L"LOOT.Shell.Instance"); + } + + // Back to CEF + //------------ + // Initialise CEF settings. CefSettings cef_settings; @@ -169,5 +186,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd // Shut down CEF. CefShutdown(); + // Release the program instance mutex. + if (hMutex != NULL) + ReleaseMutex(hMutex); + return 0; } \ No newline at end of file