Skip to content

Commit

Permalink
Added nightly option and refactor to use System.CommandLine
Browse files Browse the repository at this point in the history
  • Loading branch information
evilfactory committed Oct 4, 2024
1 parent f0c25d1 commit 6cb160d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
4 changes: 4 additions & 0 deletions Luatrauma.AutoUpdater/Luatrauma.AutoUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
</Project>
53 changes: 25 additions & 28 deletions Luatrauma.AutoUpdater/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Diagnostics;
using System.CommandLine;

namespace Luatrauma.AutoUpdater
{
internal class Program
{
public static string[] Args;

static void Main(string[] args)
{
string tempFolder = Path.Combine(Directory.GetCurrentDirectory(), "Luatrauma.AutoUpdater.Temp");
Expand All @@ -16,40 +15,38 @@ static void Main(string[] args)
Logger.Log("Unhandled exception: " + e.ExceptionObject);
};

Args = args;

Task task = Start();
task.Wait();
}
var rootCommand = new RootCommand("Luatrauma AutoUpdater");

public async static Task Start()
{
List<string> args = new List<string>(Args);
var optionServerOnly = new Option<bool>(name: "--server-only", description: "Downloads only the client patch.");
optionServerOnly.SetDefaultValue(false);
var optionNightly = new Option<bool>(name: "--nightly", description: "Downloads the nightly patch.");
optionNightly.SetDefaultValue(false);
var argumentRun = new Argument<string?>("run", "The path to the Barotrauma executable that should be ran after the update finishes.");
argumentRun.SetDefaultValue(null);

bool serverOnly = false;
rootCommand.AddArgument(argumentRun);
rootCommand.AddOption(optionServerOnly);
rootCommand.AddOption(optionNightly);

int index = args.FindIndex(x => x == "--server-only");
if (index != -1)
rootCommand.SetHandler(async (string? runExe, bool serverOnly, bool nightly) =>
{
args.RemoveAt(index);
serverOnly = true;
}
await Updater.Update(serverOnly);
await Updater.Update(serverOnly);
if (runExe != null)
{
Logger.Log("Starting " + string.Join(" ", runExe));
if (args.Count > 0)
{
Logger.Log("Starting " + string.Join(" ", args));
var info = new ProcessStartInfo
{
FileName = runExe,
WorkingDirectory = Path.GetDirectoryName(runExe)
};
var info = new ProcessStartInfo
{
FileName = args[0],
Arguments = string.Join(" ", args.Skip(1)),
WorkingDirectory = Path.GetDirectoryName(args[0]),
};
Process.Start(info);
}
}, argumentRun, optionServerOnly, optionNightly);

Process.Start(info);
}
rootCommand.Invoke(args);
}
}
}
20 changes: 12 additions & 8 deletions Luatrauma.AutoUpdater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,29 @@ private static void CopyFilesRecursively(string sourcePath, string targetPath)
}
}

public async static Task Update(bool serverOnly = false)
public async static Task Update(bool nightly = false, bool serverOnly = false)
{
Logger.Log("Starting update...");

string patchUrl = null;
string patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/";
if (nightly)
{
patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/nightly/";
}
if (OperatingSystem.IsWindows())
{
if (serverOnly) { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_windows_server.zip"; }
else { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_windows_client.zip"; }
if (serverOnly) { patchUrl += "luacsforbarotrauma_patch_windows_server.zip"; }
else { patchUrl += "luacsforbarotrauma_patch_windows_client.zip"; }
}
else if (OperatingSystem.IsLinux())
{
if (serverOnly) { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_linux_server.zip"; }
else { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_linux_client.zip"; }
if (serverOnly) { patchUrl += "luacsforbarotrauma_patch_linux_server.zip"; }
else { patchUrl += "luacsforbarotrauma_patch_linux_client.zip"; }
}
else if (OperatingSystem.IsMacOS())
{
if (serverOnly) { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_mac_server.zip"; }
else { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_mac_client.zip"; }
if (serverOnly) { patchUrl += "luacsforbarotrauma_patch_mac_server.zip"; }
else { patchUrl += "luacsforbarotrauma_patch_mac_client.zip"; }
}

if (patchUrl == null)
Expand Down

0 comments on commit 6cb160d

Please sign in to comment.