support first placeholder & overwriting version
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ModpackFactory
|
||||
modrinth.Dispose();
|
||||
}
|
||||
|
||||
public async Task<string> ResolveSourceUrl(InstallAction action, Version? targetVersion)
|
||||
public async Task<string> 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<KeyValuePair<string, string>[]> FindUpdates(InstallAction action, string? gameVersion, ModLoader modLoader)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user