forked from sim0n00ps/OF-DL
		
	Added exiting if other process is detected, to avoid overlapping runs
This commit is contained in:
		
							parent
							
								
									788dbcc2c6
								
							
						
					
					
						commit
						3d2a5fd282
					
				| @ -22,6 +22,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; | ||||
| 
 | ||||
| @ -118,6 +119,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")) | ||||
|             { | ||||
| @ -3256,4 +3259,24 @@ public class Program | ||||
| 
 | ||||
|         return Enum.Parse<VideoResolution>("_" + 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); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user