From e31ede6ca4abd3edbf9391842981b0a9f45ea2a4 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 24 Oct 2023 17:06:46 -0400 Subject: [PATCH] feat: add version to breaking change --- DownloadTask.cs | 13 ++++++++++++- PackageState.cs | 8 ++++++++ Ui/BreakingChangeWindow.cs | 25 ++++++++++++++----------- Util/IReadOnlyListExt.cs | 10 ++++++++++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/DownloadTask.cs b/DownloadTask.cs index 1d02bd9..9ee197e 100644 --- a/DownloadTask.cs +++ b/DownloadTask.cs @@ -972,9 +972,20 @@ private async Task ConstructGroups(IDownloadTask_GetVersion info) { return allSettings; }); + var oldVersion = "???"; + var installedPkgs = await this.Plugin.State.GetInstalled(); + if (installedPkgs.TryGetValue(info.Variant.Package.Id, out var meta)) { + var variant = meta.Variants.Find(v => v.Id == info.Variant.Id); + if (variant != null) { + oldVersion = variant.Version; + } + } + var change = new BreakingChange { ModName = info.Variant.Package.Name, VariantName = info.Variant.Name, + OldVersion = oldVersion, + NewVersion = info.Version, ModPath = HeliosphereMeta.ModDirectoryName(info.Variant.Package.Id, info.Variant.Package.Name, info.Version, info.Variant.Id), }; @@ -1282,4 +1293,4 @@ public override long Position { get => this._inner.Position; set => this._inner.Position = value; } -} \ No newline at end of file +} diff --git a/PackageState.cs b/PackageState.cs index cdcc836..ae50e80 100644 --- a/PackageState.cs +++ b/PackageState.cs @@ -92,6 +92,14 @@ public void Dispose() { this.InstalledInternal.Dispose(); } + internal async Task> GetInstalled(CancellationToken token = default) { + using var guard = await this.InstalledInternal.WaitAsync(token); + return guard.Data.ToImmutableDictionary( + entry => entry.Key, + entry => entry.Value + ); + } + internal async Task UpdatePackages() { // get the current update number. if this changes by the time this task // gets a lock on the update mutex, the update that this task was queued diff --git a/Ui/BreakingChangeWindow.cs b/Ui/BreakingChangeWindow.cs index a099407..efe59e9 100644 --- a/Ui/BreakingChangeWindow.cs +++ b/Ui/BreakingChangeWindow.cs @@ -53,7 +53,7 @@ private void Draw() { // draw each breaking change with a button to open that mod foreach (var change in changes.Data) { - if (!ImGui.TreeNodeEx($"{change.ModName} ({change.VariantName})", ImGuiTreeNodeFlags.DefaultOpen)) { + if (!ImGui.TreeNodeEx($"{change.ModName} ({change.VariantName}): {change.OldVersion} \u2192 {change.NewVersion}", ImGuiTreeNodeFlags.DefaultOpen)) { continue; } @@ -68,8 +68,8 @@ private void Draw() { if (ImGui.TreeNodeEx("Removed option groups", ImGuiTreeNodeFlags.DefaultOpen)) { using var pop3 = new OnDispose(ImGui.TreePop); - ImGui.TextUnformatted("These option groups are no longer available (but may be available under a different name), which means your settings for this group are no longer applied."); - ImGui.Spacing(); + ImGui.SameLine(); + ImGuiHelper.Help("These option groups are no longer available (but may be available under a different name), which means your settings for this group are no longer applied."); foreach (var group in change.RemovedGroups) { UnformattedBullet(group); @@ -81,8 +81,8 @@ private void Draw() { if (ImGui.TreeNodeEx("Changed group type", ImGuiTreeNodeFlags.DefaultOpen)) { using var pop3 = new OnDispose(ImGui.TreePop); - ImGui.TextUnformatted("These option groups have gone from single-select to multi-select or vice versa, which can change your selected options in unexpected ways."); - ImGui.Spacing(); + ImGui.SameLine(); + ImGuiHelper.Help("These option groups have gone from single-select to multi-select or vice versa, which can change your selected options in unexpected ways."); foreach (var group in change.ChangedType) { UnformattedBullet(group); @@ -94,8 +94,8 @@ private void Draw() { if (ImGui.TreeNodeEx("Removed options", ImGuiTreeNodeFlags.DefaultOpen)) { using var pop3 = new OnDispose(ImGui.TreePop); - ImGui.TextUnformatted("These option groups have had options removed from the end, which has unselected options you had enabled."); - ImGui.Spacing(); + ImGui.SameLine(); + ImGuiHelper.Help("These option groups have had options removed from the end, which has unselected options you had enabled."); foreach (var (group, options) in change.TruncatedOptions) { if (!ImGui.TreeNodeEx(group, ImGuiTreeNodeFlags.DefaultOpen)) { @@ -114,8 +114,8 @@ private void Draw() { if (ImGui.TreeNodeEx("Changed option names", ImGuiTreeNodeFlags.DefaultOpen)) { using var pop3 = new OnDispose(ImGui.TreePop); - ImGui.TextUnformatted("These option groups have had their option names changed, which may have unexpectedly changed what options you have selected."); - ImGui.Spacing(); + ImGui.SameLine(); + ImGuiHelper.Help("These option groups have had their option names changed, which may have unexpectedly changed what options you have selected."); foreach (var (group, _, _) in change.DifferentOptionNames) { UnformattedBullet(group); @@ -127,7 +127,8 @@ private void Draw() { if (ImGui.TreeNodeEx("Changed option order", ImGuiTreeNodeFlags.DefaultOpen)) { using var pop3 = new OnDispose(ImGui.TreePop); - ImGui.TextUnformatted("These option groups have had their options reordered, which may have unexpectedly changed what options you have selected."); + ImGui.SameLine(); + ImGuiHelper.Help("These option groups have had their options reordered, which may have unexpectedly changed what options you have selected."); ImGui.Spacing(); foreach (var (group, _, _) in change.ChangedOptionOrder) { @@ -150,6 +151,8 @@ void UnformattedBullet(string text) { internal class BreakingChange { internal required string ModName { get; init; } internal required string VariantName { get; init; } + internal required string OldVersion { get; init; } + internal required string NewVersion { get; init; } internal required string ModPath { get; init; } internal List RemovedGroups { get; } = new(); internal List ChangedType { get; } = new(); @@ -162,4 +165,4 @@ internal class BreakingChange { || this.TruncatedOptions.Count > 0 || this.DifferentOptionNames.Count > 0 || this.ChangedOptionOrder.Count > 0; -} \ No newline at end of file +} diff --git a/Util/IReadOnlyListExt.cs b/Util/IReadOnlyListExt.cs index 4038c04..4dc7b2f 100644 --- a/Util/IReadOnlyListExt.cs +++ b/Util/IReadOnlyListExt.cs @@ -1,6 +1,16 @@ namespace Heliosphere.Util; internal static class ReadOnlyListExt { + internal static T? Find(this IEnumerable list, Predicate predicate) { + foreach (var item in list) { + if (predicate(item)) { + return item; + } + } + + return default; + } + internal static int FindIndex(this IReadOnlyList list, Predicate predicate) { for (var i = 0; i < list.Count; i++) { if (predicate(list[i])) {