Some checks failed
LANCommander Release / build_server_linux-arm64 (push) Has been cancelled
LANCommander Release / build_server_linux-x64 (push) Has been cancelled
LANCommander Release / build_server_osx-arm64 (push) Has been cancelled
LANCommander Release / build_server_win-arm64 (push) Has been cancelled
LANCommander Release / build_server_win-x64 (push) Has been cancelled
LANCommander Release / build_launcher_linux-arm64 (push) Has been cancelled
LANCommander Release / build_launcher_linux-x64 (push) Has been cancelled
LANCommander Release / build_launcher_osx-arm64 (push) Has been cancelled
LANCommander Release / build_launcher_win-arm64 (push) Has been cancelled
LANCommander Release / build_launcher_win-x64 (push) Has been cancelled
LANCommander Release / build_release (push) Has been cancelled
64 lines
No EOL
1.7 KiB
C#
64 lines
No EOL
1.7 KiB
C#
using System.Diagnostics;
|
|
using System.IO.Compression;
|
|
|
|
var arguments = new Dictionary<string, string>();
|
|
|
|
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");
|
|
} |