From 9037166d92984267529b8a530fe668a3d8ae2ac3 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 15 Apr 2023 20:38:02 +0200 Subject: [PATCH] Add some logging, fix som bugs --- OtterGui | 2 +- Penumbra/Api/PenumbraApi.cs | 2 +- Penumbra/Api/TempModManager.cs | 13 ++++++++++-- Penumbra/Collections/Cache/CollectionCache.cs | 10 ++++++---- .../Manager/TempCollectionManager.cs | 7 +++++++ .../Collections/ModCollection.Cache.Access.cs | 3 +-- Penumbra/Interop/Services/GameEventManager.cs | 2 +- Penumbra/Mods/Manager/ModCacheManager.cs | 20 +++++++++---------- Penumbra/Mods/ModCache.cs | 20 +++++++++---------- Penumbra/UI/AdvancedWindow/ItemSwapTab.cs | 2 +- Penumbra/UI/ModsTab/ModFileSystemSelector.cs | 2 +- Penumbra/UI/Tabs/CollectionsTab.cs | 16 +++++++-------- 12 files changed, 58 insertions(+), 41 deletions(-) diff --git a/OtterGui b/OtterGui index 36c2f5f7..8ebcbf3e 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit 36c2f5f7e5af017b4ce6737f0ef7add873335cc7 +Subproject commit 8ebcbf3e78ed498be35fa2b9a13d9765d109c428 diff --git a/Penumbra/Api/PenumbraApi.cs b/Penumbra/Api/PenumbraApi.cs index 40b135e5..8d1f7a10 100644 --- a/Penumbra/Api/PenumbraApi.cs +++ b/Penumbra/Api/PenumbraApi.cs @@ -834,7 +834,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi public PenumbraApiEc CreateNamedTemporaryCollection(string name) { CheckInitialized(); - if (name.Length == 0 || ModCreator.ReplaceBadXivSymbols(name) != name) + if (name.Length == 0 || ModCreator.ReplaceBadXivSymbols(name) != name || name.Contains('|')) return PenumbraApiEc.InvalidArgument; return _tempCollections.CreateTemporaryCollection(name).Length > 0 diff --git a/Penumbra/Api/TempModManager.cs b/Penumbra/Api/TempModManager.cs index 747d49cd..c28a10f7 100644 --- a/Penumbra/Api/TempModManager.cs +++ b/Penumbra/Api/TempModManager.cs @@ -44,7 +44,8 @@ public class TempModManager : IDisposable public RedirectResult Register(string tag, ModCollection? collection, Dictionary dict, HashSet manips, int priority) { - var mod = GetOrCreateMod(tag, collection, priority, out var created); + var mod = GetOrCreateMod(tag, collection, priority, out var created); + Penumbra.Log.Verbose($"{(created ? "Created" : "Changed")} temporary Mod {mod.Name}."); mod.SetAll(dict, manips); ApplyModChange(mod, collection, created, false); return RedirectResult.Success; @@ -52,10 +53,11 @@ public class TempModManager : IDisposable public RedirectResult Unregister(string tag, ModCollection? collection, int? priority) { + Penumbra.Log.Verbose($"Removing temporary mod with tag {tag}..."); var list = collection == null ? _modsForAllCollections : _mods.TryGetValue(collection, out var l) ? l : null; if (list == null) return RedirectResult.NotRegistered; - + var removed = list.RemoveAll(m => { if (m.Name != tag || priority != null && m.Priority != priority.Value) @@ -80,12 +82,19 @@ public class TempModManager : IDisposable if (collection != null) { if (removed) + { + Penumbra.Log.Verbose($"Removing temporary Mod {mod.Name} from {collection.AnonymizedName}."); collection.Remove(mod); + } else + { + Penumbra.Log.Verbose($"Adding {(created ? "new " : string.Empty)}temporary Mod {mod.Name} to {collection.AnonymizedName}."); collection.Apply(mod, created); + } } else { + Penumbra.Log.Verbose($"Triggering global mod change for {(created ? "new " : string.Empty)}temporary Mod {mod.Name}."); _communicator.TemporaryGlobalModChange.Invoke(mod, created, removed); } } diff --git a/Penumbra/Collections/Cache/CollectionCache.cs b/Penumbra/Collections/Cache/CollectionCache.cs index de95cae6..7c58e5bf 100644 --- a/Penumbra/Collections/Cache/CollectionCache.cs +++ b/Penumbra/Collections/Cache/CollectionCache.cs @@ -19,12 +19,13 @@ public record ModConflicts(IMod Mod2, List Conflicts, bool HasPriority, /// The Cache contains all required temporary data to use a collection. /// It will only be setup if a collection gets activated in any way. /// -public class ModCollectionCache : IDisposable +public class CollectionCache : IDisposable { + private readonly CollectionCacheManager _manager; private readonly ModCollection _collection; public readonly SortedList, object?)> _changedItems = new(); public readonly Dictionary ResolvedFiles = new(); - public readonly MetaCache MetaManipulations; + public readonly MetaCache MetaManipulations; public readonly Dictionary> _conflicts = new(); public IEnumerable> AllConflicts @@ -46,8 +47,9 @@ public class ModCollectionCache : IDisposable } // The cache reacts through events on its collection changing. - public ModCollectionCache(ModCollection collection) + public CollectionCache(CollectionCacheManager manager, ModCollection collection) { + _manager = manager; _collection = collection; MetaManipulations = new MetaCache(_collection); } @@ -205,7 +207,7 @@ public class ModCollectionCache : IDisposable if (addMetaChanges) { ++_collection.ChangeCounter; - if (Penumbra.ModCaches[mod.Index].TotalManipulations > 0) + if ((mod is TemporaryMod temp ? temp.TotalManipulations : Penumbra.ModCaches[mod.Index].TotalManipulations) > 0) AddMetaFiles(); if (_collection == Penumbra.CollectionManager.Active.Default && Penumbra.CharacterUtility.Ready && Penumbra.Config.EnableMods) diff --git a/Penumbra/Collections/Manager/TempCollectionManager.cs b/Penumbra/Collections/Manager/TempCollectionManager.cs index 8c64c8e0..29733382 100644 --- a/Penumbra/Collections/Manager/TempCollectionManager.cs +++ b/Penumbra/Collections/Manager/TempCollectionManager.cs @@ -53,6 +53,7 @@ public class TempCollectionManager : IDisposable if (GlobalChangeCounter == int.MaxValue) GlobalChangeCounter = 0; var collection = ModCollection.CreateTemporary(name, ~Count, GlobalChangeCounter++); + Penumbra.Log.Debug($"Creating temporary collection {collection.AnonymizedName}."); if (_customCollections.TryAdd(collection.Name.ToLowerInvariant(), collection)) { // Temporary collection created. @@ -66,8 +67,12 @@ public class TempCollectionManager : IDisposable public bool RemoveTemporaryCollection(string collectionName) { if (!_customCollections.Remove(collectionName.ToLowerInvariant(), out var collection)) + { + Penumbra.Log.Debug($"Tried to delete temporary collection {collectionName.ToLowerInvariant()}, but did not exist."); return false; + } + Penumbra.Log.Debug($"Deleted temporary collection {collection.AnonymizedName}."); GlobalChangeCounter += Math.Max(collection.ChangeCounter + 1 - GlobalChangeCounter, 0); for (var i = 0; i < Collections.Count; ++i) { @@ -76,6 +81,7 @@ public class TempCollectionManager : IDisposable // Temporary collection assignment removed. _communicator.CollectionChange.Invoke(CollectionType.Temporary, collection, null, Collections[i].DisplayName); + Penumbra.Log.Verbose($"Unassigned temporary collection {collection.AnonymizedName} from {Collections[i].DisplayName}."); Collections.Delete(i--); } @@ -88,6 +94,7 @@ public class TempCollectionManager : IDisposable return false; // Temporary collection assignment added. + Penumbra.Log.Verbose($"Assigned temporary collection {collection.AnonymizedName} to {Collections.Last().DisplayName}."); _communicator.CollectionChange.Invoke(CollectionType.Temporary, null, collection, Collections.Last().DisplayName); return true; diff --git a/Penumbra/Collections/ModCollection.Cache.Access.cs b/Penumbra/Collections/ModCollection.Cache.Access.cs index f0bb1f29..f37d9163 100644 --- a/Penumbra/Collections/ModCollection.Cache.Access.cs +++ b/Penumbra/Collections/ModCollection.Cache.Access.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; -using System.Threading; using Penumbra.Interop.Structs; using Penumbra.Meta.Files; using Penumbra.Meta.Manipulations; @@ -19,7 +18,7 @@ namespace Penumbra.Collections; public partial class ModCollection { // Only active collections need to have a cache. - internal ModCollectionCache? _cache; + internal CollectionCache? _cache; public bool HasCache => _cache != null; diff --git a/Penumbra/Interop/Services/GameEventManager.cs b/Penumbra/Interop/Services/GameEventManager.cs index ed28f5e7..dcd5585f 100644 --- a/Penumbra/Interop/Services/GameEventManager.cs +++ b/Penumbra/Interop/Services/GameEventManager.cs @@ -129,7 +129,7 @@ public unsafe class GameEventManager : IDisposable } } - Penumbra.Log.Verbose($"{Prefix} {nameof(ResourceHandleDestructor)} triggered with 0x{(nint)handle:X}."); + Penumbra.Log.Excessive($"{Prefix} {nameof(ResourceHandleDestructor)} triggered with 0x{(nint)handle:X}."); return _resourceHandleDestructorHook!.Original(handle); } diff --git a/Penumbra/Mods/Manager/ModCacheManager.cs b/Penumbra/Mods/Manager/ModCacheManager.cs index a133e9ed..6ef43454 100644 --- a/Penumbra/Mods/Manager/ModCacheManager.cs +++ b/Penumbra/Mods/Manager/ModCacheManager.cs @@ -15,16 +15,16 @@ namespace Penumbra.Mods.Manager; public class ModCacheManager : IDisposable, IReadOnlyList { private readonly CommunicatorService _communicator; - private readonly IdentifierService _identifier; - private readonly IReadOnlyList _modManager; + private readonly IdentifierService _identifier; + private readonly ModStorage _modManager; private readonly List _cache = new(); - public ModCacheManager(CommunicatorService communicator, IdentifierService identifier, ModManager modManager) + public ModCacheManager(CommunicatorService communicator, IdentifierService identifier, ModStorage modStorage) { _communicator = communicator; - _identifier = identifier; - _modManager = modManager; + _identifier = identifier; + _modManager = modStorage; _communicator.ModOptionChanged.Subscribe(OnModOptionChange); _communicator.ModPathChanged.Subscribe(OnModPathChange); @@ -232,17 +232,17 @@ public class ModCacheManager : IDisposable, IReadOnlyList private static void UpdateCounts(ModCache cache, Mod mod) { - cache.TotalFileCount = mod.Default.Files.Count; - cache.TotalSwapCount = mod.Default.FileSwaps.Count; + cache.TotalFileCount = mod.Default.Files.Count; + cache.TotalSwapCount = mod.Default.FileSwaps.Count; cache.TotalManipulations = mod.Default.Manipulations.Count; - cache.HasOptions = false; + cache.HasOptions = false; foreach (var group in mod.Groups) { cache.HasOptions |= group.IsOption; foreach (var s in group) { - cache.TotalFileCount += s.Files.Count; - cache.TotalSwapCount += s.FileSwaps.Count; + cache.TotalFileCount += s.Files.Count; + cache.TotalSwapCount += s.FileSwaps.Count; cache.TotalManipulations += s.Manipulations.Count; } } diff --git a/Penumbra/Mods/ModCache.cs b/Penumbra/Mods/ModCache.cs index e6848034..76e01bf6 100644 --- a/Penumbra/Mods/ModCache.cs +++ b/Penumbra/Mods/ModCache.cs @@ -4,23 +4,23 @@ namespace Penumbra.Mods; public class ModCache { - public int TotalFileCount; - public int TotalSwapCount; - public int TotalManipulations; + public int TotalFileCount; + public int TotalSwapCount; + public int TotalManipulations; public bool HasOptions; - public SortedList ChangedItems = new(); - public string LowerChangedItemsString = string.Empty; - public string AllTagsLower = string.Empty; + public readonly SortedList ChangedItems = new(); + public string LowerChangedItemsString = string.Empty; + public string AllTagsLower = string.Empty; public void Reset() { - TotalFileCount = 0; - TotalSwapCount = 0; + TotalFileCount = 0; + TotalSwapCount = 0; TotalManipulations = 0; - HasOptions = false; + HasOptions = false; ChangedItems.Clear(); LowerChangedItemsString = string.Empty; - AllTagsLower = string.Empty; + AllTagsLower = string.Empty; } } diff --git a/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs b/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs index 929a8276..1721480b 100644 --- a/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs +++ b/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs @@ -743,7 +743,7 @@ public class ItemSwapTab : IDisposable, ITab private void OnCollectionChange(CollectionType collectionType, ModCollection? oldCollection, ModCollection? newCollection, string _) { - if (collectionType != CollectionType.Current || _mod == null || newCollection == null) + if (collectionType is not CollectionType.Current || _mod == null || newCollection == null) return; UpdateMod(_mod, _mod.Index < newCollection.Settings.Count ? newCollection[_mod.Index].Settings : null); diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index c33003e4..448ddd00 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -395,7 +395,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector