using System.Globalization;
using Titano.Core.Diagnostics;
using Titano.Core.Localization;
using Titano.Setup.Cli;
using Titano.Setup.Engine;
namespace Titano.Setup;
///
/// Entry point. Silent mode and the uninstaller cleanup helper 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", $"Titano.Setup {typeof(Program).Assembly.GetName().Version} {string.Join(' ', args)}");
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.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);
}
}