From e7cf9d35c9ca7208423c95bc59fbfcddaa415df9 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 1 Jun 2024 23:33:21 +0200 Subject: [PATCH] Add GetChangedItems for Mods. --- Penumbra.Api | 2 +- Penumbra/Api/Api/ModsApi.cs | 9 +++-- Penumbra/Api/Api/PenumbraApi.cs | 2 +- Penumbra/Api/IpcProviders.cs | 1 + Penumbra/Api/IpcTester/ModsIpcTester.cs | 44 +++++++++++++++++++------ 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Penumbra.Api b/Penumbra.Api index 69d106b4..f1e4e520 160000 --- a/Penumbra.Api +++ b/Penumbra.Api @@ -1 +1 @@ -Subproject commit 69d106b457eb0f73d4b4caf1234da5631fd6fbf0 +Subproject commit f1e4e520daaa8f23e5c8b71d55e5992b8f6768e2 diff --git a/Penumbra/Api/Api/ModsApi.cs b/Penumbra/Api/Api/ModsApi.cs index c1e0c684..16dd8be9 100644 --- a/Penumbra/Api/Api/ModsApi.cs +++ b/Penumbra/Api/Api/ModsApi.cs @@ -106,8 +106,8 @@ public class ModsApi : IPenumbraApiMods, IApiService, IDisposable var fullPath = leaf.FullName(); var isDefault = ModFileSystem.ModHasDefaultPath(mod, fullPath); - var isNameDefault = isDefault || ModFileSystem.ModHasDefaultPath(mod, leaf.Name); - return (PenumbraApiEc.Success, fullPath, !isDefault, !isNameDefault ); + var isNameDefault = isDefault || ModFileSystem.ModHasDefaultPath(mod, leaf.Name); + return (PenumbraApiEc.Success, fullPath, !isDefault, !isNameDefault); } public PenumbraApiEc SetModPath(string modDirectory, string modName, string newPath) @@ -129,4 +129,9 @@ public class ModsApi : IPenumbraApiMods, IApiService, IDisposable return PenumbraApiEc.PathRenameFailed; } } + + public Dictionary GetChangedItems(string modDirectory, string modName) + => _modManager.TryGetMod(modDirectory, modName, out var mod) + ? mod.ChangedItems.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) + : []; } diff --git a/Penumbra/Api/Api/PenumbraApi.cs b/Penumbra/Api/Api/PenumbraApi.cs index 1d5b1537..0400c694 100644 --- a/Penumbra/Api/Api/PenumbraApi.cs +++ b/Penumbra/Api/Api/PenumbraApi.cs @@ -22,7 +22,7 @@ public class PenumbraApi( } public (int Breaking, int Feature) ApiVersion - => (5, 0); + => (5, 1); public bool Valid { get; private set; } = true; public IPenumbraApiCollection Collection { get; } = collection; diff --git a/Penumbra/Api/IpcProviders.cs b/Penumbra/Api/IpcProviders.cs index ebf71176..6b146c39 100644 --- a/Penumbra/Api/IpcProviders.cs +++ b/Penumbra/Api/IpcProviders.cs @@ -49,6 +49,7 @@ public sealed class IpcProviders : IDisposable, IApiService IpcSubscribers.ModMoved.Provider(pi, api.Mods), IpcSubscribers.GetModPath.Provider(pi, api.Mods), IpcSubscribers.SetModPath.Provider(pi, api.Mods), + IpcSubscribers.GetChangedItems.Provider(pi, api.Mods), IpcSubscribers.GetAvailableModSettings.Provider(pi, api.ModSettings), IpcSubscribers.GetCurrentModSettings.Provider(pi, api.ModSettings), diff --git a/Penumbra/Api/IpcTester/ModsIpcTester.cs b/Penumbra/Api/IpcTester/ModsIpcTester.cs index 43f397e5..2be51a80 100644 --- a/Penumbra/Api/IpcTester/ModsIpcTester.cs +++ b/Penumbra/Api/IpcTester/ModsIpcTester.cs @@ -3,6 +3,7 @@ using Dalamud.Plugin; using ImGuiNET; using OtterGui.Raii; using OtterGui.Services; +using OtterGui.Text; using Penumbra.Api.Enums; using Penumbra.Api.Helpers; using Penumbra.Api.IpcSubscribers; @@ -13,16 +14,17 @@ public class ModsIpcTester : IUiService, IDisposable { private readonly DalamudPluginInterface _pi; - private string _modDirectory = string.Empty; - private string _modName = string.Empty; - private string _pathInput = string.Empty; - private string _newInstallPath = string.Empty; - private PenumbraApiEc _lastReloadEc; - private PenumbraApiEc _lastAddEc; - private PenumbraApiEc _lastDeleteEc; - private PenumbraApiEc _lastSetPathEc; - private PenumbraApiEc _lastInstallEc; - private Dictionary _mods = []; + private string _modDirectory = string.Empty; + private string _modName = string.Empty; + private string _pathInput = string.Empty; + private string _newInstallPath = string.Empty; + private PenumbraApiEc _lastReloadEc; + private PenumbraApiEc _lastAddEc; + private PenumbraApiEc _lastDeleteEc; + private PenumbraApiEc _lastSetPathEc; + private PenumbraApiEc _lastInstallEc; + private Dictionary _mods = []; + private Dictionary _changedItems = []; public readonly EventSubscriber DeleteSubscriber; public readonly EventSubscriber AddSubscriber; @@ -120,6 +122,14 @@ public class ModsIpcTester : IUiService, IDisposable ImGui.SameLine(); ImGui.TextUnformatted(_lastDeleteEc.ToString()); + IpcTester.DrawIntro(GetChangedItems.Label, "Get Changed Items"); + DrawChangedItemsPopup(); + if (ImUtf8.Button("Get##ChangedItems"u8)) + { + _changedItems = new GetChangedItems(_pi).Invoke(_modDirectory, _modName); + ImUtf8.OpenPopup("ChangedItems"u8); + } + IpcTester.DrawIntro(GetModPath.Label, "Current Path"); var (ec, path, def, nameDef) = new GetModPath(_pi).Invoke(_modDirectory, _modName); ImGui.TextUnformatted($"{path} ({(def ? "Custom" : "Default")} Path, {(nameDef ? "Custom" : "Default")} Name) [{ec}]"); @@ -157,4 +167,18 @@ public class ModsIpcTester : IUiService, IDisposable if (ImGui.Button("Close", -Vector2.UnitX) || !ImGui.IsWindowFocused()) ImGui.CloseCurrentPopup(); } + + private void DrawChangedItemsPopup() + { + ImGui.SetNextWindowSize(ImGuiHelpers.ScaledVector2(500, 500)); + using var p = ImUtf8.Popup("ChangedItems"u8); + if (!p) + return; + + foreach (var (name, data) in _changedItems) + ImUtf8.Text($"{name}: {data}"); + + if (ImUtf8.Button("Close"u8, -Vector2.UnitX) || !ImGui.IsWindowFocused()) + ImGui.CloseCurrentPopup(); + } }