allow curseforge and modrinth as source
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<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.Plugins.Advanced" Version="2.10.1" />
|
||||
<PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.7.0" />
|
||||
|
||||
@@ -172,9 +172,8 @@ partial class MainForm
|
||||
radGridView_Actions.Size = new Size(590, 416);
|
||||
radGridView_Actions.TabIndex = 0;
|
||||
radGridView_Actions.CellFormatting += RadGridView_Actions_CellFormatting;
|
||||
radGridView_Actions.UserAddingRow += RadGridView_Actions_UserAddingRow;
|
||||
radGridView_Actions.UserAddedRow += RadGridView_Actions_UserAddedRow;
|
||||
radGridView_Actions.UserDeletedRow += RadGridView_Actions_UserDeletedRow;
|
||||
radGridView_Actions.UserDeletingRow += RadGridView_Actions_UserDeletingRow;
|
||||
radGridView_Actions.CellValueChanged += RadGridView_Actions_CellValueChanged;
|
||||
//
|
||||
// radMenuItem_Workspace
|
||||
|
||||
@@ -20,7 +20,7 @@ public partial class MainForm : RadForm, IMainApi
|
||||
|
||||
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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
foreach (var row in e.Rows)
|
||||
{
|
||||
if (row.Tag is UpdateAction uaction && CurActionSet is UpdateInfo uinfo && !uinfo.Actions.Contains(uaction))
|
||||
uinfo.Actions.Add(uaction);
|
||||
else if (row.Tag is InstallAction iaction && CurActionSet is InstallInfos iinfo && !iinfo.Actions.Contains(iaction))
|
||||
iinfo.Actions.Add(iaction);
|
||||
if (CurActionSet is UpdateInfo uinfo)
|
||||
{
|
||||
var action = new UpdateAction();
|
||||
// ...
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ModpackUpdater;
|
||||
@@ -27,6 +28,7 @@ public class InstallAction
|
||||
public string SourceUrl { get; set; }
|
||||
|
||||
[DefaultValue(SourceType.DirectLink)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public SourceType SourceType { get; set; }
|
||||
|
||||
[DefaultValue(null)]
|
||||
@@ -42,6 +44,7 @@ public class InstallAction
|
||||
public string SourceTag { get; set; }
|
||||
|
||||
[DefaultValue(Side.Both)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Side Side { get; set; } = Side.Both;
|
||||
|
||||
[DefaultValue(false)]
|
||||
|
||||
@@ -4,4 +4,7 @@ public enum SourceType
|
||||
{
|
||||
DirectLink,
|
||||
GitHub,
|
||||
GitLab,
|
||||
CurseForge,
|
||||
Modrinth,
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace ModpackUpdater;
|
||||
|
||||
public class UpdateAction : InstallAction
|
||||
{
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
[DefaultValue(UpdateActionType.Update)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public UpdateActionType Type { get; set; }
|
||||
|
||||
[DefaultValue(null)]
|
||||
|
||||
Reference in New Issue
Block a user