diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index d1981e8..79ed4be 100644 --- a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs +++ b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs @@ -6,6 +6,7 @@ using ModpackUpdater.Manager; using OfficeOpenXml; using Pilz.UI.Extensions; using System.Text; +using Telerik.WinControls; using Telerik.WinControls.UI; namespace ModpackUpdater.Apps.Manager.Features; @@ -212,7 +213,46 @@ internal static class SharedFunctions return log.ToString().TrimEnd(); } - public static ExcelPackage? GenerateModlist(InstallInfos installInfos) + public static string GenerateModlistAsMarkdown(InstallInfos installInfos) + { + var sb = new StringBuilder(); + sb.Append("|" + ActionsListLangRes.Col_Name); + sb.Append("|" + ActionsListLangRes.Col_SrcTag); + sb.Append("|" + ActionsListLangRes.Col_Side); + sb.Append("|" + ActionsListLangRes.Col_SrcType); + sb.Append("|" + ActionsListLangRes.Col_SrcOwner); + sb.Append("|" + ActionsListLangRes.Col_SrcName); + sb.AppendLine("|"); + sb.AppendLine("|---|---|---|---|---|---|"); + + // Rows + foreach (var action in installInfos.Actions.OrderBy(n => n.Name)) + { + if (action.IsExtra || action.IsZip || string.IsNullOrWhiteSpace(action.Id) || !action.Id.StartsWith("mod:")) + continue; + + if (string.IsNullOrWhiteSpace(action.Website)) + sb.Append($"|{action.Name}"); + else + sb.Append($"|[{action.Name}]({action.Website})"); + + if (string.IsNullOrWhiteSpace(action.SourceUrl)) + sb.Append($"|{action.SourceTag}"); + else + sb.Append($"|[{action.SourceTag}]({action.SourceUrl})"); + + sb.Append($"|{action.Side.ToString()}"); + sb.Append($"|{action.SourceType}"); + sb.Append($"|{action.SourceOwner}"); + sb.Append($"|{action.SourceName}"); + + sb.AppendLine("|"); + } + + return sb.ToString().TrimEnd(); + } + + public static ExcelPackage? GenerateModlistAsExcel(InstallInfos installInfos) { var pkg = new ExcelPackage(); var ws = pkg.Workbook.Worksheets.Add(string.Format(GeneralLangRes.Text_ModlistForVersion, installInfos.Version)); diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistFeature.cs b/ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistAsExcelFeature.cs similarity index 71% rename from ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistFeature.cs rename to ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistAsExcelFeature.cs index 11de523..4f20b0d 100644 --- a/ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistFeature.cs +++ b/ModpackUpdater.Apps.Manager/Features/Tools/GenerateModlistAsExcelFeature.cs @@ -1,16 +1,15 @@ 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 +internal class GenerateModlistAsExcelFeature : PluginFunction, IPluginFeatureProvider { - public static GenerateModlistFeature Instance { get; } = new(); + public static GenerateModlistAsExcelFeature Instance { get; } = new(); - public GenerateModlistFeature() : base(FeatureTypes.Tools, "origin.genmodlist", FeatureNamesLangRes.GenerateModlistFeature) + public GenerateModlistAsExcelFeature() : base(FeatureTypes.Tools, "origin.genmodlist.xlsx", FeatureNamesLangRes.GenerateModlistAsExcelFeature) { Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.list_view, Pilz.UI.Symbols.SymbolSize.Small); } @@ -20,7 +19,7 @@ internal class GenerateModlistFeature : PluginFunction, IPluginFeatureProvider +{ + public static GenerateModlistAsExcelFeature Instance { get; } = new(); + + public GenerateModlistAsMarkdownFeature() : base(FeatureTypes.Tools, "origin.genmodlist.md", FeatureNamesLangRes.GenerateModlistAsMarkdownFeature) + { + 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; + + Clipboard.SetText(SharedFunctions.GenerateModlistAsMarkdown(p.Api.CurWorkspace.InstallInfos)); + + RadMessageBox.Show(p.Api.MainWindow, MsgBoxLangRes.ModlistCopiedToClipboard, MsgBoxLangRes.ModlistCopiedToClipboard_Title, 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 49e20f6..a549a92 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs @@ -106,11 +106,20 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Generate modlist ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Generate modlist excel file ähnelt. /// - internal static string GenerateModlistFeature { + internal static string GenerateModlistAsExcelFeature { get { - return ResourceManager.GetString("GenerateModlistFeature", resourceCulture); + return ResourceManager.GetString("GenerateModlistAsExcelFeature", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Generate modlist markdown table ähnelt. + /// + internal static string GenerateModlistAsMarkdownFeature { + get { + return ResourceManager.GetString("GenerateModlistAsMarkdownFeature", resourceCulture); } } diff --git a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx index 823ec55..ce1cf1c 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx @@ -132,8 +132,11 @@ Generate changelog - - Generate modlist + + Generate modlist excel file + + + Generate modlist markdown table GitLab workspace diff --git a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs index 702aaef..d3d3e26 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 and copied to the clipboard. ähnelt. + /// + internal static string ModlistCopiedToClipboard { + get { + return ResourceManager.GetString("ModlistCopiedToClipboard", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Modlist generated successfully ähnelt. + /// + internal static string ModlistCopiedToClipboard_Title { + get { + return ResourceManager.GetString("ModlistCopiedToClipboard_Title", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die The modlist has been generated successfully and saved to the selected location. ähnelt. /// diff --git a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx index 9651f10..4b6b952 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 and copied to the clipboard. + + + Modlist generated successfully + The modlist has been generated successfully and saved to the selected location.