diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 7fbf338..3b74731 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -37,7 +37,12 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath) return InstallInfos.Parse(content); } - public async Task Check(bool allowUpdaterAfterInstall = true) + public Task Check() + { + return Check(Side.Client, true); + } + + public async Task Check(Side side, bool allowUpdaterAfterInstall) { var result = new UpdateCheckResult(); var hasConfig = ModpackInfo.HasModpackInfo(localPath); diff --git a/ModpackUpdater.Model/InstallAction.cs b/ModpackUpdater.Model/InstallAction.cs index b7e3283..7ec563f 100644 --- a/ModpackUpdater.Model/InstallAction.cs +++ b/ModpackUpdater.Model/InstallAction.cs @@ -6,4 +6,5 @@ public class InstallAction public string ZipPath { get; set; } public string DestPath { get; set; } public string DownloadUrl { get; set; } + public Side Side { get; set; } = Side.Both; } \ No newline at end of file diff --git a/ModpackUpdater.Model/Side.cs b/ModpackUpdater.Model/Side.cs new file mode 100644 index 0000000..55cbd6b --- /dev/null +++ b/ModpackUpdater.Model/Side.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace ModpackUpdater.Model; + +[JsonConverter(typeof(StringEnumConverter)), Flags] +public enum Side +{ + Client = 1, + Server = 2, + Both = Client | Server, +} diff --git a/ModpackUpdater/Form1.cs b/ModpackUpdater/Form1.cs index ded2573..178617e 100644 --- a/ModpackUpdater/Form1.cs +++ b/ModpackUpdater/Form1.cs @@ -12,9 +12,15 @@ public partial class Form1 private ModpackConfig updateConfig = new(); private bool currentUpdating = false; private UpdateCheckResult lastUpdateCheckResult = null; + private readonly bool allowUpdateCheck; + private readonly bool allowUpdaterAfterInstall; + private readonly Side side; - public Form1(string modpackConfig, string profilePath) : this() + public Form1(string modpackConfig, string profilePath, Side side, bool allowUpdaterAfterInstall, bool allowUpdateCheck) : this() { + this.allowUpdaterAfterInstall = allowUpdaterAfterInstall; + this.side = side; + if (!string.IsNullOrWhiteSpace(modpackConfig)) LoadUpdateConfigFile(modpackConfig); @@ -123,7 +129,7 @@ public partial class Form1 try { - lastUpdateCheckResult = await updater.Check(); + lastUpdateCheckResult = await updater.Check(side, allowUpdaterAfterInstall); } catch { @@ -239,7 +245,7 @@ public partial class Form1 private async void Form1_Shown(object sender, EventArgs e) { var updater = new AppUpdater(); - if (await updater.Check() && RadMessageBox.Show(LangRes.MsgBox_UpdateAvailable, LangRes.MsgBox_UpdateAvailable_Title, MessageBoxButtons.YesNo, RadMessageIcon.Info) == DialogResult.Yes) + if (allowUpdateCheck && await updater.Check() && RadMessageBox.Show(LangRes.MsgBox_UpdateAvailable, LangRes.MsgBox_UpdateAvailable_Title, MessageBoxButtons.YesNo, RadMessageIcon.Info) == DialogResult.Yes) { SetStatus(LangRes.StatusText_InstallingAppUpdate, MySymbols.icons8_software_installer_16px); Enabled = false; diff --git a/ModpackUpdater/Options.cs b/ModpackUpdater/Options.cs index 348e4fa..e462f26 100644 --- a/ModpackUpdater/Options.cs +++ b/ModpackUpdater/Options.cs @@ -1,4 +1,5 @@ -using Mono.Options; +using ModpackUpdater.Model; +using Mono.Options; namespace ModpackUpdater; @@ -9,6 +10,9 @@ internal class Options public IReadOnlyList Additionals => additionals; public bool Silent { get; private set; } public bool NoUi { get; private set; } + public bool NoUpdate { get; private set; }; + public bool AllowUpdaterAfterInstall { get; private set; } = true; + public Side Side { get; private set; } = Side.Client; public string ProfileFolder { get; private set; } public string ModpackConfig { get; private set; } @@ -16,10 +20,13 @@ internal class Options { var options = new OptionSet { - { "s|silent", "Do not output anything.", s => Silent = s != null }, + { "silent", "Do not output anything.", s => Silent = s != null }, { "n|noui", "Install without user interface.", n => NoUi = n != null }, { "p|profile=", "Sets the minecraft profile folder.", p => ProfileFolder = p }, { "c|config=", "Sets the minecraft profile folder.", c => ModpackConfig = c }, + { "s|side=", "Sets the minecraft profile folder.\nDefault side is Client.\nAvailable: Client, Server", s => Side = Enum.Parse(s)}, + { "uai", "Allow an update directly after install. This only has affect if there is no existing installation.", uai => AllowUpdaterAfterInstall = uai != null}, + { "noupdate", "Skip the update check wich happens when opening the user interface.", noupdate => NoUpdate = noupdate != null}, }; var additional = options.Parse(args); diff --git a/ModpackUpdater/Program.cs b/ModpackUpdater/Program.cs index 567d549..a8e4456 100644 --- a/ModpackUpdater/Program.cs +++ b/ModpackUpdater/Program.cs @@ -24,12 +24,12 @@ public static class Program { var options = new Options(args); if (options.NoUi) - InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent); + InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent, options.Side, options.AllowUpdaterAfterInstall); else - RunApp(options.ModpackConfig, options.ProfileFolder); + RunApp(options.ModpackConfig, options.ProfileFolder, options.Side, options.AllowUpdaterAfterInstall, !options.NoUpdate); } - private static void RunApp(string modpackConfig, string profileFolder) + private static void RunApp(string modpackConfig, string profileFolder, Side side, bool allowUpdaterAfterInstall, bool allowUpdateCheck) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -38,7 +38,7 @@ public static class Program if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp")) ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple"; - Application.Run(new Form1(modpackConfig, profileFolder)); + Application.Run(new Form1(modpackConfig, profileFolder, side, allowUpdaterAfterInstall, allowUpdateCheck)); } private static string GetSettingsPath(int? settingsVersion = 2) @@ -72,11 +72,11 @@ public static class Program File.Delete(settingsPath); } - private static void InstallWithoutGui(string modpackConfig, string profileFolder, bool silent) + private static void InstallWithoutGui(string modpackConfig, string profileFolder, bool silent, Side side, bool allowUpdaterAfterInstall) { var config = ModpackConfig.LoadFromUrl(modpackConfig); var installer = new ModpackInstaller(config, profileFolder); - var result = installer.Check().Result; + var result = installer.Check(side, allowUpdaterAfterInstall).Result; if (result.HasUpdates) {