iw4x-client/src/Components/Modules/Singleton.cpp

37 lines
936 B
C++
Raw Normal View History

2022-02-27 07:53:44 -05:00
#include <STDInclude.hpp>
#include "ConnectProtocol.hpp"
#include "Console.hpp"
2017-01-19 16:23:59 -05:00
#include <version.hpp>
2017-01-19 16:23:59 -05:00
namespace Components
{
bool Singleton::FirstInstance = true;
bool Singleton::IsFirstInstance()
{
return FirstInstance;
2017-01-19 16:23:59 -05:00
}
Singleton::Singleton()
{
if (Flags::HasFlag("version"))
{
printf("%s", "IW4x " VERSION " (built " __DATE__ " " __TIME__ ")\n");
2017-01-19 16:23:59 -05:00
printf("%d\n", REVISION);
ExitProcess(EXIT_SUCCESS);
2017-01-19 16:23:59 -05:00
}
Console::FreeNativeConsole();
2022-10-15 16:31:16 -04:00
if (Loader::IsPerformingUnitTests() || Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
2017-01-19 16:23:59 -05:00
FirstInstance = (CreateMutexA(nullptr, FALSE, "iw4x_mutex") && GetLastError() != ERROR_ALREADY_EXISTS);
2017-01-19 16:23:59 -05:00
if (!FirstInstance && !ConnectProtocol::Used() && MessageBoxA(nullptr, "Do you want to start another instance?\nNot all features will be available!", "Game already running", MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
2017-01-19 16:23:59 -05:00
{
ExitProcess(EXIT_SUCCESS);
2017-01-19 16:23:59 -05:00
}
}
}