diff --git a/ModpackUpdater.Manager/Extensions.cs b/ModpackUpdater.Manager/Extensions.cs index 3c6c9f8..6b4b7d3 100644 --- a/ModpackUpdater.Manager/Extensions.cs +++ b/ModpackUpdater.Manager/Extensions.cs @@ -1,8 +1,15 @@ -namespace ModpackUpdater.Manager; +using ModpackUpdater.Model; + +namespace ModpackUpdater.Manager; public static class Extensions { + public static bool IsSide(this Side @this, Side side) + { + return @this.HasFlag(side) || side.HasFlag(@this); + } + public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive) { diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 3b74731..bb9332b 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -37,32 +37,38 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath) return InstallInfos.Parse(content); } - public Task Check() - { - return Check(Side.Client, true); - } - - public async Task Check(Side side, bool allowUpdaterAfterInstall) + public async Task Check(UpdateCheckOptions options) { var result = new UpdateCheckResult(); var hasConfig = ModpackInfo.HasModpackInfo(localPath); InstallInfos installInfos = null; UpdateInfos updateInfos = null; + if (updateConfig.Maintenance && !options.IgnoreMaintenance) + { + result.IsInMaintenance = true; + return result; + } + if (!hasConfig) { installInfos = await DownloadInstallInfos(); if (installInfos is not null && installInfos.Actions.Count != 0) { - result.Actions.AddRange(installInfos.Actions); - result.LatestVersion = installInfos.Version; + var actions = installInfos.Actions.Where(n => n.Side.IsSide(options.Side)); + if (actions.Any()) + { + result.Actions.AddRange(installInfos.Actions); + result.LatestVersion = installInfos.Version; + } } - else + + if (result.Actions.Count == 0) result.HasError = true; } - if (allowUpdaterAfterInstall) + if (options.AllowUpdaterAfterInstall) { updateInfos = await DownloadUpdateInfos(); var modpackInfo = ModpackInfo.HasModpackInfo(localPath) ? ModpackInfo.Load(localPath) : new(); @@ -83,7 +89,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath) foreach (var action in checkingVersion.Actions) { - if (!result.Actions.Any(n => n.DestPath == action.DestPath)) + if (action.Side.IsSide(options.Side) && !result.Actions.Any(n => n.DestPath == action.DestPath)) actionsToAdd.Add(action); } diff --git a/ModpackUpdater.Manager/UpdateCheckOptions.cs b/ModpackUpdater.Manager/UpdateCheckOptions.cs new file mode 100644 index 0000000..bf28bbd --- /dev/null +++ b/ModpackUpdater.Manager/UpdateCheckOptions.cs @@ -0,0 +1,10 @@ +using ModpackUpdater.Model; + +namespace ModpackUpdater.Manager; + +public class UpdateCheckOptions +{ + public bool IgnoreMaintenance { get; set; } + public bool AllowUpdaterAfterInstall { get; set; } = true; + public Side Side { get; set; } = Side.Client; +} diff --git a/ModpackUpdater.Manager/UpdateCheckResult.cs b/ModpackUpdater.Manager/UpdateCheckResult.cs index 77c8335..658f208 100644 --- a/ModpackUpdater.Manager/UpdateCheckResult.cs +++ b/ModpackUpdater.Manager/UpdateCheckResult.cs @@ -9,5 +9,6 @@ public class UpdateCheckResult public List Actions { get; private set; } = []; public bool IsInstalled { get; set; } public bool HasError { get; set; } + public bool IsInMaintenance { get; set; } public bool HasUpdates => !IsInstalled || CurrentVersion < LatestVersion; } \ No newline at end of file diff --git a/ModpackUpdater.Model/ModpackConfig.cs b/ModpackUpdater.Model/ModpackConfig.cs index afaffd2..3e7bdfa 100644 --- a/ModpackUpdater.Model/ModpackConfig.cs +++ b/ModpackUpdater.Model/ModpackConfig.cs @@ -4,6 +4,7 @@ namespace ModpackUpdater.Model; public class ModpackConfig { + public bool Maintenance { get; set; } public string Name { get; set; } public string UpdateUrl { get; set; } public string InstallUrl { get; set; } diff --git a/ModpackUpdater/Form1.cs b/ModpackUpdater/Form1.cs index 178617e..73b498a 100644 --- a/ModpackUpdater/Form1.cs +++ b/ModpackUpdater/Form1.cs @@ -12,20 +12,17 @@ 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; + private readonly UpdateCheckOptionsAdv updateOptions; - public Form1(string modpackConfig, string profilePath, Side side, bool allowUpdaterAfterInstall, bool allowUpdateCheck) : this() + public Form1(UpdateCheckOptionsAdv updateOptions) : this() { - this.allowUpdaterAfterInstall = allowUpdaterAfterInstall; - this.side = side; + this.updateOptions = updateOptions; - if (!string.IsNullOrWhiteSpace(modpackConfig)) - LoadUpdateConfigFile(modpackConfig); + if (!string.IsNullOrWhiteSpace(updateOptions.ModpackConfig)) + LoadUpdateConfigFile(updateOptions.ModpackConfig); - if (!string.IsNullOrWhiteSpace(profilePath)) - LoadMinecraftProfile(profilePath); + if (!string.IsNullOrWhiteSpace(updateOptions.ProfileFolder)) + LoadMinecraftProfile(updateOptions.ProfileFolder); } public Form1() @@ -129,7 +126,7 @@ public partial class Form1 try { - lastUpdateCheckResult = await updater.Check(side, allowUpdaterAfterInstall); + lastUpdateCheckResult = await updater.Check(updateOptions); } catch { @@ -245,7 +242,7 @@ public partial class Form1 private async void Form1_Shown(object sender, EventArgs e) { var updater = new AppUpdater(); - if (allowUpdateCheck && await updater.Check() && RadMessageBox.Show(LangRes.MsgBox_UpdateAvailable, LangRes.MsgBox_UpdateAvailable_Title, MessageBoxButtons.YesNo, RadMessageIcon.Info) == DialogResult.Yes) + if (!updateOptions.NoUpdate && 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 e462f26..e4c4fac 100644 --- a/ModpackUpdater/Options.cs +++ b/ModpackUpdater/Options.cs @@ -10,11 +10,7 @@ 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; } + public UpdateCheckOptionsAdv UpdateOptions { get; } = new(); public Options(string[] args) { @@ -22,13 +18,14 @@ internal class Options { { "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}, + { "p|profile=", "Sets the minecraft profile folder.", p => UpdateOptions.ProfileFolder = p }, + { "c|config=", "Sets the minecraft profile folder.", c => UpdateOptions.ModpackConfig = c }, + { "s|side=", "Sets the minecraft profile folder.\nDefault side is Client.\nAvailable: Client, Server", s => UpdateOptions.Side = Enum.Parse(s)}, + { "uai", "Allow an update directly after install. This only has affect if there is no existing installation.", uai => UpdateOptions.AllowUpdaterAfterInstall = uai != null}, + { "noupdate", "Skip the update check.", noupdate => UpdateOptions.NoUpdate = noupdate != null}, + { "m|maintenance", "Ignores the maintenance mode.", m => UpdateOptions.IgnoreMaintenance = m != null}, }; - var additional = options.Parse(args); + additionals.AddRange(options.Parse(args)); } } diff --git a/ModpackUpdater/Program.cs b/ModpackUpdater/Program.cs index a8e4456..7e0c00b 100644 --- a/ModpackUpdater/Program.cs +++ b/ModpackUpdater/Program.cs @@ -1,6 +1,5 @@ using ModpackUpdater.Manager; using ModpackUpdater.Model; -using Mono.Options; using Newtonsoft.Json; using Pilz.Configuration; using Telerik.WinControls; @@ -24,12 +23,12 @@ public static class Program { var options = new Options(args); if (options.NoUi) - InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent, options.Side, options.AllowUpdaterAfterInstall); + InstallWithoutGui(options.UpdateOptions, options.Silent); else - RunApp(options.ModpackConfig, options.ProfileFolder, options.Side, options.AllowUpdaterAfterInstall, !options.NoUpdate); + RunApp(options.UpdateOptions); } - private static void RunApp(string modpackConfig, string profileFolder, Side side, bool allowUpdaterAfterInstall, bool allowUpdateCheck) + private static void RunApp(UpdateCheckOptionsAdv updateOptions) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -38,7 +37,7 @@ public static class Program if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp")) ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple"; - Application.Run(new Form1(modpackConfig, profileFolder, side, allowUpdaterAfterInstall, allowUpdateCheck)); + Application.Run(new Form1(updateOptions)); } private static string GetSettingsPath(int? settingsVersion = 2) @@ -72,11 +71,14 @@ public static class Program File.Delete(settingsPath); } - private static void InstallWithoutGui(string modpackConfig, string profileFolder, bool silent, Side side, bool allowUpdaterAfterInstall) + private static void InstallWithoutGui(UpdateCheckOptionsAdv updateOptions, bool silent) { - var config = ModpackConfig.LoadFromUrl(modpackConfig); - var installer = new ModpackInstaller(config, profileFolder); - var result = installer.Check(side, allowUpdaterAfterInstall).Result; + var config = ModpackConfig.LoadFromUrl(updateOptions.ModpackConfig); + var installer = new ModpackInstaller(config, updateOptions.ProfileFolder); + var result = installer.Check(updateOptions).Result; + + if (!silent && !updateOptions.NoUpdate && new AppUpdater().Check().Result) + Console.WriteLine("A new version is available!"); if (result.HasUpdates) { diff --git a/ModpackUpdater/UpdateCheckOptionsAdv.cs b/ModpackUpdater/UpdateCheckOptionsAdv.cs new file mode 100644 index 0000000..cbe6b61 --- /dev/null +++ b/ModpackUpdater/UpdateCheckOptionsAdv.cs @@ -0,0 +1,10 @@ +using ModpackUpdater.Manager; + +namespace ModpackUpdater; + +public class UpdateCheckOptionsAdv : UpdateCheckOptions +{ + public string ProfileFolder { get; set; } + public string ModpackConfig { get; set; } + public bool NoUpdate { get; set; } +}