Skip to content

Commit

Permalink
fix: Fix for Forge-installers having different version format in olde…
Browse files Browse the repository at this point in the history
…r versions
  • Loading branch information
itssimple committed May 14, 2022
1 parent 2c35366 commit 6294215
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion CurseForge.Minecraft.Serverpack.Launcher/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text.Json;
using System.Threading.Tasks;
using CurseForge.APIClient;
using Spectre.Console;

namespace CurseForge.Minecraft.Serverpack.Launcher
{
Expand Down Expand Up @@ -122,7 +123,22 @@ private static async Task DownloadLoaderDependencies<T>(HttpClient _client, stri
case ForgeModLoaderInfo forge:
var versionString = $"{info.NonMapped["minecraftVersion"]}-{info.NonMapped["forgeVersion"]}";
var forgeInstallerMaven = new MavenString($"net.minecraftforge.forge:{versionString}");
downloadUrls.Add(new(forgeInstallerMaven, installPath, new Uri($"https://maven.minecraftforge.net/net/minecraftforge/forge/{versionString}/forge-{versionString}-installer.jar")));

var forgeDlUrl = $"https://maven.minecraftforge.net/net/minecraftforge/forge/{versionString}/forge-{versionString}-installer.jar";

if (!await CheckIfEndpointExists(_client, forgeDlUrl))
{
versionString = $"{info.NonMapped["minecraftVersion"]}-{info.NonMapped["forgeVersion"]}-{info.NonMapped["minecraftVersion"]}";
forgeDlUrl = $"https://maven.minecraftforge.net/net/minecraftforge/forge/{versionString}/forge-{versionString}-installer.jar";
}

if (!await CheckIfEndpointExists(_client, forgeDlUrl))
{
AnsiConsole.WriteLine($"[red]Could not find an installer for the version of Forge that we need ({info.NonMapped["forgeVersion"]}) for Minecraft {info.NonMapped["minecraftVersion"]}[/]");
throw new Exception("Missing Forge installer");
}

downloadUrls.Add(new(forgeInstallerMaven, installPath, new Uri(forgeDlUrl)));
break;
}

Expand Down Expand Up @@ -152,5 +168,11 @@ private static async Task DownloadLoaderDependencies<T>(HttpClient _client, stri

Console.WriteLine("Downloaded all library assets");
}

private static async Task<bool> CheckIfEndpointExists(HttpClient _client, string url)
{
var result = await _client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
return result.IsSuccessStatusCode;
}
}
}

0 comments on commit 6294215

Please sign in to comment.