From 8561fdb09b653bc37872b66d138bab99cb7986c9 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Sun, 13 Oct 2024 09:22:19 +0200 Subject: [PATCH] add simple generate changelog feature --- .../Features/SharedFunctions.cs | 50 ++++++++++++++++++- .../Tools/GenerateChangelogFeature.cs | 31 ++++++++++++ .../LangRes/FeatureNamesLangRes.Designer.cs | 9 ++++ .../LangRes/FeatureNamesLangRes.resx | 3 ++ .../LangRes/MsgBoxLangRes.Designer.cs | 18 +++++++ .../LangRes/MsgBoxLangRes.resx | 6 +++ 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 ModpackUpdater.Apps.Manager/Features/Tools/GenerateChangelogFeature.cs diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index 492fce4..9a41916 100644 --- a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs +++ b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs @@ -1,7 +1,9 @@ -using ModpackUpdater.Apps.Manager.Api.Model; +using Microsoft.Extensions.Primitives; +using ModpackUpdater.Apps.Manager.Api.Model; using ModpackUpdater.Apps.Manager.Ui; using ModpackUpdater.Manager; using Pilz.UI.Extensions; +using System.Text; using Telerik.WinControls.UI; namespace ModpackUpdater.Apps.Manager.Features; @@ -154,4 +156,50 @@ internal static class SharedFunctions gridView?.EndUpdate(); rwb?.StopWaiting(); } + + public static string GenerateChangelog(InstallInfos installInfos, UpdateInfo updateInfos) + { + var log = new StringBuilder(); + + foreach (var action in updateInfos.Actions.OrderBy(n => n.Type)) + { + // Create copy + var copy = new UpdateAction(); + ModpackInstaller.DuplicateTo(action, copy); + + // Resolve inherit + if (!string.IsNullOrWhiteSpace(copy.InheritFrom)) + ModpackInstaller.ResolveInherit(copy, installInfos); + + if (string.IsNullOrWhiteSpace(copy.Name) || copy.Type != UpdateActionType.Update) + continue; + + // Append bullet + log.Append('-'); + + // Append action indicator + log.Append(' '); + log.Append("⚒️"); + + // Append name + log.Append(' '); + log.Append("**"); + log.Append(copy.Name); + log.Append("**"); + + // Append new version + if (!string.IsNullOrWhiteSpace(copy.SourceTag)) + { + log.Append(' '); + log.Append('`'); + log.Append(copy.SourceTag); + log.Append('`'); + } + + // Append new line + log.AppendLine(); + } + + return log.ToString().TrimEnd(); + } } diff --git a/ModpackUpdater.Apps.Manager/Features/Tools/GenerateChangelogFeature.cs b/ModpackUpdater.Apps.Manager/Features/Tools/GenerateChangelogFeature.cs new file mode 100644 index 0000000..c210828 --- /dev/null +++ b/ModpackUpdater.Apps.Manager/Features/Tools/GenerateChangelogFeature.cs @@ -0,0 +1,31 @@ +using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; +using Pilz.Plugins.Advanced; +using Telerik.WinControls; + +namespace ModpackUpdater.Apps.Manager.Features.Tools; + +internal class GenerateChangelogFeature : PluginFunction, IPluginFeatureProvider +{ + public static GenerateChangelogFeature Instance { get; } = new(); + + public GenerateChangelogFeature() : base(FeatureTypes.Tools, "origin.genchangelog", FeatureNamesLangRes.GenerateChangelogFeature) + { + Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.time_machine, 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.CurActionSet is not UpdateInfo updateInfos) + return null; + + var changelog = SharedFunctions.GenerateChangelog(p.Api.CurWorkspace.InstallInfos, updateInfos); + if (!string.IsNullOrWhiteSpace(changelog)) + { + Clipboard.SetText(changelog); + RadMessageBox.Show(p.Api.MainWindow, MsgBoxLangRes.ChangelogCopiedToClipboard, MsgBoxLangRes.ChangelogCopiedToClipboard_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 16616a4..c62f4c4 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.Designer.cs @@ -96,6 +96,15 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Generate changelog ähnelt. + /// + internal static string GenerateChangelogFeature { + get { + return ResourceManager.GetString("GenerateChangelogFeature", 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 9ac31bb..e002da2 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/FeatureNamesLangRes.resx @@ -129,6 +129,9 @@ Clear direct links + + Generate changelog + GitLab workspace diff --git a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs index 8504dae..f37a2a0 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs @@ -60,6 +60,24 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die The changelog for the selected version has been generated and copied to the clipboard. ähnelt. + /// + internal static string ChangelogCopiedToClipboard { + get { + return ResourceManager.GetString("ChangelogCopiedToClipboard", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Changelog generated successfully ähnelt. + /// + internal static string ChangelogCopiedToClipboard_Title { + get { + return ResourceManager.GetString("ChangelogCopiedToClipboard_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 092b398..a8cc55f 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + The changelog for the selected version has been generated and copied to the clipboard. + + + Changelog generated successfully + Are you sure that you want to delete this update?