From 33a209a01a0acda8e5d570006fb77b13f5da4abe Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Tue, 28 Jan 2025 20:38:27 +0100 Subject: [PATCH] add generate modlist feature --- .../Features/SharedFunctions.cs | 59 +++++++++++++++++++ .../Features/Tools/GenerateModlistFeature.cs | 40 +++++++++++++ .../LangRes/FeatureNamesLangRes.Designer.cs | 9 +++ .../LangRes/FeatureNamesLangRes.resx | 3 + .../LangRes/GeneralLangRes.Designer.cs | 9 +++ .../LangRes/GeneralLangRes.resx | 3 + .../LangRes/MsgBoxLangRes.Designer.cs | 18 ++++++ .../LangRes/MsgBoxLangRes.resx | 6 ++ .../ModpackUpdater.Apps.Manager.csproj | 11 ++-- ModpackUpdater.Apps.Manager/Program.cs | 2 + ModpackUpdater.Apps/AppSymbols.cs | 1 + ModpackUpdater.Apps/Symbols/list_view.svg | 1 + 12 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistFeature.cs create mode 100644 ModpackUpdater.Apps/Symbols/list_view.svg diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index 6b5b7d0..9a7ab22 100644 --- a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs +++ b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs @@ -1,7 +1,9 @@ using Microsoft.Extensions.Primitives; using ModpackUpdater.Apps.Manager.Api.Model; +using ModpackUpdater.Apps.Manager.LangRes; using ModpackUpdater.Apps.Manager.Ui; using ModpackUpdater.Manager; +using OfficeOpenXml; using Pilz.UI.Extensions; using System.Text; using Telerik.WinControls.UI; @@ -209,4 +211,61 @@ internal static class SharedFunctions return log.ToString().TrimEnd(); } + + public static ExcelPackage? GenerateModlist(InstallInfos installInfos) + { + var pkg = new ExcelPackage(); + var ws = pkg.Workbook.Worksheets.Add(GeneralLangRes.Text_Modlist); + var cr = 1; + var cc = 1; + + // Header + ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_Name; + ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcTag; + ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_Side; + ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcType; + ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcOwner; + ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcName; + cr += 1; + cc = 1; + + // Rows + foreach (var action in installInfos.Actions) + { + if (action.IsExtra || action.IsZip || string.IsNullOrWhiteSpace(action.Id) || !action.Id.StartsWith("mod:")) + continue; + + var cellName = ws.Cells[cr, cc++]; + cellName.Value = action.Name; + if (!string.IsNullOrWhiteSpace(action.Website)) + cellName.SetHyperlink(new Uri(action.Website)); + + var cellTag = ws.Cells[cr, cc++]; + cellTag.Value = action.SourceTag; + if (!string.IsNullOrWhiteSpace(action.SourceUrl)) + cellTag.SetHyperlink(new Uri(action.SourceUrl)); + + ws.Cells[cr, cc++].Value = action.Side.ToString(); + ws.Cells[cr, cc++].Value = action.SourceType; + ws.Cells[cr, cc++].Value = action.SourceOwner; + ws.Cells[cr, cc++].Value = action.SourceName; + + cr += 1; + cc = 1; + } + + // Styling + cc = 1; + ws.Column(cc++).Width = 30; + ws.Column(cc++).Width = 15; + ws.Column(cc++).Width = 10; + ws.Column(cc++).Width = 20; + ws.Column(cc++).Width = 20; + ws.Column(cc++).Width = 30; + var tableDef = ws.Tables.Add(ws.Cells[1, 1, cr - 1, cc - 1], "Table"); + tableDef.TableStyle = OfficeOpenXml.Table.TableStyles.Medium16; + tableDef.ShowHeader = true; + + return pkg; + } } diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistFeature.cs b/ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistFeature.cs new file mode 100644 index 0000000..3edb5c7 --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistFeature.cs @@ -0,0 +1,40 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using OfficeOpenXml; +using Pilz.Plugins.Advanced; +using Telerik.WinControls; +using Telerik.WinControls.UI; + +namespace ModpackUpdater.Apps.Manager.Features.Tools; +internal class GenerateModlistFeature : PluginFunction, IPluginFeatureProvider +{ + public static GenerateModlistFeature Instance { get; } = new(); + + public GenerateModlistFeature() : base(FeatureTypes.Tools, "origin.genmodlist", FeatureNamesLangRes.GenerateModlistFeature) + { + Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.list_view, Pilz.UI.Symbols.SymbolSize.Small); + } + + protected override object? ExecuteFunction(PluginFunctionParameter? @params) + { + if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null || p.Api.CurWorkspace?.InstallInfos is null) + return null; + + using var pkg = SharedFunctions.GenerateModlist(p.Api.CurWorkspace.InstallInfos); + if (pkg is null) + return null; + + using var sfd = new RadSaveFileDialog + { + Filter = "*.xlsx|*.xlsx|*|*" + }; + + if (sfd.ShowDialog(p.Api.MainWindow) == DialogResult.OK) + { + pkg.SaveAs(sfd.FileName); + RadMessageBox.Show(p.Api.MainWindow, MsgBoxLangRes., MsgBoxLangRes., MessageBoxButtons.OK, RadMessageIcon.Info); + } + + return null; + } +} diff --git a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs index c62f4c4..49e20f6 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs @@ -105,6 +105,15 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Generate modlist ähnelt. + /// + internal static string GenerateModlistFeature { + get { + return ResourceManager.GetString("GenerateModlistFeature", 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 e002da2..823ec55 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx @@ -132,6 +132,9 @@ Generate changelog + + Generate modlist + GitLab workspace diff --git a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs index 618b66c..341529a 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs @@ -77,5 +77,14 @@ namespace ModpackUpdater.Apps.Manager.LangRes { return ResourceManager.GetString("Node_Update", resourceCulture); } } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Modlist ähnelt. + /// + internal static string Text_Modlist { + get { + return ResourceManager.GetString("Text_Modlist", resourceCulture); + } + } } } diff --git a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx index edc348b..26bc033 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx @@ -123,4 +123,7 @@ Update: {0} + + Modlist + \ No newline at end of file diff --git a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs index f37a2a0..702aaef 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs @@ -78,6 +78,24 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die The modlist has been generated successfully and saved to the selected location. ähnelt. + /// + internal static string ModlistGenerated { + get { + return ResourceManager.GetString("ModlistGenerated", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Modlist generated successfully ähnelt. + /// + internal static string ModlistGenerated_Title { + get { + return ResourceManager.GetString("ModlistGenerated_Title", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Are you sure that you want to delete this update? ähnelt. /// diff --git a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx index a8cc55f..9651f10 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx @@ -123,6 +123,12 @@ Changelog generated successfully + + The modlist has been generated successfully and saved to the selected location. + + + Modlist generated successfully + Are you sure that you want to delete this update? diff --git a/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj b/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj index c05e9e9..f4f4afe 100644 --- a/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj +++ b/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj @@ -11,15 +11,16 @@ - + + - - - - + + + + diff --git a/ModpackUpdater.Apps.Manager/Program.cs b/ModpackUpdater.Apps.Manager/Program.cs index 502e4da..8864a2c 100644 --- a/ModpackUpdater.Apps.Manager/Program.cs +++ b/ModpackUpdater.Apps.Manager/Program.cs @@ -1,3 +1,4 @@ +using OfficeOpenXml; using Pilz; using Pilz.Configuration; using Pilz.Plugins.Advanced; @@ -14,6 +15,7 @@ public static class Program static Program() { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; settingsManager = new(GetSettingsPath(), true); } diff --git a/ModpackUpdater.Apps/AppSymbols.cs b/ModpackUpdater.Apps/AppSymbols.cs index 9d2edd3..ebc3475 100644 --- a/ModpackUpdater.Apps/AppSymbols.cs +++ b/ModpackUpdater.Apps/AppSymbols.cs @@ -35,4 +35,5 @@ public enum AppSymbols heart_with_pulse, broom, renew, + list_view, } diff --git a/ModpackUpdater.Apps/Symbols/list_view.svg b/ModpackUpdater.Apps/Symbols/list_view.svg new file mode 100644 index 0000000..113c1fa --- /dev/null +++ b/ModpackUpdater.Apps/Symbols/list_view.svg @@ -0,0 +1 @@ + \ No newline at end of file