From 34b6fef148943ed388759bd3656e378214f780f0 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sun, 2 Jul 2023 21:50:35 +0100 Subject: [PATCH] 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 --- Bloxstrap/App.xaml.cs | 7 +++++++ Bloxstrap/Logger.cs | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 76d32f27..4e7fb936 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -209,6 +209,13 @@ protected override void OnStartup(StartupEventArgs e) if (!IsFirstRun) { Logger.Initialize(IsUninstall); + + if (!Logger.Initialized) + { + Logger.WriteLine("[App::OnStartup] Possible duplicate launch detected, terminating."); + Terminate(); + } + Settings.Load(); State.Load(); FastFlags.Load(); diff --git a/Bloxstrap/Logger.cs b/Bloxstrap/Logger.cs index f9bcd18a..2b54d928 100644 --- a/Bloxstrap/Logger.cs +++ b/Bloxstrap/Logger.cs @@ -32,10 +32,19 @@ public void Initialize(bool useTempDir = false) 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)