Main: add single-instance checking.
This commit is contained in:
parent
e99ff14749
commit
22c9627b84
1 changed files with 23 additions and 1 deletions
24
src/main.cpp
24
src/main.cpp
|
@ -18,7 +18,25 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <errhandlingapi.h>
|
||||||
|
#include <synchapi.h>
|
||||||
|
#include <winerror.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
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
|
#ifndef SAVETOOL_DEBUG_BUILD
|
||||||
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
|
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
|
||||||
|
|
||||||
|
@ -28,5 +46,9 @@ int main(int argc, char** argv) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SaveTool app({argc, argv});
|
SaveTool app({argc, argv});
|
||||||
return app.exec();
|
Int result = app.exec();
|
||||||
|
|
||||||
|
ReleaseMutex(mutex_handle);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue