Main: add single-instance checking.

This commit is contained in:
Guillaume Jacquemin 2021-07-28 15:17:46 +02:00
parent e99ff14749
commit 22c9627b84
1 changed files with 23 additions and 1 deletions

View File

@ -18,7 +18,25 @@
#include <fstream>
#include <errhandlingapi.h>
#include <synchapi.h>
#include <winerror.h>
int main(int argc, char** argv) {
void* mutex_handle = CreateMutexW(nullptr, 0, L"MassBuilderSaveTool");
if(!mutex_handle) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
"There was an error initialising the mutex.",nullptr);
return EXIT_FAILURE;
}
if(GetLastError() == ERROR_ALREADY_EXISTS) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
"There can be only one running instance of the application.",nullptr);
return EXIT_FAILURE;
}
#ifndef SAVETOOL_DEBUG_BUILD
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
@ -28,5 +46,9 @@ int main(int argc, char** argv) {
#endif
SaveTool app({argc, argv});
return app.exec();
Int result = app.exec();
ReleaseMutex(mutex_handle);
return result;
}