using System.Reflection; using Castle.Core.Logging; using ModpackUpdater.Manager; using Pilz.Extensions; namespace ModpackUpdater.Apps.Client; public static class Program { private static readonly ILogger log = new ConsoleLogger(); public static ILogger Log => log; internal static Options Options { get; private set; } = null!; [STAThread] internal static void Main(string[] args) { Options = new Options(args); if (Options.Help) { DrawInfo(); Options.DrawHelp(); return; } if (!Options.Silent) DrawInfo(); InstallWithoutGui(Options.UpdateOptions, Options.Silent); } private static void DrawInfo() { Console.WriteLine("Minecraft Modpack Updater CLI"); Console.WriteLine("Version " + Assembly.GetExecutingAssembly().GetAppVersion().ToShortString()); Console.WriteLine("------------------------------"); } private static void InstallWithoutGui(UpdateCheckOptionsAdv updateOptions, bool silent) { var info = ModpackInfo.TryLoad(updateOptions.ProfileFolder); var config = ModpackConfig.LoadFromUrl(CheckModpackConfigUrl(updateOptions.ModpackConfig!, info)); var features = new ModpackFeatures(config); // Check features if (!string.IsNullOrWhiteSpace(updateOptions.ExtrasKey)) info.ExtrasKey = updateOptions.ExtrasKey; if (!string.IsNullOrWhiteSpace(info.ExtrasKey)) updateOptions.IncludeExtras = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(info)); // Check for update var installer = new ModpackInstaller(config, info) { OverwriteRefTag = Options.RefTag, OverwriteVersion = Options.Version, Log = Log, }; var result = installer.Check(updateOptions).Result; if (result.HasUpdates) { var success = installer.Install(result).Result; if (!silent) Log.Info($"Installation {(success ?? false ? "completed successfully" : "failed")}!"); } else if (!silent) Log.Info("No updates available"); } private static string CheckModpackConfigUrl(string configUrl, ModpackInfo info) { if (string.IsNullOrWhiteSpace(configUrl) && !string.IsNullOrWhiteSpace(info.ConfigUrl)) return info.ConfigUrl; return configUrl; } }