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

33 lines
887 B
C++
Raw Normal View History

2017-01-19 16:23:59 -05:00
#include "STDInclude.hpp"
namespace Components
{
bool Singleton::FirstInstance = true;
bool Singleton::IsFirstInstance()
{
return Singleton::FirstInstance;
}
Singleton::Singleton()
{
if (Flags::HasFlag("version"))
{
printf("IW4x " VERSION " (built " __DATE__ " " __TIME__ ")\n");
printf("%d\n", REVISION);
ExitProcess(0);
}
Console::FreeNativeConsole();
2017-07-03 09:40:32 -04:00
if (Loader::IsPerformingUnitTests() || Dedicated::IsEnabled() || ZoneBuilder::IsEnabled() || Monitor::IsEnabled()) return;
2017-01-19 16:23:59 -05:00
Singleton::FirstInstance = (CreateMutexA(nullptr, FALSE, "iw4x_mutex") && GetLastError() != ERROR_ALREADY_EXISTS);
2017-01-19 16:23:59 -05:00
2017-02-18 15:14:42 -05:00
if (!Singleton::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(0);
}
}
}