add support for version placeholder in download links
This commit is contained in:
@@ -41,7 +41,7 @@ internal static class SharedFunctions
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await factory.ResolveSourceUrl(action);
|
var result = await factory.ResolveSourceUrl(action, null);
|
||||||
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);
|
action.SourceUrl = await factory.ResolveSourceUrl(action, null);
|
||||||
}).Wait();
|
}).Wait();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -239,7 +239,7 @@ internal static class SharedFunctions
|
|||||||
if (string.IsNullOrWhiteSpace(action.SourceUrl))
|
if (string.IsNullOrWhiteSpace(action.SourceUrl))
|
||||||
sb.Append($"|{action.SourceTag}");
|
sb.Append($"|{action.SourceTag}");
|
||||||
else
|
else
|
||||||
sb.Append($"|[{action.SourceTag}]({action.SourceUrl})");
|
sb.Append($"|[{action.SourceTag}]({action.GetSourceUrl(installInfos.Version)})");
|
||||||
|
|
||||||
sb.Append($"|{action.Side.ToString()}");
|
sb.Append($"|{action.Side.ToString()}");
|
||||||
sb.Append($"|{action.SourceType}");
|
sb.Append($"|{action.SourceType}");
|
||||||
@@ -283,7 +283,7 @@ internal static class SharedFunctions
|
|||||||
var cellTag = ws.Cells[cr, cc++];
|
var cellTag = ws.Cells[cr, cc++];
|
||||||
cellTag.Value = string.IsNullOrWhiteSpace(action.SourceTag)? "direct link" : action.SourceTag;
|
cellTag.Value = string.IsNullOrWhiteSpace(action.SourceTag)? "direct link" : action.SourceTag;
|
||||||
if (!string.IsNullOrWhiteSpace(action.SourceUrl))
|
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.Side.ToString();
|
||||||
ws.Cells[cr, cc++].Value = action.SourceType;
|
ws.Cells[cr, cc++].Value = action.SourceType;
|
||||||
|
|||||||
@@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ public class ModpackFactory
|
|||||||
modrinth.Dispose();
|
modrinth.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> ResolveSourceUrl(InstallAction action)
|
public async Task<string> ResolveSourceUrl(InstallAction action, Version? targetVersion)
|
||||||
{
|
{
|
||||||
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.SourceUrl;
|
return action.GetSourceUrl(targetVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -150,8 +150,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.SourceUrl
|
? iaction.GetSourceUrl(checkResult.LatestVersion)
|
||||||
: await factory.ResolveSourceUrl(iaction);
|
: await factory.ResolveSourceUrl(iaction, checkResult.LatestVersion);
|
||||||
|
|
||||||
if (iaction is UpdateAction uaction)
|
if (iaction is UpdateAction uaction)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,19 +6,12 @@ namespace ModpackUpdater;
|
|||||||
public class ModpackConfig
|
public class ModpackConfig
|
||||||
{
|
{
|
||||||
public bool Maintenance { get; set; }
|
public bool Maintenance { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string UpdateUrl { get; set; }
|
public string UpdateUrl { get; set; }
|
||||||
|
|
||||||
public string InstallUrl { get; set; }
|
public string InstallUrl { get; set; }
|
||||||
|
|
||||||
public string UnleashApiUrl { get; set; }
|
public string UnleashApiUrl { get; set; }
|
||||||
|
|
||||||
public string UnleashInstanceId { get; set; }
|
public string UnleashInstanceId { get; set; }
|
||||||
|
|
||||||
public bool PreferDirectLinks { get; set; }
|
public bool PreferDirectLinks { get; set; }
|
||||||
|
|
||||||
public string MinecraftVersion { get; set; }
|
public string MinecraftVersion { get; set; }
|
||||||
|
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
|
|||||||
Reference in New Issue
Block a user