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)
{
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

View file

@ -45,6 +45,7 @@ public class TempModManager : IDisposable
HashSet<MetaManipulation> manips, int priority)
{
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,6 +53,7 @@ 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;
@ -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
collection.Apply(mod, created);
}
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);
}
}

View file

@ -19,8 +19,9 @@ public record ModConflicts(IMod Mod2, List<object> 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.
/// </summary>
public class ModCollectionCache : IDisposable
public class CollectionCache : IDisposable
{
private readonly CollectionCacheManager _manager;
private readonly ModCollection _collection;
public readonly SortedList<string, (SingleArray<IMod>, object?)> _changedItems = new();
public readonly Dictionary<Utf8GamePath, ModPath> ResolvedFiles = new();
@ -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)

View file

@ -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;

View file

@ -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;

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);
}

View file

@ -16,15 +16,15 @@ public class ModCacheManager : IDisposable, IReadOnlyList<ModCache>
{
private readonly CommunicatorService _communicator;
private readonly IdentifierService _identifier;
private readonly IReadOnlyList<Mod> _modManager;
private readonly ModStorage _modManager;
private readonly List<ModCache> _cache = new();
public ModCacheManager(CommunicatorService communicator, IdentifierService identifier, ModManager modManager)
public ModCacheManager(CommunicatorService communicator, IdentifierService identifier, ModStorage modStorage)
{
_communicator = communicator;
_identifier = identifier;
_modManager = modManager;
_modManager = modStorage;
_communicator.ModOptionChanged.Subscribe(OnModOptionChange);
_communicator.ModPathChanged.Subscribe(OnModPathChange);

View file

@ -9,7 +9,7 @@ public class ModCache
public int TotalManipulations;
public bool HasOptions;
public SortedList<string, object?> ChangedItems = new();
public readonly SortedList<string, object?> ChangedItems = new();
public string LowerChangedItemsString = string.Empty;
public string AllTagsLower = string.Empty;

View file

@ -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);

View file

@ -395,7 +395,7 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
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;
SetFilterDirty();