Add some logging, fix som bugs

This commit is contained in:
Ottermandias 2023-04-15 20:38:02 +02:00
parent 85fb98b557
commit 9037166d92
12 changed files with 58 additions and 41 deletions

@ -1 +1 @@
Subproject commit 36c2f5f7e5af017b4ce6737f0ef7add873335cc7 Subproject commit 8ebcbf3e78ed498be35fa2b9a13d9765d109c428

View file

@ -834,7 +834,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
public PenumbraApiEc CreateNamedTemporaryCollection(string name) public PenumbraApiEc CreateNamedTemporaryCollection(string name)
{ {
CheckInitialized(); CheckInitialized();
if (name.Length == 0 || ModCreator.ReplaceBadXivSymbols(name) != name) if (name.Length == 0 || ModCreator.ReplaceBadXivSymbols(name) != name || name.Contains('|'))
return PenumbraApiEc.InvalidArgument; return PenumbraApiEc.InvalidArgument;
return _tempCollections.CreateTemporaryCollection(name).Length > 0 return _tempCollections.CreateTemporaryCollection(name).Length > 0

View file

@ -44,7 +44,8 @@ public class TempModManager : IDisposable
public RedirectResult Register(string tag, ModCollection? collection, Dictionary<Utf8GamePath, FullPath> dict, public RedirectResult Register(string tag, ModCollection? collection, Dictionary<Utf8GamePath, FullPath> dict,
HashSet<MetaManipulation> manips, int priority) HashSet<MetaManipulation> 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); mod.SetAll(dict, manips);
ApplyModChange(mod, collection, created, false); ApplyModChange(mod, collection, created, false);
return RedirectResult.Success; return RedirectResult.Success;
@ -52,10 +53,11 @@ public class TempModManager : IDisposable
public RedirectResult Unregister(string tag, ModCollection? collection, int? priority) 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; var list = collection == null ? _modsForAllCollections : _mods.TryGetValue(collection, out var l) ? l : null;
if (list == null) if (list == null)
return RedirectResult.NotRegistered; return RedirectResult.NotRegistered;
var removed = list.RemoveAll(m => var removed = list.RemoveAll(m =>
{ {
if (m.Name != tag || priority != null && m.Priority != priority.Value) if (m.Name != tag || priority != null && m.Priority != priority.Value)
@ -80,12 +82,19 @@ public class TempModManager : IDisposable
if (collection != null) if (collection != null)
{ {
if (removed) if (removed)
{
Penumbra.Log.Verbose($"Removing temporary Mod {mod.Name} from {collection.AnonymizedName}.");
collection.Remove(mod); collection.Remove(mod);
}
else else
{
Penumbra.Log.Verbose($"Adding {(created ? "new " : string.Empty)}temporary Mod {mod.Name} to {collection.AnonymizedName}.");
collection.Apply(mod, created); collection.Apply(mod, created);
}
} }
else else
{ {
Penumbra.Log.Verbose($"Triggering global mod change for {(created ? "new " : string.Empty)}temporary Mod {mod.Name}.");
_communicator.TemporaryGlobalModChange.Invoke(mod, created, removed); _communicator.TemporaryGlobalModChange.Invoke(mod, created, removed);
} }
} }

View file

@ -19,12 +19,13 @@ public record ModConflicts(IMod Mod2, List<object> Conflicts, bool HasPriority,
/// The Cache contains all required temporary data to use a collection. /// The Cache contains all required temporary data to use a collection.
/// It will only be setup if a collection gets activated in any way. /// It will only be setup if a collection gets activated in any way.
/// </summary> /// </summary>
public class ModCollectionCache : IDisposable public class CollectionCache : IDisposable
{ {
private readonly CollectionCacheManager _manager;
private readonly ModCollection _collection; private readonly ModCollection _collection;
public readonly SortedList<string, (SingleArray<IMod>, object?)> _changedItems = new(); public readonly SortedList<string, (SingleArray<IMod>, object?)> _changedItems = new();
public readonly Dictionary<Utf8GamePath, ModPath> ResolvedFiles = new(); public readonly Dictionary<Utf8GamePath, ModPath> ResolvedFiles = new();
public readonly MetaCache MetaManipulations; public readonly MetaCache MetaManipulations;
public readonly Dictionary<IMod, SingleArray<ModConflicts>> _conflicts = new(); public readonly Dictionary<IMod, SingleArray<ModConflicts>> _conflicts = new();
public IEnumerable<SingleArray<ModConflicts>> AllConflicts public IEnumerable<SingleArray<ModConflicts>> AllConflicts
@ -46,8 +47,9 @@ public class ModCollectionCache : IDisposable
} }
// The cache reacts through events on its collection changing. // The cache reacts through events on its collection changing.
public ModCollectionCache(ModCollection collection) public CollectionCache(CollectionCacheManager manager, ModCollection collection)
{ {
_manager = manager;
_collection = collection; _collection = collection;
MetaManipulations = new MetaCache(_collection); MetaManipulations = new MetaCache(_collection);
} }
@ -205,7 +207,7 @@ public class ModCollectionCache : IDisposable
if (addMetaChanges) if (addMetaChanges)
{ {
++_collection.ChangeCounter; ++_collection.ChangeCounter;
if (Penumbra.ModCaches[mod.Index].TotalManipulations > 0) if ((mod is TemporaryMod temp ? temp.TotalManipulations : Penumbra.ModCaches[mod.Index].TotalManipulations) > 0)
AddMetaFiles(); AddMetaFiles();
if (_collection == Penumbra.CollectionManager.Active.Default && Penumbra.CharacterUtility.Ready && Penumbra.Config.EnableMods) if (_collection == Penumbra.CollectionManager.Active.Default && Penumbra.CharacterUtility.Ready && Penumbra.Config.EnableMods)

View file

@ -53,6 +53,7 @@ public class TempCollectionManager : IDisposable
if (GlobalChangeCounter == int.MaxValue) if (GlobalChangeCounter == int.MaxValue)
GlobalChangeCounter = 0; GlobalChangeCounter = 0;
var collection = ModCollection.CreateTemporary(name, ~Count, GlobalChangeCounter++); var collection = ModCollection.CreateTemporary(name, ~Count, GlobalChangeCounter++);
Penumbra.Log.Debug($"Creating temporary collection {collection.AnonymizedName}.");
if (_customCollections.TryAdd(collection.Name.ToLowerInvariant(), collection)) if (_customCollections.TryAdd(collection.Name.ToLowerInvariant(), collection))
{ {
// Temporary collection created. // Temporary collection created.
@ -66,8 +67,12 @@ public class TempCollectionManager : IDisposable
public bool RemoveTemporaryCollection(string collectionName) public bool RemoveTemporaryCollection(string collectionName)
{ {
if (!_customCollections.Remove(collectionName.ToLowerInvariant(), out var collection)) if (!_customCollections.Remove(collectionName.ToLowerInvariant(), out var collection))
{
Penumbra.Log.Debug($"Tried to delete temporary collection {collectionName.ToLowerInvariant()}, but did not exist.");
return false; return false;
}
Penumbra.Log.Debug($"Deleted temporary collection {collection.AnonymizedName}.");
GlobalChangeCounter += Math.Max(collection.ChangeCounter + 1 - GlobalChangeCounter, 0); GlobalChangeCounter += Math.Max(collection.ChangeCounter + 1 - GlobalChangeCounter, 0);
for (var i = 0; i < Collections.Count; ++i) for (var i = 0; i < Collections.Count; ++i)
{ {
@ -76,6 +81,7 @@ public class TempCollectionManager : IDisposable
// Temporary collection assignment removed. // Temporary collection assignment removed.
_communicator.CollectionChange.Invoke(CollectionType.Temporary, collection, null, Collections[i].DisplayName); _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--); Collections.Delete(i--);
} }
@ -88,6 +94,7 @@ public class TempCollectionManager : IDisposable
return false; return false;
// Temporary collection assignment added. // 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); _communicator.CollectionChange.Invoke(CollectionType.Temporary, null, collection, Collections.Last().DisplayName);
return true; return true;

View file

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading;
using Penumbra.Interop.Structs; using Penumbra.Interop.Structs;
using Penumbra.Meta.Files; using Penumbra.Meta.Files;
using Penumbra.Meta.Manipulations; using Penumbra.Meta.Manipulations;
@ -19,7 +18,7 @@ namespace Penumbra.Collections;
public partial class ModCollection public partial class ModCollection
{ {
// Only active collections need to have a cache. // Only active collections need to have a cache.
internal ModCollectionCache? _cache; internal CollectionCache? _cache;
public bool HasCache public bool HasCache
=> _cache != null; => _cache != null;

View file

@ -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); return _resourceHandleDestructorHook!.Original(handle);
} }

View file

@ -15,16 +15,16 @@ namespace Penumbra.Mods.Manager;
public class ModCacheManager : IDisposable, IReadOnlyList<ModCache> public class ModCacheManager : IDisposable, IReadOnlyList<ModCache>
{ {
private readonly CommunicatorService _communicator; private readonly CommunicatorService _communicator;
private readonly IdentifierService _identifier; private readonly IdentifierService _identifier;
private readonly IReadOnlyList<Mod> _modManager; private readonly ModStorage _modManager;
private readonly List<ModCache> _cache = new(); private readonly List<ModCache> _cache = new();
public ModCacheManager(CommunicatorService communicator, IdentifierService identifier, ModManager modManager) public ModCacheManager(CommunicatorService communicator, IdentifierService identifier, ModStorage modStorage)
{ {
_communicator = communicator; _communicator = communicator;
_identifier = identifier; _identifier = identifier;
_modManager = modManager; _modManager = modStorage;
_communicator.ModOptionChanged.Subscribe(OnModOptionChange); _communicator.ModOptionChanged.Subscribe(OnModOptionChange);
_communicator.ModPathChanged.Subscribe(OnModPathChange); _communicator.ModPathChanged.Subscribe(OnModPathChange);
@ -232,17 +232,17 @@ public class ModCacheManager : IDisposable, IReadOnlyList<ModCache>
private static void UpdateCounts(ModCache cache, Mod mod) private static void UpdateCounts(ModCache cache, Mod mod)
{ {
cache.TotalFileCount = mod.Default.Files.Count; cache.TotalFileCount = mod.Default.Files.Count;
cache.TotalSwapCount = mod.Default.FileSwaps.Count; cache.TotalSwapCount = mod.Default.FileSwaps.Count;
cache.TotalManipulations = mod.Default.Manipulations.Count; cache.TotalManipulations = mod.Default.Manipulations.Count;
cache.HasOptions = false; cache.HasOptions = false;
foreach (var group in mod.Groups) foreach (var group in mod.Groups)
{ {
cache.HasOptions |= group.IsOption; cache.HasOptions |= group.IsOption;
foreach (var s in group) foreach (var s in group)
{ {
cache.TotalFileCount += s.Files.Count; cache.TotalFileCount += s.Files.Count;
cache.TotalSwapCount += s.FileSwaps.Count; cache.TotalSwapCount += s.FileSwaps.Count;
cache.TotalManipulations += s.Manipulations.Count; cache.TotalManipulations += s.Manipulations.Count;
} }
} }

View file

@ -4,23 +4,23 @@ namespace Penumbra.Mods;
public class ModCache public class ModCache
{ {
public int TotalFileCount; public int TotalFileCount;
public int TotalSwapCount; public int TotalSwapCount;
public int TotalManipulations; public int TotalManipulations;
public bool HasOptions; public bool HasOptions;
public SortedList<string, object?> ChangedItems = new(); public readonly SortedList<string, object?> ChangedItems = new();
public string LowerChangedItemsString = string.Empty; public string LowerChangedItemsString = string.Empty;
public string AllTagsLower = string.Empty; public string AllTagsLower = string.Empty;
public void Reset() public void Reset()
{ {
TotalFileCount = 0; TotalFileCount = 0;
TotalSwapCount = 0; TotalSwapCount = 0;
TotalManipulations = 0; TotalManipulations = 0;
HasOptions = false; HasOptions = false;
ChangedItems.Clear(); ChangedItems.Clear();
LowerChangedItemsString = string.Empty; LowerChangedItemsString = string.Empty;
AllTagsLower = string.Empty; AllTagsLower = string.Empty;
} }
} }

View file

@ -743,7 +743,7 @@ public class ItemSwapTab : IDisposable, ITab
private void OnCollectionChange(CollectionType collectionType, ModCollection? oldCollection, private void OnCollectionChange(CollectionType collectionType, ModCollection? oldCollection,
ModCollection? newCollection, string _) ModCollection? newCollection, string _)
{ {
if (collectionType != CollectionType.Current || _mod == null || newCollection == null) if (collectionType is not CollectionType.Current || _mod == null || newCollection == null)
return; return;
UpdateMod(_mod, _mod.Index < newCollection.Settings.Count ? newCollection[_mod.Index].Settings : null); UpdateMod(_mod, _mod.Index < newCollection.Settings.Count ? newCollection[_mod.Index].Settings : null);

View file

@ -395,7 +395,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private void OnCollectionChange(CollectionType collectionType, ModCollection? oldCollection, ModCollection? newCollection, string _) private void OnCollectionChange(CollectionType collectionType, ModCollection? oldCollection, ModCollection? newCollection, string _)
{ {
if (collectionType != CollectionType.Current || oldCollection == newCollection) if (collectionType is not CollectionType.Current || oldCollection == newCollection)
return; return;
SetFilterDirty(); SetFilterDirty();

View file

@ -8,19 +8,19 @@ using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using OtterGui.Widgets; using OtterGui.Widgets;
using Penumbra.Collections; using Penumbra.Collections;
using Penumbra.Collections.Manager; using Penumbra.Collections.Manager;
using Penumbra.Services; using Penumbra.Services;
using Penumbra.UI.CollectionTab; using Penumbra.UI.CollectionTab;
namespace Penumbra.UI.Tabs; namespace Penumbra.UI.Tabs;
public class CollectionsTab : IDisposable, ITab public class CollectionsTab : IDisposable, ITab
{ {
private readonly CommunicatorService _communicator; private readonly CommunicatorService _communicator;
private readonly Configuration _config; private readonly Configuration _config;
private readonly CollectionManager _collectionManager; private readonly CollectionManager _collectionManager;
private readonly TutorialService _tutorial; private readonly TutorialService _tutorial;
private readonly SpecialCombo _specialCollectionCombo; private readonly SpecialCombo _specialCollectionCombo;
private readonly CollectionSelector _collectionsWithEmpty; private readonly CollectionSelector _collectionsWithEmpty;
private readonly CollectionSelector _collectionSelector; private readonly CollectionSelector _collectionSelector;