Files
Triforce-Source/builder/HookshotBuilder/App.xaml.cs
ruckus7382sfgsgdf 34b3683441 Triforce v0.2.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:32:48 -06:00

50 lines
1.8 KiB
C#

using System.IO;
using System.Text;
using System.Windows;
namespace HookshotBuilder;
public partial class App : Application
{
// (RecompLauncher) --cli <make_game.py's options>: no window; its lines on stdout, and its result as the exit code.
// Why it stopped is one "error <text>" line on stdout (the stream a launcher reads) and again on stderr
protected override void OnStartup(StartupEventArgs e)
{
if (e.Args.Length > 0 && e.Args[0] == "--cli")
{
Environment.Exit(Cli(e.Args.Skip(1).ToList()));
return;
}
base.OnStartup(e);
}
static int Cli(List<string> args)
{
using var stdout = new StreamWriter(Console.OpenStandardOutput(), new UTF8Encoding(false)) { AutoFlush = true };
var tools = Tools.Find();
if (tools == null)
{
const string missing = "error The build tools were not found next to this program.";
stdout.WriteLine(missing);
Console.Error.WriteLine(missing);
return 1;
}
var done = new ManualResetEventSlim();
string? failure = null, said = null; // (said: make_game's own "error" line in --prepare mode, already passed on to stdout)
var runner = new Runner(tools, args);
runner.Line += line =>
{
if (line.StartsWith("error ")) said = line[6..];
lock (stdout) stdout.WriteLine(line);
};
runner.Finished += result => { failure = result; done.Set(); };
runner.Start();
done.Wait();
if (failure == null) return 0;
var reason = failure == "cancelled" ? failure : said ?? failure;
if (said == null) lock (stdout) stdout.WriteLine("error " + reason);
Console.Error.WriteLine("error " + reason);
return 1;
}
}