53 lines
1.2 KiB
C++
Raw Normal View History

2022-02-27 12:53:44 +00:00
#include <STDInclude.hpp>
#include "ConnectProtocol.hpp"
#include "Console.hpp"
2017-01-19 22:23:59 +01:00
#include <version.hpp>
2017-01-19 22:23:59 +01:00
namespace Components
{
2023-12-30 12:58:51 +01:00
HANDLE Singleton::Mutex;
2017-01-19 22:23:59 +01:00
bool Singleton::FirstInstance = true;
bool Singleton::IsFirstInstance()
{
return FirstInstance;
2017-01-19 22:23:59 +01:00
}
2023-12-30 12:58:51 +01:00
void Singleton::preDestroy()
{
if (INVALID_HANDLE_VALUE != Mutex)
{
CloseHandle(Mutex);
}
}
2017-01-19 22:23:59 +01:00
Singleton::Singleton()
{
if (Flags::HasFlag("version"))
{
printf("%s", "IW4x " VERSION " (built " __DATE__ " " __TIME__ ")\n");
2023-04-21 11:08:18 +02:00
#ifdef EXPERIMENTAL_BUILD
printf("Revision: %i - develop\n", REVISION);
#else
printf("Revision: %i\n", REVISION);
2023-04-21 11:08:18 +02:00
#endif
ExitProcess(EXIT_SUCCESS);
2017-01-19 22:23:59 +01:00
}
Console::FreeNativeConsole();
2022-10-15 21:31:16 +01:00
if (Loader::IsPerformingUnitTests() || Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
2017-01-19 22:23:59 +01:00
2023-12-30 12:58:51 +01:00
Mutex = CreateMutexA(nullptr, FALSE, "iw4x_mutex");
FirstInstance = ((INVALID_HANDLE_VALUE != Mutex) && GetLastError() != ERROR_ALREADY_EXISTS);
2017-01-19 22:23:59 +01: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 22:23:59 +01:00
{
ExitProcess(EXIT_SUCCESS);
2017-01-19 22:23:59 +01:00
}
}
}