From 01fc5606cba1e4fea80613f02331ea58909b4bf9 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 21 Apr 2025 20:50:16 +0200 Subject: [PATCH] add reftag commandline argument --- ModpackUpdater.Apps.Client/Options.cs | 2 ++ ModpackUpdater.Manager/Extensions.cs | 20 ++++++++++++-------- ModpackUpdater.Manager/ModpackInstaller.cs | 5 +++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ModpackUpdater.Apps.Client/Options.cs b/ModpackUpdater.Apps.Client/Options.cs index 74289f7..e8f7076 100644 --- a/ModpackUpdater.Apps.Client/Options.cs +++ b/ModpackUpdater.Apps.Client/Options.cs @@ -11,6 +11,7 @@ internal class Options public bool Help { get; private set; } public bool Silent { get; private set; } public bool NoUi { get; private set; } + public string RefTag { get; private set; } public UpdateCheckOptionsAdv UpdateOptions { get; } = new(); public Options(string[] args) @@ -28,6 +29,7 @@ internal class Options { "m|maintenance", "Ignores the maintenance mode.", m => UpdateOptions.IgnoreMaintenance = true}, { "i|nonpublic", "Include non public (currently hidden) updates.", i => UpdateOptions.IncludeNonPublic = true}, { "k|key=", "An key for retriving extra files on updates.", k => UpdateOptions.ExtrasKey = k}, + { "r|reftag=", "Force uses a specific version, if supported.", r => RefTag = r}, }; additionals.AddRange(options.Parse(args)); diff --git a/ModpackUpdater.Manager/Extensions.cs b/ModpackUpdater.Manager/Extensions.cs index 2c25730..2c7f21b 100644 --- a/ModpackUpdater.Manager/Extensions.cs +++ b/ModpackUpdater.Manager/Extensions.cs @@ -48,17 +48,21 @@ public static class Extensions return @this.SourceUrl.Replace("{version}", version.ToString(3)); } - public static string GetInstallUrl(this ModpackConfig @this) + public static string GetInstallUrl(this ModpackConfig @this, string? overwriteRefTag = null) { - if (string.IsNullOrWhiteSpace(@this.RefTag)) - return @this.InstallUrl; - return @this.InstallUrl.Replace("{ref}", @this.RefTag); + if (!string.IsNullOrWhiteSpace(overwriteRefTag)) + return @this.InstallUrl.Replace("{ref}", overwriteRefTag); + if (!string.IsNullOrWhiteSpace(@this.RefTag)) + return @this.InstallUrl.Replace("{ref}", @this.RefTag); + return @this.InstallUrl; } - public static string GetUpdateUrl(this ModpackConfig @this) + public static string GetUpdateUrl(this ModpackConfig @this, string? overwriteRefTag = null) { - if (string.IsNullOrWhiteSpace(@this.RefTag)) - return @this.UpdateUrl; - return @this.UpdateUrl.Replace("{ref}", @this.RefTag); + if (!string.IsNullOrWhiteSpace(overwriteRefTag)) + return @this.UpdateUrl.Replace("{ref}", overwriteRefTag); + if (!string.IsNullOrWhiteSpace(@this.RefTag)) + return @this.UpdateUrl.Replace("{ref}", @this.RefTag); + return @this.UpdateUrl; } } \ No newline at end of file diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 26c3847..7b3dc6c 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -21,6 +21,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf public delegate void CheckingProgressUpdatedEventHandler(int toCheck, int processed); public ILogger Log { get; set; } = NullLogger.Instance; + public string? OverwriteRefTag { get; set; } private readonly HttpClient http = new(); private readonly ModpackFactory factory = new(); @@ -32,13 +33,13 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf private async Task DownloadUpdateInfos() { - var content = await http.GetStringAsync(updateConfig.GetUpdateUrl()); + var content = await http.GetStringAsync(updateConfig.GetUpdateUrl(overwriteRefTag: OverwriteRefTag)); return UpdateInfos.Parse(content); } private async Task DownloadInstallInfos() { - var content = await http.GetStringAsync(updateConfig.GetInstallUrl()); + var content = await http.GetStringAsync(updateConfig.GetInstallUrl(overwriteRefTag: OverwriteRefTag)); return InstallInfos.Parse(content); }