Skip to content

Commit

Permalink
Exit if duplicate launch detected (#212)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pizzaboxer committed Jul 2, 2023
1 parent 0a7ae17 commit 34b6fef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion Bloxstrap/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 34b6fef

Please sign in to comment.