Exit if duplicate launch detected (#212)

amendment to the fix for that issue - the prior fix was to just allow two instances to launch

that probably isn't great for the user, so it's better to just terminate if it detects a duplicate launch, and that only happens if two launches happen within the same second so lol
This commit is contained in:
pizzaboxer 2023-07-02 21:50:35 +01:00
parent 0a7ae17473
commit 34b6fef148
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
2 changed files with 17 additions and 1 deletions

View File

@ -209,6 +209,13 @@ namespace Bloxstrap
if (!IsFirstRun)
{
Logger.Initialize(IsUninstall);
if (!Logger.Initialized)
{
Logger.WriteLine("[App::OnStartup] Possible duplicate launch detected, terminating.");
Terminate();
}
Settings.Load();
State.Load();
FastFlags.Load();

View File

@ -32,10 +32,19 @@ namespace Bloxstrap
WriteLine($"[Logger::Initialize] Initializing at {location}");
if (Initialized)
throw new Exception("Logger is already initialized");
{
WriteLine("[Logger::Initialize] Failed to initialize because logger is already initialized");
return;
}
Directory.CreateDirectory(directory);
if (File.Exists(location))
{
WriteLine("[Logger::Initialize] Failed to initialize because log file already exists");
return;
}
_filestream = File.Open(location, FileMode.Create, FileAccess.Write, FileShare.Read);
if (Backlog.Count > 0)