diff --git a/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj b/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj index edb3b70..34c1375 100644 --- a/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj +++ b/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj @@ -11,7 +11,7 @@ - + diff --git a/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs b/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs index 193b1d4..7adcfee 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs @@ -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 diff --git a/ModpackUpdater.Apps.Manager/Ui/MainForm.cs b/ModpackUpdater.Apps.Manager/Ui/MainForm.cs index 1a0eba2..0ff8d6b 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainForm.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainForm.cs @@ -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) { diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 7bfb0d6..47898ef 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -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 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; } diff --git a/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj b/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj index 19904b8..0ea5380 100644 --- a/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj +++ b/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj @@ -6,9 +6,11 @@ + + - + diff --git a/ModpackUpdater/InstallAction.cs b/ModpackUpdater/InstallAction.cs index a52cc22..eaef33d 100644 --- a/ModpackUpdater/InstallAction.cs +++ b/ModpackUpdater/InstallAction.cs @@ -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)] diff --git a/ModpackUpdater/SourceType.cs b/ModpackUpdater/SourceType.cs index 5389b4f..be08a7b 100644 --- a/ModpackUpdater/SourceType.cs +++ b/ModpackUpdater/SourceType.cs @@ -4,4 +4,7 @@ public enum SourceType { DirectLink, GitHub, + GitLab, + CurseForge, + Modrinth, } diff --git a/ModpackUpdater/UpdateAction.cs b/ModpackUpdater/UpdateAction.cs index 3a05fbf..35e1cc3 100644 --- a/ModpackUpdater/UpdateAction.cs +++ b/ModpackUpdater/UpdateAction.cs @@ -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)]