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

@@ -11,7 +11,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NGitLab" Version="6.53.0" /> <PackageReference Include="NGitLab" Version="6.55.0" />
<PackageReference Include="Pilz.Configuration" Version="3.1.3" /> <PackageReference Include="Pilz.Configuration" Version="3.1.3" />
<PackageReference Include="Pilz.Plugins.Advanced" Version="2.10.1" /> <PackageReference Include="Pilz.Plugins.Advanced" Version="2.10.1" />
<PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.7.0" /> <PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.7.0" />

View File

@@ -172,9 +172,8 @@ partial class MainForm
radGridView_Actions.Size = new Size(590, 416); radGridView_Actions.Size = new Size(590, 416);
radGridView_Actions.TabIndex = 0; radGridView_Actions.TabIndex = 0;
radGridView_Actions.CellFormatting += RadGridView_Actions_CellFormatting; radGridView_Actions.CellFormatting += RadGridView_Actions_CellFormatting;
radGridView_Actions.UserAddingRow += RadGridView_Actions_UserAddingRow;
radGridView_Actions.UserAddedRow += RadGridView_Actions_UserAddedRow; radGridView_Actions.UserAddedRow += RadGridView_Actions_UserAddedRow;
radGridView_Actions.UserDeletedRow += RadGridView_Actions_UserDeletedRow; radGridView_Actions.UserDeletingRow += RadGridView_Actions_UserDeletingRow;
radGridView_Actions.CellValueChanged += RadGridView_Actions_CellValueChanged; radGridView_Actions.CellValueChanged += RadGridView_Actions_CellValueChanged;
// //
// radMenuItem_Workspace // radMenuItem_Workspace

View File

@@ -20,7 +20,7 @@ public partial class MainForm : RadForm, IMainApi
IWorkspace? IMainApi.CurWorkspace => wsInfo?.Workspace; IWorkspace? IMainApi.CurWorkspace => wsInfo?.Workspace;
public IActionSetInfos? CurActionSet => CurActionSet as IActionSetInfos; public IActionSetInfos? CurActionSet => radListControl_Updates.SelectedValue as IActionSetInfos;
private record RecentFilesItemTag(WorkspaceConfig Config, WorkspaceFeature Feature); private record RecentFilesItemTag(WorkspaceConfig Config, WorkspaceFeature Feature);
@@ -513,24 +513,26 @@ public partial class MainForm : RadForm, IMainApi
} }
} }
private void RadGridView_Actions_UserAddingRow(object sender, GridViewRowCancelEventArgs e)
{
foreach (var row in e.Rows)
row.Tag = CurActionSet is UpdateInfo ? new UpdateAction() : new InstallAction();
}
private void RadGridView_Actions_UserAddedRow(object sender, GridViewRowEventArgs e) private void RadGridView_Actions_UserAddedRow(object sender, GridViewRowEventArgs e)
{ {
foreach (var row in e.Rows) foreach (var row in e.Rows)
{ {
if (row.Tag is UpdateAction uaction && CurActionSet is UpdateInfo uinfo && !uinfo.Actions.Contains(uaction)) if (CurActionSet is UpdateInfo uinfo)
uinfo.Actions.Add(uaction); {
else if (row.Tag is InstallAction iaction && CurActionSet is InstallInfos iinfo && !iinfo.Actions.Contains(iaction)) var action = new UpdateAction();
iinfo.Actions.Add(iaction); // ...
uinfo.Actions.Add(action);
}
if (CurActionSet is InstallInfos iinfo)
{
var action = new InstallAction();
// ...
iinfo.Actions.Add(action);
}
} }
} }
private void RadGridView_Actions_UserDeletedRow(object sender, GridViewRowEventArgs e) private void RadGridView_Actions_UserDeletingRow(object sender, GridViewRowCancelEventArgs e)
{ {
foreach (var row in e.Rows) foreach (var row in e.Rows)
{ {

View File

@@ -1,4 +1,6 @@
using Newtonsoft.Json; using Modrinth;
using Modrinth.Extensions;
using Newtonsoft.Json;
using Octokit; using Octokit;
using System.IO.Compression; using System.IO.Compression;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@@ -23,10 +25,18 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
private readonly HttpClient http = new(); private readonly HttpClient http = new();
private readonly GitHubClient github = new(new ProductHeaderValue("MinecraftModpackUpdater")); 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() ~ModpackInstaller()
{ {
http.Dispose(); http.Dispose();
curseForge.Dispose();
modrinth.Dispose();
} }
private async Task<UpdateInfos> DownloadUpdateInfos() 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) if (assets.LastOrDefault(asset => Regex.IsMatch(asset.Name, action.SourceRegex)) is ReleaseAsset asset)
return asset.BrowserDownloadUrl; 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; return action.SourceUrl;
} }

View File

@@ -6,9 +6,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <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="Octokit" Version="13.0.1" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" /> <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>
<ItemGroup> <ItemGroup>

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.ComponentModel; using System.ComponentModel;
namespace ModpackUpdater; namespace ModpackUpdater;
@@ -27,6 +28,7 @@ public class InstallAction
public string SourceUrl { get; set; } public string SourceUrl { get; set; }
[DefaultValue(SourceType.DirectLink)] [DefaultValue(SourceType.DirectLink)]
[JsonConverter(typeof(StringEnumConverter))]
public SourceType SourceType { get; set; } public SourceType SourceType { get; set; }
[DefaultValue(null)] [DefaultValue(null)]
@@ -42,6 +44,7 @@ public class InstallAction
public string SourceTag { get; set; } public string SourceTag { get; set; }
[DefaultValue(Side.Both)] [DefaultValue(Side.Both)]
[JsonConverter(typeof(StringEnumConverter))]
public Side Side { get; set; } = Side.Both; public Side Side { get; set; } = Side.Both;
[DefaultValue(false)] [DefaultValue(false)]

View File

@@ -4,4 +4,7 @@ public enum SourceType
{ {
DirectLink, DirectLink,
GitHub, GitHub,
GitLab,
CurseForge,
Modrinth,
} }

View File

@@ -6,8 +6,8 @@ namespace ModpackUpdater;
public class UpdateAction : InstallAction public class UpdateAction : InstallAction
{ {
[JsonConverter(typeof(StringEnumConverter))]
[DefaultValue(UpdateActionType.Update)] [DefaultValue(UpdateActionType.Update)]
[JsonConverter(typeof(StringEnumConverter))]
public UpdateActionType Type { get; set; } public UpdateActionType Type { get; set; }
[DefaultValue(null)] [DefaultValue(null)]