diff --git a/ModpackUpdater.Apps.Client/Form1.cs b/ModpackUpdater.Apps.Client/Form1.cs index 02a8ac9..80ed7bc 100644 --- a/ModpackUpdater.Apps.Client/Form1.cs +++ b/ModpackUpdater.Apps.Client/Form1.cs @@ -146,7 +146,8 @@ public partial class Form1 { var updater = new ModpackInstaller(updateConfig, modpackInfo) { - OverwriteRefTag = Program.Options.RefTag + OverwriteRefTag = Program.Options.RefTag, + OverwriteVersion = Program.Options.Version, }; updater.InstallProgessUpdated += Update_InstallProgessUpdated; updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated; diff --git a/ModpackUpdater.Apps.Client/Options.cs b/ModpackUpdater.Apps.Client/Options.cs index e8f7076..ec4aaf1 100644 --- a/ModpackUpdater.Apps.Client/Options.cs +++ b/ModpackUpdater.Apps.Client/Options.cs @@ -12,6 +12,7 @@ internal class Options public bool Silent { get; private set; } public bool NoUi { get; private set; } public string RefTag { get; private set; } + public string Version { get; private set; } public UpdateCheckOptionsAdv UpdateOptions { get; } = new(); public Options(string[] args) @@ -29,7 +30,8 @@ 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}, + { "r|reftag=", "Force uses a specific reference tag, if supported.", r => RefTag = r}, + { "v|version=", "Force uses a specific version, if supported.", v => Version = v}, }; additionals.AddRange(options.Parse(args)); diff --git a/ModpackUpdater.Apps.Client/Program.cs b/ModpackUpdater.Apps.Client/Program.cs index 8285894..0eb1be5 100644 --- a/ModpackUpdater.Apps.Client/Program.cs +++ b/ModpackUpdater.Apps.Client/Program.cs @@ -106,6 +106,7 @@ public static class Program var installer = new ModpackInstaller(config, info) { OverwriteRefTag = Options.RefTag, + OverwriteVersion = Options.Version, Log = Log, }; var result = installer.Check(updateOptions).Result; diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index 37f3b9b..63166e3 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, null); + var result = await factory.ResolveSourceUrl(action); failed = string.IsNullOrWhiteSpace(result); } catch (Exception ex) @@ -130,7 +130,7 @@ internal static class SharedFunctions { Task.Run(async () => { - action.SourceUrl = await factory.ResolveSourceUrl(action, null); + action.SourceUrl = await factory.ResolveSourceUrl(action); }).Wait(); } catch (Exception) diff --git a/ModpackUpdater.Manager/Extensions.cs b/ModpackUpdater.Manager/Extensions.cs index 2c7f21b..0a0a51a 100644 --- a/ModpackUpdater.Manager/Extensions.cs +++ b/ModpackUpdater.Manager/Extensions.cs @@ -41,11 +41,13 @@ public static class Extensions } } - public static string GetSourceUrl(this InstallAction @this, Version version) + public static string GetSourceUrl(this InstallAction @this, Version version, string? overwriteVersion = null) { - if (version is null) - return @this.SourceUrl; - return @this.SourceUrl.Replace("{version}", version.ToString(3)); + if (!string.IsNullOrWhiteSpace(overwriteVersion)) + return @this.SourceUrl.Replace("{version}", overwriteVersion); + if (version is not null) + return @this.SourceUrl.Replace("{version}", version.ToString(3)); + return @this.SourceUrl; } public static string GetInstallUrl(this ModpackConfig @this, string? overwriteRefTag = null) diff --git a/ModpackUpdater.Manager/ModpackFactory.cs b/ModpackUpdater.Manager/ModpackFactory.cs index 41d2752..31aba32 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, Version? targetVersion) + public async Task ResolveSourceUrl(InstallAction action, Version? targetVersion = null, string? overwriteVersion = null) { if (action.SourceType == SourceType.GitHub) { @@ -53,7 +53,7 @@ public class ModpackFactory return file.Url; } - return action.GetSourceUrl(targetVersion); + return action.GetSourceUrl(targetVersion, overwriteVersion: overwriteVersion); } public async Task[]> FindUpdates(InstallAction action, string? gameVersion, ModLoader modLoader) diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 7b3dc6c..02bdf98 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -22,6 +22,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf public ILogger Log { get; set; } = NullLogger.Instance; public string? OverwriteRefTag { get; set; } + public string? OverwriteVersion { get; set; } private readonly HttpClient http = new(); private readonly ModpackFactory factory = new(); @@ -151,8 +152,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.GetSourceUrl(checkResult.LatestVersion) - : await factory.ResolveSourceUrl(iaction, checkResult.LatestVersion); + ? iaction.GetSourceUrl(checkResult.LatestVersion, overwriteVersion: OverwriteVersion) + : await factory.ResolveSourceUrl(iaction, targetVersion: checkResult.LatestVersion, overwriteVersion: OverwriteVersion); if (iaction is UpdateAction uaction) { @@ -278,6 +279,11 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf if (cachedZipInfo != null) { // Copy content + if (zipPath.StartsWith("{first}")) + { + var firstDirName = Path.GetFileName(Directory.GetDirectories(cachedZipInfo.ExtractedZipPath).First()); + zipPath = zipPath.Replace("{first}", firstDirName); + } var zipSrc = Path.Combine(cachedZipInfo.ExtractedZipPath, zipPath); Extensions.CopyDirectory(zipSrc, destFilePath, true); }