add appimage buildscript for linux

This commit is contained in:
theofficialgman
2026-08-25 23:29:46 -04:00
parent e3c4028b50
commit c5db4d0e8e
2 changed files with 174 additions and 13 deletions
+30 -13
View File
@@ -6,8 +6,10 @@ internal static class Program
{
private static async Task<int> Main(string[] args)
{
if (args.Length == 0 || args[0] is "-h" or "--help") { PrintUsage(); return 0; }
if (args[0] == "--version") { Console.WriteLine(ProductInfo.Version); return 0; }
// Checked anywhere in argv, not just args[0]: AppRun (Launcher/build-appimage.sh) prepends
// --workspace <cache> ahead of whatever the caller passed, so these can't assume position 0.
if (args.Length == 0 || args.Contains("-h") || args.Contains("--help")) { PrintUsage(); return 0; }
if (args.Contains("--version")) { Console.WriteLine(ProductInfo.Version); return 0; }
using var cts = new CancellationTokenSource();
// Replaces CancellationSignal.cs's named-EventWaitHandle IPC (Windows-only): SIGINT/SIGTERM
@@ -22,9 +24,11 @@ internal static class Program
private static async Task<int> RunAsync(string[] args, CancellationTokenSource cts)
{
var command = args[0];
var rest = args[1..];
var flags = ParseFlags(rest);
// AppRun (Launcher/build-appimage.sh) invokes this as `wiicompiled-setup --workspace
// <cache> <command> [options]` - a global flag ahead of the subcommand - so the command
// word is whichever token isn't part of a --flag/value pair, not strictly args[0].
var (command, flags) = ParseArgs(args);
if (command is null) { PrintUsage(); return 1; }
var progressJson = flags.ContainsKey("progress-json");
IInstallReporter reporter = progressJson ? new NdjsonInstallReporter() : new ConsoleInstallReporter();
@@ -216,24 +220,37 @@ internal static class Program
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WiiCompiled", "Install",
profile == "base" ? "Base" : "RetroRewind");
private static Dictionary<string, string?> ParseFlags(string[] args)
/// <summary>
/// A single pass that finds both the command word and every --flag[=value] pair, regardless
/// of order - a --flag may appear before or after the command (see the AppRun caller note in
/// RunAsync). The first token that is neither a --flag nor a value already consumed by the
/// preceding --flag is taken as the command.
/// </summary>
private static (string? Command, Dictionary<string, string?> Flags) ParseArgs(string[] args)
{
string? command = null;
var flags = new Dictionary<string, string?>();
for (var i = 0; i < args.Length; i++)
{
var arg = args[i];
if (!arg.StartsWith("--", StringComparison.Ordinal)) continue;
var name = arg[2..];
if (i + 1 < args.Length && !args[i + 1].StartsWith("--", StringComparison.Ordinal))
if (arg.StartsWith("--", StringComparison.Ordinal))
{
flags[name] = args[++i];
var name = arg[2..];
if (i + 1 < args.Length && !args[i + 1].StartsWith("--", StringComparison.Ordinal))
{
flags[name] = args[++i];
}
else
{
flags[name] = null; // boolean flag
}
}
else
else if (command is null)
{
flags[name] = null; // boolean flag
command = arg;
}
}
return flags;
return (command, flags);
}
private static void PrintUsage()