From 690355266c985a4da0535f54e5e24acc2c14878c Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Thu, 3 Oct 2024 10:46:16 +0200 Subject: [PATCH] add options to update and clear direct links --- .../Features/CM/ClearDirectLinkFeature.cs | 29 +++++++++++ .../Features/CM/UpdateDirectLinkFeature.cs | 29 +++++++++++ .../Features/SharedFunctions.cs | 51 ++++++++++++++++++- .../Features/Tools/ClearDirectLinksFeature.cs | 24 +++++++++ .../Tools/UpdateDirectLinksFeature.cs | 24 +++++++++ .../LangRes/FeatureNamesLangRes.Designer.cs | 36 +++++++++++++ .../LangRes/FeatureNamesLangRes.resx | 12 +++++ .../UpdatesCollectorUi.Designer.cs | 2 +- .../Tools => Ui}/UpdatesCollectorUi.cs | 2 +- .../Tools => Ui}/UpdatesCollectorUi.resx | 0 10 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 ModpackUpdater.Apps.Manager/Features/CM/ClearDirectLinkFeature.cs create mode 100644 ModpackUpdater.Apps.Manager/Features/CM/UpdateDirectLinkFeature.cs create mode 100644 ModpackUpdater.Apps.Manager/Features/Tools/ClearDirectLinksFeature.cs create mode 100644 ModpackUpdater.Apps.Manager/Features/Tools/UpdateDirectLinksFeature.cs rename ModpackUpdater.Apps.Manager/{Features/Tools => Ui}/UpdatesCollectorUi.Designer.cs (99%) rename ModpackUpdater.Apps.Manager/{Features/Tools => Ui}/UpdatesCollectorUi.cs (98%) rename ModpackUpdater.Apps.Manager/{Features/Tools => Ui}/UpdatesCollectorUi.resx (100%) diff --git a/ModpackUpdater.Apps.Manager/Features/CM/ClearDirectLinkFeature.cs b/ModpackUpdater.Apps.Manager/Features/CM/ClearDirectLinkFeature.cs new file mode 100644 index 0000000..1b9de4a --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/CM/ClearDirectLinkFeature.cs @@ -0,0 +1,29 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using ModpackUpdater.Apps.Manager.Ui; +using Pilz.Plugins.Advanced; +using Telerik.WinControls.UI; + +namespace ModpackUpdater.Apps.Manager.Features.CM; + +internal class ClearDirectLinkFeature : PluginFunction, IPluginFeatureProvider +{ + public static ClearDirectLinkFeature Instance { get; } = new(); + + public ClearDirectLinkFeature() : base(FeatureTypes.ActionsContextMenu, "origin.cleardirectlink", FeatureNamesLangRes.ClearDirectLinkFeature) + { + } + + protected override object? ExecuteFunction(PluginFunctionParameter? @params) + { + if (@params is not MainApiParameters p + || p.Api.MainWindow is not MainForm mainForm + || mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView + || gridView.SelectedRows.FirstOrDefault()?.Tag is not InstallAction selectedAction) + return null; + + SharedFunctions.ClearDirectLinks(p.Api, selectedAction); + + return null; + } +} diff --git a/ModpackUpdater.Apps.Manager/Features/CM/UpdateDirectLinkFeature.cs b/ModpackUpdater.Apps.Manager/Features/CM/UpdateDirectLinkFeature.cs new file mode 100644 index 0000000..3824473 --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/CM/UpdateDirectLinkFeature.cs @@ -0,0 +1,29 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using ModpackUpdater.Apps.Manager.Ui; +using Pilz.Plugins.Advanced; +using Telerik.WinControls.UI; + +namespace ModpackUpdater.Apps.Manager.Features.CM; + +internal class UpdateDirectLinkFeature : PluginFunction, IPluginFeatureProvider +{ + public static UpdateDirectLinkFeature Instance { get; } = new(); + + public UpdateDirectLinkFeature() : base(FeatureTypes.ActionsContextMenu, "origin.updatedirectlink", FeatureNamesLangRes.UpdateDirectLinkFeature) + { + } + + protected override object? ExecuteFunction(PluginFunctionParameter? @params) + { + if (@params is not MainApiParameters p + || p.Api.MainWindow is not MainForm mainForm + || mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView + || gridView.SelectedRows.FirstOrDefault()?.Tag is not InstallAction selectedAction) + return null; + + SharedFunctions.FindNewDirectLinks(p.Api, selectedAction); + + return null; + } +} diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index 9299a9a..f939f3b 100644 --- a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs +++ b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs @@ -1,5 +1,4 @@ using ModpackUpdater.Apps.Manager.Api.Model; -using ModpackUpdater.Apps.Manager.Features.Tools; using ModpackUpdater.Apps.Manager.Ui; using ModpackUpdater.Manager; using Pilz.UI.Extensions; @@ -24,6 +23,7 @@ internal static class SharedFunctions var failed = false; var msg = default(string); + var factory = new ModpackFactory(); var rows = new Dictionary(); for (var i = 0; i < selectedRows.Length; i++) @@ -36,7 +36,6 @@ internal static class SharedFunctions { try { - var factory = new ModpackFactory(); var result = await factory.ResolveSourceUrl(action); failed = string.IsNullOrWhiteSpace(result); } @@ -107,4 +106,52 @@ internal static class SharedFunctions return true; } + + public static void FindNewDirectLinks(IMainApi api, params InstallAction[] actions) + { + var mainForm = api.MainWindow as MainForm; + var gridView = mainForm?.Controls.Find("radGridView_Actions", true).FirstOrDefault() as RadGridView; + var rwb = mainForm?.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() as RadWaitingBar; + var factory = new ModpackFactory(); + + rwb?.StartWaiting(); + gridView?.BeginUpdate(); + + foreach (var action in actions) + { + if (action.SourceType != SourceType.DirectLink) + { + Task.Run(async () => + { + action.SourceUrl = await factory.ResolveSourceUrl(action); + }).Wait(); + api.UpdateItem(action); + } + } + + gridView?.EndUpdate(); + rwb?.StopWaiting(); + } + + public static void ClearDirectLinks(IMainApi api, params InstallAction[] actions) + { + var mainForm = api.MainWindow as MainForm; + var gridView = mainForm?.Controls.Find("radGridView_Actions", true).FirstOrDefault() as RadGridView; + var rwb = mainForm?.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() as RadWaitingBar; + + rwb?.StartWaiting(); + gridView?.BeginUpdate(); + + foreach (var action in actions) + { + if (action.SourceType != SourceType.DirectLink) + { + action.SourceUrl = null; + api.UpdateItem(action); + } + } + + gridView?.EndUpdate(); + rwb?.StopWaiting(); + } } diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/ClearDirectLinksFeature.cs b/ModpackUpdater.Apps.Manager/Features/Tools/ClearDirectLinksFeature.cs new file mode 100644 index 0000000..7ba7506 --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/Tools/ClearDirectLinksFeature.cs @@ -0,0 +1,24 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using Pilz.Plugins.Advanced; + +namespace ModpackUpdater.Apps.Manager.Features.Tools; + +internal class ClearDirectLinksFeature : PluginFunction, IPluginFeatureProvider +{ + public static ClearDirectLinksFeature Instance { get; } = new(); + + public ClearDirectLinksFeature() : base(FeatureTypes.Tools, "origin.cleardirectlinks", FeatureNamesLangRes.ClearDirectLinksFeature) + { + } + + protected override object? ExecuteFunction(PluginFunctionParameter? @params) + { + if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null) + return null; + + SharedFunctions.ClearDirectLinks(p.Api, [.. p.Api.CurWorkspace.InstallInfos.Actions]); + + return null; + } +} diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/UpdateDirectLinksFeature.cs b/ModpackUpdater.Apps.Manager/Features/Tools/UpdateDirectLinksFeature.cs new file mode 100644 index 0000000..bf84849 --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/Tools/UpdateDirectLinksFeature.cs @@ -0,0 +1,24 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using Pilz.Plugins.Advanced; + +namespace ModpackUpdater.Apps.Manager.Features.Tools; + +internal class UpdateDirectLinksFeature : PluginFunction, IPluginFeatureProvider +{ + public static UpdateDirectLinksFeature Instance { get; } = new(); + + public UpdateDirectLinksFeature() : base(FeatureTypes.Tools, "origin.updatedirectlinks", FeatureNamesLangRes.UpdateDirectLinksFeature) + { + } + + protected override object? ExecuteFunction(PluginFunctionParameter? @params) + { + if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null) + return null; + + SharedFunctions.FindNewDirectLinks(p.Api, [.. p.Api.CurWorkspace.InstallInfos.Actions]); + + return null; + } +} diff --git a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs index 8aa773a..16616a4 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs @@ -78,6 +78,24 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Clear direct link ähnelt. + /// + internal static string ClearDirectLinkFeature { + get { + return ResourceManager.GetString("ClearDirectLinkFeature", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Clear direct links ähnelt. + /// + internal static string ClearDirectLinksFeature { + get { + return ResourceManager.GetString("ClearDirectLinksFeature", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die GitLab workspace ähnelt. /// @@ -96,6 +114,24 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Update direct link ähnelt. + /// + internal static string UpdateDirectLinkFeature { + get { + return ResourceManager.GetString("UpdateDirectLinkFeature", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Update direct links ähnelt. + /// + internal static string UpdateDirectLinksFeature { + get { + return ResourceManager.GetString("UpdateDirectLinksFeature", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Find updates ähnelt. /// diff --git a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx index 6c7a22a..9ac31bb 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx @@ -123,12 +123,24 @@ Check healthy + + Clear direct link + + + Clear direct links + GitLab workspace Find update + + Update direct link + + + Update direct links + Find updates diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.Designer.cs b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.Designer.cs similarity index 99% rename from ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.Designer.cs rename to ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.Designer.cs index a328f4b..5d710ee 100644 --- a/ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.Designer.cs +++ b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.Designer.cs @@ -1,4 +1,4 @@ -namespace ModpackUpdater.Apps.Manager.Features.Tools; +namespace ModpackUpdater.Apps.Manager.Ui; partial class UpdatesCollectorUi { diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.cs b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.cs similarity index 98% rename from ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.cs rename to ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.cs index e666700..4a806a9 100644 --- a/ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.cs +++ b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.cs @@ -1,7 +1,7 @@ using ModpackUpdater.Manager; using Telerik.WinControls.UI; -namespace ModpackUpdater.Apps.Manager.Features.Tools; +namespace ModpackUpdater.Apps.Manager.Ui; public partial class UpdatesCollectorUi : RadForm { diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.resx b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.resx similarity index 100% rename from ModpackUpdater.Apps.Manager/Features/Tools/UpdatesCollectorUi.resx rename to ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorUi.resx