support first placeholder & overwriting version
This commit is contained in:
@@ -146,7 +146,8 @@ public partial class Form1
|
|||||||
{
|
{
|
||||||
var updater = new ModpackInstaller(updateConfig, modpackInfo)
|
var updater = new ModpackInstaller(updateConfig, modpackInfo)
|
||||||
{
|
{
|
||||||
OverwriteRefTag = Program.Options.RefTag
|
OverwriteRefTag = Program.Options.RefTag,
|
||||||
|
OverwriteVersion = Program.Options.Version,
|
||||||
};
|
};
|
||||||
updater.InstallProgessUpdated += Update_InstallProgessUpdated;
|
updater.InstallProgessUpdated += Update_InstallProgessUpdated;
|
||||||
updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated;
|
updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ internal class Options
|
|||||||
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 string RefTag { get; private set; }
|
public string RefTag { get; private set; }
|
||||||
|
public string Version { get; private set; }
|
||||||
public UpdateCheckOptionsAdv UpdateOptions { get; } = new();
|
public UpdateCheckOptionsAdv UpdateOptions { get; } = new();
|
||||||
|
|
||||||
public Options(string[] args)
|
public Options(string[] args)
|
||||||
@@ -29,7 +30,8 @@ internal class Options
|
|||||||
{ "m|maintenance", "Ignores the maintenance mode.", m => UpdateOptions.IgnoreMaintenance = true},
|
{ "m|maintenance", "Ignores the maintenance mode.", m => UpdateOptions.IgnoreMaintenance = true},
|
||||||
{ "i|nonpublic", "Include non public (currently hidden) updates.", i => UpdateOptions.IncludeNonPublic = 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},
|
{ "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));
|
additionals.AddRange(options.Parse(args));
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public static class Program
|
|||||||
var installer = new ModpackInstaller(config, info)
|
var installer = new ModpackInstaller(config, info)
|
||||||
{
|
{
|
||||||
OverwriteRefTag = Options.RefTag,
|
OverwriteRefTag = Options.RefTag,
|
||||||
|
OverwriteVersion = Options.Version,
|
||||||
Log = Log,
|
Log = Log,
|
||||||
};
|
};
|
||||||
var result = installer.Check(updateOptions).Result;
|
var result = installer.Check(updateOptions).Result;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ internal static class SharedFunctions
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await factory.ResolveSourceUrl(action, null);
|
var result = await factory.ResolveSourceUrl(action);
|
||||||
failed = string.IsNullOrWhiteSpace(result);
|
failed = string.IsNullOrWhiteSpace(result);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -130,7 +130,7 @@ internal static class SharedFunctions
|
|||||||
{
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
action.SourceUrl = await factory.ResolveSourceUrl(action, null);
|
action.SourceUrl = await factory.ResolveSourceUrl(action);
|
||||||
}).Wait();
|
}).Wait();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
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)
|
if (!string.IsNullOrWhiteSpace(overwriteVersion))
|
||||||
return @this.SourceUrl;
|
return @this.SourceUrl.Replace("{version}", overwriteVersion);
|
||||||
return @this.SourceUrl.Replace("{version}", version.ToString(3));
|
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)
|
public static string GetInstallUrl(this ModpackConfig @this, string? overwriteRefTag = null)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class ModpackFactory
|
|||||||
modrinth.Dispose();
|
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)
|
if (action.SourceType == SourceType.GitHub)
|
||||||
{
|
{
|
||||||
@@ -53,7 +53,7 @@ public class ModpackFactory
|
|||||||
return file.Url;
|
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)
|
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 ILogger Log { get; set; } = NullLogger.Instance;
|
||||||
public string? OverwriteRefTag { get; set; }
|
public string? OverwriteRefTag { get; set; }
|
||||||
|
public string? OverwriteVersion { get; set; }
|
||||||
|
|
||||||
private readonly HttpClient http = new();
|
private readonly HttpClient http = new();
|
||||||
private readonly ModpackFactory factory = 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 destFilePath = Path.Combine(modpackInfo.LocaLPath, iaction.DestPath);
|
||||||
var sourceUrl = updateConfig.PreferDirectLinks && !string.IsNullOrWhiteSpace(iaction.SourceUrl)
|
var sourceUrl = updateConfig.PreferDirectLinks && !string.IsNullOrWhiteSpace(iaction.SourceUrl)
|
||||||
? iaction.GetSourceUrl(checkResult.LatestVersion)
|
? iaction.GetSourceUrl(checkResult.LatestVersion, overwriteVersion: OverwriteVersion)
|
||||||
: await factory.ResolveSourceUrl(iaction, checkResult.LatestVersion);
|
: await factory.ResolveSourceUrl(iaction, targetVersion: checkResult.LatestVersion, overwriteVersion: OverwriteVersion);
|
||||||
|
|
||||||
if (iaction is UpdateAction uaction)
|
if (iaction is UpdateAction uaction)
|
||||||
{
|
{
|
||||||
@@ -278,6 +279,11 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
if (cachedZipInfo != null)
|
if (cachedZipInfo != null)
|
||||||
{
|
{
|
||||||
// Copy content
|
// 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);
|
var zipSrc = Path.Combine(cachedZipInfo.ExtractedZipPath, zipPath);
|
||||||
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user