From 31f557cc8d4b230d15654a4c5782e9f453956f75 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Sat, 28 Sep 2024 14:08:30 +0200 Subject: [PATCH] finish healthy check & other sources implemtation --- ModpackUpdater.Apps.Manager/FeatureTypes.cs | 1 + .../Tools/CheckAllActionsHealthyFeature.cs | 72 +++++++++++++++++++ .../Tools/CheckSingleActionHealthyFeature.cs | 58 +++++++++++++++ .../LangRes/FeatureNamesLangRes.Designer.cs | 18 +++++ .../LangRes/FeatureNamesLangRes.resx | 6 ++ .../Ui/MainForm.Designer.cs | 3 +- ModpackUpdater.Apps.Manager/Ui/MainForm.cs | 9 +++ ModpackUpdater.Apps/AppSymbols.cs | 1 + .../Symbols/heart_with_pulse.svg | 11 +++ ModpackUpdater.Manager/ModpackFactory.cs | 2 +- 10 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 ModpackUpdater.Apps.Manager/Features/Tools/CheckAllActionsHealthyFeature.cs create mode 100644 ModpackUpdater.Apps.Manager/Features/Tools/CheckSingleActionHealthyFeature.cs create mode 100644 ModpackUpdater.Apps/Symbols/heart_with_pulse.svg diff --git a/ModpackUpdater.Apps.Manager/FeatureTypes.cs b/ModpackUpdater.Apps.Manager/FeatureTypes.cs index b0340eb..946c0b4 100644 --- a/ModpackUpdater.Apps.Manager/FeatureTypes.cs +++ b/ModpackUpdater.Apps.Manager/FeatureTypes.cs @@ -4,4 +4,5 @@ public static class FeatureTypes { public static string Workspace => "workspace"; public static string Tools => "tools"; + public static string ActionsContextMenu => "cm.actions"; } diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/CheckAllActionsHealthyFeature.cs b/ModpackUpdater.Apps.Manager/Features/Tools/CheckAllActionsHealthyFeature.cs new file mode 100644 index 0000000..d1d456d --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/Tools/CheckAllActionsHealthyFeature.cs @@ -0,0 +1,72 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using ModpackUpdater.Apps.Manager.Ui; +using ModpackUpdater.Manager; +using Pilz.Plugins.Advanced; +using Telerik.WinControls.UI; + +namespace ModpackUpdater.Apps.Manager.Features.Tools; + +internal class CheckAllActionsHealthyFeature : PluginFunction, IPluginFeatureProvider +{ + public static CheckAllActionsHealthyFeature Instance { get; } = new(); + + public CheckAllActionsHealthyFeature() : base(FeatureTypes.Tools, "origin.checkallactionshearlthy", FeatureNamesLangRes.CheckAllActionsHealthy) + { + Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.heart_with_pulse, Pilz.UI.Symbols.SymbolSize.Small); + } + + 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 + || mainForm.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() is not RadWaitingBar rwb) + return null; + + rwb.StartWaiting(); + rwb.ShowText = true; + var rowsCount = gridView.Rows.Count; + rwb.Text = "0 / " + rowsCount; + gridView.BeginUpdate(); + + var rows = new Dictionary(); + for (var i = 0; i < gridView.Rows.Count; i++) + { + var row = gridView.Rows[i]; + var failed = false; + + if (row.Tag is InstallAction action) + { + Task.Run(async () => + { + try + { + var factory = new ModpackFactory(); + var result = await factory.ResolveSourceUrl(action); + failed = string.IsNullOrWhiteSpace(result); + } + catch (Exception) + { + } + }).Wait(); + } + + foreach (var c in row.Cells) + { + c.Style.CustomizeFill = true; + c.Style.BackColor = failed ? Color.IndianRed : Color.ForestGreen; + } + + rwb.Text = $"{i} / {rowsCount}"; + + Application.DoEvents(); + } + + gridView.EndUpdate(); + rwb.ShowText = false; + rwb.StopWaiting(); + + return null; + } +} diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/CheckSingleActionHealthyFeature.cs b/ModpackUpdater.Apps.Manager/Features/Tools/CheckSingleActionHealthyFeature.cs new file mode 100644 index 0000000..b8425db --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/Tools/CheckSingleActionHealthyFeature.cs @@ -0,0 +1,58 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using ModpackUpdater.Apps.Manager.Ui; +using ModpackUpdater.Manager; +using Pilz.Plugins.Advanced; +using Telerik.WinControls.UI; + +namespace ModpackUpdater.Apps.Manager.Features.Tools; + +internal class CheckSingleActionHealthyFeature : PluginFunction, IPluginFeatureProvider +{ + public static CheckSingleActionHealthyFeature Instance { get; } = new(); + + public CheckSingleActionHealthyFeature() : base(FeatureTypes.ActionsContextMenu, "origin.checksingleactionhearlthy", FeatureNamesLangRes.CheckSingleActionHealthy) + { + Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.heart_with_pulse, Pilz.UI.Symbols.SymbolSize.Small); + } + + 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() is not GridViewRowInfo row + || row.Tag is not InstallAction action) + return null; + + bool failed = true; + string? msg = null; + + Task.Run(async () => + { + try + { + var factory = new ModpackFactory(); + var result = await factory.ResolveSourceUrl(action); + failed = string.IsNullOrWhiteSpace(result); + } + catch(Exception ex) + { + msg = ex.Message; + } + }).Wait(); + + gridView.BeginUpdate(); + foreach (var c in row.Cells) + { + c.Style.CustomizeFill = true; + c.Style.BackColor = failed ? Color.IndianRed : Color.ForestGreen; + } + gridView.EndUpdate(); + + if (failed && !string.IsNullOrWhiteSpace(msg)) + MessageBox.Show(msg); + + return null; + } +} diff --git a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs index 851ce6b..512eef2 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs @@ -60,6 +60,24 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Check healthy ähnelt. + /// + internal static string CheckAllActionsHealthy { + get { + return ResourceManager.GetString("CheckAllActionsHealthy", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Check healthy ähnelt. + /// + internal static string CheckSingleActionHealthy { + get { + return ResourceManager.GetString("CheckSingleActionHealthy", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die GitLab workspace ähnelt. /// diff --git a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx index 363297d..d4c4a60 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Check healthy + + + Check healthy + GitLab workspace diff --git a/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs b/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs index 4321b1f..5e6536b 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs @@ -175,6 +175,7 @@ partial class MainForm radGridView_Actions.UserAddedRow += RadGridView_Actions_UserAddedRow; radGridView_Actions.UserDeletingRow += RadGridView_Actions_UserDeletingRow; radGridView_Actions.CellValueChanged += RadGridView_Actions_CellValueChanged; + radGridView_Actions.ContextMenuOpening += RadGridView_Actions_ContextMenuOpening; // // radMenuItem_Workspace // @@ -274,11 +275,11 @@ partial class MainForm // radWaitingBar_Actions // radWaitingBar_Actions.AssociatedControl = radGridView_Actions; + radWaitingBar_Actions.ForeColor = Color.Black; radWaitingBar_Actions.Location = new Point(0, 145); radWaitingBar_Actions.Name = "radWaitingBar_Actions"; radWaitingBar_Actions.Size = new Size(70, 70); radWaitingBar_Actions.TabIndex = 3; - radWaitingBar_Actions.Text = "radWaitingBar2"; radWaitingBar_Actions.WaitingIndicators.Add(dotsRingWaitingBarIndicatorElement2); radWaitingBar_Actions.WaitingIndicatorSize = new Size(100, 14); radWaitingBar_Actions.WaitingSpeed = 50; diff --git a/ModpackUpdater.Apps.Manager/Ui/MainForm.cs b/ModpackUpdater.Apps.Manager/Ui/MainForm.cs index ceac685..6e545f5 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainForm.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainForm.cs @@ -358,6 +358,7 @@ public partial class MainForm : RadForm, IMainApi row.Cells["srctag"].Value = action.SourceTag; row.Cells["side"].Value = action.Side; row.Cells["isextra"].Value = action.IsExtra; + row.Cells["website"].Value = action.Website; if (action is not UpdateAction uaction) return; @@ -504,6 +505,9 @@ public partial class MainForm : RadForm, IMainApi case "srctag": action.SourceTag = valueNullStr; break; + case "website": + action.Website = valueNullStr; + break; case "side": action.Side = Enum.Parse(valueStr); break; @@ -587,4 +591,9 @@ public partial class MainForm : RadForm, IMainApi iinfo.Actions.Remove(iaction); } } + + private void RadGridView_Actions_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) + { + PluginFeatureController.Instance.Functions.Get(FeatureTypes.ActionsContextMenu).InsertItemsTo(e.ContextMenu.Items, customClickHandler: RadMenuItem_ToolsItem_Click); + } } diff --git a/ModpackUpdater.Apps/AppSymbols.cs b/ModpackUpdater.Apps/AppSymbols.cs index 516e8d2..bb10f21 100644 --- a/ModpackUpdater.Apps/AppSymbols.cs +++ b/ModpackUpdater.Apps/AppSymbols.cs @@ -32,4 +32,5 @@ public enum AppSymbols search, eye, invisible, + heart_with_pulse, } diff --git a/ModpackUpdater.Apps/Symbols/heart_with_pulse.svg b/ModpackUpdater.Apps/Symbols/heart_with_pulse.svg new file mode 100644 index 0000000..e04480a --- /dev/null +++ b/ModpackUpdater.Apps/Symbols/heart_with_pulse.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ModpackUpdater.Manager/ModpackFactory.cs b/ModpackUpdater.Manager/ModpackFactory.cs index 575c726..1229086 100644 --- a/ModpackUpdater.Manager/ModpackFactory.cs +++ b/ModpackUpdater.Manager/ModpackFactory.cs @@ -7,7 +7,7 @@ namespace ModpackUpdater.Manager; public class ModpackFactory { 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 CurseForge.APIClient.ApiClient curseForge = new("$2a$10$pE4dD09gmr7IcOe8hjWhleWWjXopJcDNpq1P9FlrDMCBw05pCyAXa", "pilzinsel64@gmx.de"); // b67bd218-e011-4963-ac8a-ffd025e1091f private readonly ModrinthClient modrinth = new(new ModrinthClientConfig { ModrinthToken = "mrp_zUlDSET5actMUdTU3FK242TXgvlWgaErSSEFuegNG7thLgkC50IiK2NCGOzW",