From 74517d8ec5dc17e3a2023782cd5d55f441797b1f Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 24 Jan 2026 15:23:20 +0100 Subject: [PATCH] Add ModUsage subscription. --- .../Interop/Penumbra/ModUsageInformer.cs | 58 +++++++++++++++++++ Glamourer/Interop/Penumbra/PenumbraService.cs | 28 +++++---- Penumbra.Api | 2 +- 3 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 Glamourer/Interop/Penumbra/ModUsageInformer.cs diff --git a/Glamourer/Interop/Penumbra/ModUsageInformer.cs b/Glamourer/Interop/Penumbra/ModUsageInformer.cs new file mode 100644 index 0000000..f6d992e --- /dev/null +++ b/Glamourer/Interop/Penumbra/ModUsageInformer.cs @@ -0,0 +1,58 @@ +using Glamourer.Automation; +using Glamourer.Designs; +using OtterGui.Services; + +namespace Glamourer.Interop.Penumbra; + +public sealed class ModUsageInformer : IDisposable, IRequiredService +{ + private readonly PenumbraService _penumbra; + private readonly DesignManager _designs; + private readonly AutoDesignManager _automation; + + public ModUsageInformer(PenumbraService penumbra, DesignManager designs, AutoDesignManager automation) + { + _penumbra = penumbra; + _designs = designs; + _automation = automation; + + _penumbra.ModUsageQueried += OnModUsageQueried; + } + + private void OnModUsageQueried(string modPath, string modName, Dictionary notes) + { + var sb = new StringBuilder(); + var inUse = false; + foreach (var design in _designs.Designs) + { + if (!design.AssociatedMods.Any(p => ModMatches(modPath, modName, p.Key))) + continue; + + sb.AppendLine($"Contained in Design {design.Name}."); + if (_automation.EnabledSets.Values.Any(s => s.Designs.Any(d => d.Type is not 0 && d.Design == design))) + { + inUse = true; + break; + } + } + + if (inUse) + notes.TryAdd(Assembly.GetAssembly(typeof(ModUsageInformer))!, (true, string.Empty)); + else if (sb.Length > 0) + notes.TryAdd(Assembly.GetAssembly(typeof(ModUsageInformer))!, (false, sb.ToString())); + } + + private static bool ModMatches(string modPath, string modName, in Mod mod) + { + if (mod.DirectoryName.Equals(modPath, StringComparison.OrdinalIgnoreCase)) + return true; + + if (mod.Name.Equals(modName, StringComparison.OrdinalIgnoreCase)) + return true; + + return false; + } + + public void Dispose() + => _penumbra.ModUsageQueried -= OnModUsageQueried; +} diff --git a/Glamourer/Interop/Penumbra/PenumbraService.cs b/Glamourer/Interop/Penumbra/PenumbraService.cs index b2813cd..b43a0b5 100644 --- a/Glamourer/Interop/Penumbra/PenumbraService.cs +++ b/Glamourer/Interop/Penumbra/PenumbraService.cs @@ -44,15 +44,16 @@ public class PenumbraService : IDisposable private const int KeyManual = -6160; private const string NameManual = "Glamourer (Manually)"; - private readonly IDalamudPluginInterface _pluginInterface; - private readonly Configuration _config; - private readonly EventSubscriber _tooltipSubscriber; - private readonly EventSubscriber _clickSubscriber; - private readonly EventSubscriber _creatingCharacterBase; - private readonly EventSubscriber _createdCharacterBase; - private readonly EventSubscriber _modSettingChanged; - private readonly EventSubscriber _pcpParsed; - private readonly EventSubscriber _pcpCreated; + private readonly IDalamudPluginInterface _pluginInterface; + private readonly Configuration _config; + private readonly EventSubscriber _tooltipSubscriber; + private readonly EventSubscriber _clickSubscriber; + private readonly EventSubscriber _creatingCharacterBase; + private readonly EventSubscriber _createdCharacterBase; + private readonly EventSubscriber _modSettingChanged; + private readonly EventSubscriber _pcpParsed; + private readonly EventSubscriber _pcpCreated; + private readonly EventSubscriber> _modUsageQueried; private global::Penumbra.Api.IpcSubscribers.GetCollectionsByIdentifier? _collectionByIdentifier; private global::Penumbra.Api.IpcSubscribers.GetCollections? _collections; @@ -109,6 +110,7 @@ public class PenumbraService : IDisposable _modSettingChanged = global::Penumbra.Api.IpcSubscribers.ModSettingChanged.Subscriber(pi); _pcpCreated = global::Penumbra.Api.IpcSubscribers.CreatingPcp.Subscriber(pi); _pcpParsed = global::Penumbra.Api.IpcSubscribers.ParsingPcp.Subscriber(pi); + _modUsageQueried = global::Penumbra.Api.IpcSubscribers.ModUsageQueried.Subscriber(pi); Reattach(); } @@ -155,6 +157,12 @@ public class PenumbraService : IDisposable remove => _pcpParsed.Event -= value; } + public event Action> ModUsageQueried + { + add => _modUsageQueried.Event += value; + remove => _modUsageQueried.Event -= value; + } + public event Action? DrawSettingsSection; private void InvokeDrawSettingsSection() @@ -573,7 +581,7 @@ public class PenumbraService : IDisposable _changedItems = new global::Penumbra.Api.IpcSubscribers.GetChangedItemAdapterList(_pluginInterface).Invoke(); _checkCurrentChangedItems = new global::Penumbra.Api.IpcSubscribers.CheckCurrentChangedItemFunc(_pluginInterface).Invoke(); - _registerSettingsSection = new global::Penumbra.Api.IpcSubscribers.RegisterSettingsSection(_pluginInterface); + _registerSettingsSection = new global::Penumbra.Api.IpcSubscribers.RegisterSettingsSection(_pluginInterface); _unregisterSettingsSection = new global::Penumbra.Api.IpcSubscribers.UnregisterSettingsSection(_pluginInterface); _registerSettingsSection.Invoke(InvokeDrawSettingsSection); diff --git a/Penumbra.Api b/Penumbra.Api index 52a3216..a79ff8d 160000 --- a/Penumbra.Api +++ b/Penumbra.Api @@ -1 +1 @@ -Subproject commit 52a3216a525592205198303df2844435e382cf87 +Subproject commit a79ff8d87c5b1ac12192f18563fb4247173ff4f0