diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 3e52912..4157034 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -21,6 +21,7 @@ using static OF_DL.Entities.Messages.Messages; using Akka.Configuration; using System.Text; using static Akka.Actor.ProviderSelection; +using System.Diagnostics; namespace OF_DL; @@ -117,6 +118,8 @@ public class Program AnsiConsole.Write(new FigletText("Welcome to OF-DL").Color(Color.Red)); + ExitIfOtherProcess(); + //Remove config.json and convert to config.conf if (File.Exists("config.json")) { @@ -3295,4 +3298,24 @@ public class Program return Enum.Parse("_" + value, ignoreCase: true); } + + static void ExitIfOtherProcess() + { + Assembly entryAssembly = Assembly.GetEntryAssembly(); + AssemblyName entryAssemblyName = entryAssembly?.GetName(); + + if (entryAssemblyName?.Name is null) + return; + + Process thisProcess = Process.GetCurrentProcess(); + Process[] otherProcesses = [.. Process.GetProcessesByName(entryAssemblyName.Name).Where(p => p.Id != thisProcess.Id)]; + + if (otherProcesses.Length <= 0) + return; + + AnsiConsole.Markup($"[green]Other OF DL process detected, exiting..\n[/]"); + Log.Warning("Other OF DL process detected, exiting.."); + + Environment.Exit(0); + } }