using System.Globalization; using Chronos.Core.Diagnostics; using Chronos.Core.Localization; using Chronos.Setup.Cli; using Chronos.Setup.Engine; namespace Chronos.Setup; /// /// Entry point. Silent mode, the uninstaller cleanup helper and the elevated service step run without WPF; the /// interactive window is the . The return value is the process exit code (). /// internal static class Program { [STAThread] public static int Main(string[] args) { using var log = new FileLogSink(SetupPaths.LogDirectory, "setup"); Log.SetSink(log); Log.Info("setup", $"Chronos.Setup {typeof(Program).Assembly.GetName().Version} {string.Join(' ', args)}"); // The screenshot mode of every Chronos program (CI); it builds its own sample installer. if (args is ["--capture", var captureDirectory]) return Views.SetupCapture.Run(captureDirectory); SetupArguments arguments; try { arguments = SetupArguments.Parse(args); } catch (ArgumentException ex) { Log.Error("setup", ex.Message); return (int)SetupExitCode.InvalidArguments; } ApplyLanguage(arguments.Language); if (arguments.CleanupTarget is { } uninstaller) return (int)SelfCleanup.Run(uninstaller, arguments.WaitProcessId); if (arguments.Services != ServiceActions.None) return (int)InstalledServices.RunStep(arguments); if (arguments.Silent) return (int)SilentSetup.RunAsync(arguments).GetAwaiter().GetResult(); return new App(arguments).Run(); } /// Sets the UI language: the requested code, else the best match for the Windows display language. public static void ApplyLanguage(string? code) { var requested = CultureInfo.CurrentUICulture; if (code is not null) { try { requested = CultureInfo.GetCultureInfo(code); } catch (CultureNotFoundException) { Log.Warning("setup", $"Unknown language '{code}'"); } } var culture = Languages.BestMatch(requested); CultureInfo.DefaultThreadCurrentUICulture = culture; CultureInfo.CurrentUICulture = culture; Loc.SetCulture(culture); } }