allow curseforge and modrinth as source

This commit is contained in:
2024-09-22 09:41:09 +02:00
parent 7e5acd413e
commit bc6c483ba6
8 changed files with 54 additions and 18 deletions

View File

@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using Modrinth;
using Modrinth.Extensions;
using Newtonsoft.Json;
using Octokit;
using System.IO.Compression;
using System.Text.RegularExpressions;
@@ -23,10 +25,18 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
private readonly HttpClient http = new();
private readonly GitHubClient github = new(new ProductHeaderValue("MinecraftModpackUpdater"));
private readonly CurseForge.APIClient.ApiClient curseForge = new("b67bd218-e011-4963-ac8a-ffd025e1091f", "pilzinsel64@gmx.de");
private readonly ModrinthClient modrinth = new(new ModrinthClientConfig
{
ModrinthToken = "mrp_zUlDSET5actMUdTU3FK242TXgvlWgaErSSEFuegNG7thLgkC50IiK2NCGOzW",
UserAgent = "Pilz.ModpackUpater",
});
~ModpackInstaller()
{
http.Dispose();
curseForge.Dispose();
modrinth.Dispose();
}
private async Task<UpdateInfos> DownloadUpdateInfos()
@@ -271,6 +281,23 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
if (assets.LastOrDefault(asset => Regex.IsMatch(asset.Name, action.SourceRegex)) is ReleaseAsset asset)
return asset.BrowserDownloadUrl;
}
else if (action.SourceType == SourceType.GitLab)
{
throw new NotImplementedException("To be implemented soon.");
}
else if (action.SourceType == SourceType.CurseForge)
{
var res = await curseForge.GetModFileDownloadUrlAsync(Convert.ToInt32(action.SourceName), Convert.ToInt32(action.SourceTag));
if (!string.IsNullOrWhiteSpace(res.Data))
return res.Data;
}
else if (action.SourceType == SourceType.Modrinth)
{
var res = await modrinth.VersionFile.GetVersionByHashAsync(action.SourceTag);
var file = res.Files.Length == 1 ? res.Files[0] : res.Files.FirstOrDefault(n => Regex.IsMatch(n.FileName, action.SourceRegex));
if (file != null)
return file.Url;
}
return action.SourceUrl;
}

View File

@@ -6,9 +6,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CurseForge.APIClient" Version="3.0.0" />
<PackageReference Include="Modrinth.Net" Version="3.4.5" />
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="Unleash.Client" Version="4.1.11" />
<PackageReference Include="Unleash.Client" Version="4.1.12" />
</ItemGroup>
<ItemGroup>