From b11ad06287cc2f93f6c6055318474d4e64e824c9 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 21 Apr 2025 18:39:47 +0200 Subject: [PATCH] add support for version placeholder in download links --- ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs | 8 ++++---- ModpackUpdater.Manager/Extensions.cs | 7 +++++++ ModpackUpdater.Manager/ModpackFactory.cs | 4 ++-- ModpackUpdater.Manager/ModpackInstaller.cs | 4 ++-- ModpackUpdater/ModpackConfig.cs | 7 ------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index 79ed4be..37f3b9b 100644 --- a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs +++ b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs @@ -41,7 +41,7 @@ internal static class SharedFunctions { try { - var result = await factory.ResolveSourceUrl(action); + var result = await factory.ResolveSourceUrl(action, null); failed = string.IsNullOrWhiteSpace(result); } catch (Exception ex) @@ -130,7 +130,7 @@ internal static class SharedFunctions { Task.Run(async () => { - action.SourceUrl = await factory.ResolveSourceUrl(action); + action.SourceUrl = await factory.ResolveSourceUrl(action, null); }).Wait(); } catch (Exception) @@ -239,7 +239,7 @@ internal static class SharedFunctions if (string.IsNullOrWhiteSpace(action.SourceUrl)) sb.Append($"|{action.SourceTag}"); else - sb.Append($"|[{action.SourceTag}]({action.SourceUrl})"); + sb.Append($"|[{action.SourceTag}]({action.GetSourceUrl(installInfos.Version)})"); sb.Append($"|{action.Side.ToString()}"); sb.Append($"|{action.SourceType}"); @@ -283,7 +283,7 @@ internal static class SharedFunctions var cellTag = ws.Cells[cr, cc++]; cellTag.Value = string.IsNullOrWhiteSpace(action.SourceTag)? "direct link" : action.SourceTag; if (!string.IsNullOrWhiteSpace(action.SourceUrl)) - cellTag.SetHyperlink(new Uri(action.SourceUrl)); + cellTag.SetHyperlink(new Uri(action.GetSourceUrl(installInfos.Version))); ws.Cells[cr, cc++].Value = action.Side.ToString(); ws.Cells[cr, cc++].Value = action.SourceType; diff --git a/ModpackUpdater.Manager/Extensions.cs b/ModpackUpdater.Manager/Extensions.cs index 6ea07ef..4b518cd 100644 --- a/ModpackUpdater.Manager/Extensions.cs +++ b/ModpackUpdater.Manager/Extensions.cs @@ -40,4 +40,11 @@ public static class Extensions } } } + + public static string GetSourceUrl(this InstallAction @this, Version version) + { + if (version is null) + return @this.SourceUrl; + return @this.SourceUrl.Replace("{version}", version.ToString(3)); + } } \ No newline at end of file diff --git a/ModpackUpdater.Manager/ModpackFactory.cs b/ModpackUpdater.Manager/ModpackFactory.cs index 03150b2..41d2752 100644 --- a/ModpackUpdater.Manager/ModpackFactory.cs +++ b/ModpackUpdater.Manager/ModpackFactory.cs @@ -24,7 +24,7 @@ public class ModpackFactory modrinth.Dispose(); } - public async Task ResolveSourceUrl(InstallAction action) + public async Task ResolveSourceUrl(InstallAction action, Version? targetVersion) { if (action.SourceType == SourceType.GitHub) { @@ -53,7 +53,7 @@ public class ModpackFactory return file.Url; } - return action.SourceUrl; + return action.GetSourceUrl(targetVersion); } public async Task[]> FindUpdates(InstallAction action, string? gameVersion, ModLoader modLoader) diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 27e8848..bde60c2 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -150,8 +150,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf { var destFilePath = Path.Combine(modpackInfo.LocaLPath, iaction.DestPath); var sourceUrl = updateConfig.PreferDirectLinks && !string.IsNullOrWhiteSpace(iaction.SourceUrl) - ? iaction.SourceUrl - : await factory.ResolveSourceUrl(iaction); + ? iaction.GetSourceUrl(checkResult.LatestVersion) + : await factory.ResolveSourceUrl(iaction, checkResult.LatestVersion); if (iaction is UpdateAction uaction) { diff --git a/ModpackUpdater/ModpackConfig.cs b/ModpackUpdater/ModpackConfig.cs index 43914ec..9d3d30d 100644 --- a/ModpackUpdater/ModpackConfig.cs +++ b/ModpackUpdater/ModpackConfig.cs @@ -6,19 +6,12 @@ namespace ModpackUpdater; public class ModpackConfig { public bool Maintenance { get; set; } - public string Name { get; set; } - public string UpdateUrl { get; set; } - public string InstallUrl { get; set; } - public string UnleashApiUrl { get; set; } - public string UnleashInstanceId { get; set; } - public bool PreferDirectLinks { get; set; } - public string MinecraftVersion { get; set; } [JsonConverter(typeof(StringEnumConverter))]