using ModpackUpdater.Manager; using ModpackUpdater.Model; using Mono.Options; using Newtonsoft.Json; using Pilz.Configuration; using Telerik.WinControls; namespace ModpackUpdater; public static class Program { private static readonly SettingsManager settingsManager; public static ISettings Settings => settingsManager.Instance; static Program() { settingsManager = new(GetSettingsPath(2), true); MigrateLegacySettings(GetSettingsPath(null)); } [STAThread] internal static void Main(string[] args) { var options = new Options(args); if (options.NoUi) InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent); else RunApp(options.ModpackConfig, options.ProfileFolder); } private static void RunApp(string modpackConfig, string profileFolder) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp")) ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple"; Application.Run(new Form1(modpackConfig, profileFolder)); } private static string GetSettingsPath(int? settingsVersion = 2) { const string AppDataDirectoryName = "MinecraftModpackUpdater"; var fileNamePostfix = settingsVersion == null ? string.Empty : $"V{settingsVersion}"; var SettingsFileName = $"Settings{fileNamePostfix}.json"; var settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppDataDirectoryName); Directory.CreateDirectory(settingsPath); settingsPath = Path.Combine(settingsPath, SettingsFileName); return settingsPath; } private static void MigrateLegacySettings(string settingsPath) { // Try load legacy config file if (!File.Exists(settingsPath) || JsonConvert.DeserializeObject(File.ReadAllText(settingsPath)) is not AppConfig legacyConfig) return; // Migrate var newConfig = Settings.Get(); newConfig.LastMinecraftProfilePath = legacyConfig.LastMinecraftProfilePath; newConfig.LastConfigFilePath = legacyConfig.LastConfigFilePath; // Ensure save settings settingsManager.Save(); // Delete legacy config file File.Delete(settingsPath); } private static void InstallWithoutGui(string modpackConfig, string profileFolder, bool silent) { var config = ModpackConfig.LoadFromUrl(modpackConfig); var installer = new ModpackInstaller(config, profileFolder); var result = installer.Check().Result; if (result.HasUpdates) { var success = installer.Install(result).Result; if (!silent) Console.WriteLine($"Installation {(success ?? false ? "completed successfully" : "failed")}!"); } else if (!silent) Console.WriteLine("No updates available"); } }