using System.IO; using System.Text; using System.Windows; namespace HookshotBuilder; public partial class App : Application { // (RecompLauncher) --cli : no window; its lines on stdout, and its result as the exit code. // Why it stopped is one "error " 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 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; } }