using System.Diagnostics; using System.IO.Compression; var arguments = new Dictionary(); if (args.Length % 2 != 0) throw new Exception("An invalid number of arguments were supplied!"); for (int i = 0; i < args.Length; i += 2) { arguments[args[i].TrimStart('-')] = args[i + 1]; } Console.WriteLine("Waiting for LANCommander to stop..."); int delay = 500; int maxAttempts = 30 * (1000 / delay); string processName = Path.GetFileNameWithoutExtension(arguments["Executable"]); for (int i = 0; i < maxAttempts; i++) { var stillRunning = Process.GetProcessesByName(processName).Any(); if (!stillRunning) break; else if (i == maxAttempts - 1) throw new Exception("Cannot update! LANCommander is still running!"); await Task.Delay(delay); } Console.WriteLine("LANCommander has exited! Updating..."); try { var updateFile = Path.Combine(arguments["Path"], arguments["Version"] + ".zip"); if (!File.Exists(updateFile)) throw new ArgumentException("The specified update file does not exist!"); Console.WriteLine($"Update file found for {arguments["Version"]}. Extracting files..."); ZipFile.ExtractToDirectory(updateFile, AppDomain.CurrentDomain.BaseDirectory, true); Console.WriteLine("Extraction complete!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("Starting LANCommander..."); var executable = "LANCommander.exe"; if (arguments.ContainsKey("Executable")) executable = arguments["Executable"]; Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, executable)); Console.WriteLine("LANCommander has been started! My job here is done"); }