This commit is contained in:
2024-06-20 06:30:24 +02:00
parent 00de4d8708
commit c31cc3aa20
6 changed files with 43 additions and 12 deletions

View File

@@ -37,7 +37,12 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
return InstallInfos.Parse(content); return InstallInfos.Parse(content);
} }
public async Task<UpdateCheckResult> Check(bool allowUpdaterAfterInstall = true) public Task<UpdateCheckResult> Check()
{
return Check(Side.Client, true);
}
public async Task<UpdateCheckResult> Check(Side side, bool allowUpdaterAfterInstall)
{ {
var result = new UpdateCheckResult(); var result = new UpdateCheckResult();
var hasConfig = ModpackInfo.HasModpackInfo(localPath); var hasConfig = ModpackInfo.HasModpackInfo(localPath);

View File

@@ -6,4 +6,5 @@ public class InstallAction
public string ZipPath { get; set; } public string ZipPath { get; set; }
public string DestPath { get; set; } public string DestPath { get; set; }
public string DownloadUrl { get; set; } public string DownloadUrl { get; set; }
public Side Side { get; set; } = Side.Both;
} }

View File

@@ -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,
}

View File

@@ -12,9 +12,15 @@ public partial class Form1
private ModpackConfig updateConfig = new(); private ModpackConfig updateConfig = new();
private bool currentUpdating = false; private bool currentUpdating = false;
private UpdateCheckResult lastUpdateCheckResult = null; 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)) if (!string.IsNullOrWhiteSpace(modpackConfig))
LoadUpdateConfigFile(modpackConfig); LoadUpdateConfigFile(modpackConfig);
@@ -123,7 +129,7 @@ public partial class Form1
try try
{ {
lastUpdateCheckResult = await updater.Check(); lastUpdateCheckResult = await updater.Check(side, allowUpdaterAfterInstall);
} }
catch catch
{ {
@@ -239,7 +245,7 @@ public partial class Form1
private async void Form1_Shown(object sender, EventArgs e) private async void Form1_Shown(object sender, EventArgs e)
{ {
var updater = new AppUpdater(); 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); SetStatus(LangRes.StatusText_InstallingAppUpdate, MySymbols.icons8_software_installer_16px);
Enabled = false; Enabled = false;

View File

@@ -1,4 +1,5 @@
using Mono.Options; using ModpackUpdater.Model;
using Mono.Options;
namespace ModpackUpdater; namespace ModpackUpdater;
@@ -9,6 +10,9 @@ internal class Options
public IReadOnlyList<string> Additionals => additionals; public IReadOnlyList<string> Additionals => additionals;
public bool Silent { get; private set; } public bool Silent { get; private set; }
public bool NoUi { 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 ProfileFolder { get; private set; }
public string ModpackConfig { get; private set; } public string ModpackConfig { get; private set; }
@@ -16,10 +20,13 @@ internal class Options
{ {
var options = new OptionSet 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 }, { "n|noui", "Install without user interface.", n => NoUi = n != null },
{ "p|profile=", "Sets the minecraft profile folder.", p => ProfileFolder = p }, { "p|profile=", "Sets the minecraft profile folder.", p => ProfileFolder = p },
{ "c|config=", "Sets the minecraft profile folder.", c => ModpackConfig = c }, { "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<Side>(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); var additional = options.Parse(args);

View File

@@ -24,12 +24,12 @@ public static class Program
{ {
var options = new Options(args); var options = new Options(args);
if (options.NoUi) if (options.NoUi)
InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent); InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent, options.Side, options.AllowUpdaterAfterInstall);
else 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.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
@@ -38,7 +38,7 @@ public static class Program
if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp")) if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp"))
ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple"; 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) private static string GetSettingsPath(int? settingsVersion = 2)
@@ -72,11 +72,11 @@ public static class Program
File.Delete(settingsPath); 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 config = ModpackConfig.LoadFromUrl(modpackConfig);
var installer = new ModpackInstaller(config, profileFolder); var installer = new ModpackInstaller(config, profileFolder);
var result = installer.Check().Result; var result = installer.Check(side, allowUpdaterAfterInstall).Result;
if (result.HasUpdates) if (result.HasUpdates)
{ {