diff --git a/Penumbra/Collections/CollectionManager.cs b/Penumbra/Collections/CollectionManager.cs index 1ab16c6a..05e221d3 100644 --- a/Penumbra/Collections/CollectionManager.cs +++ b/Penumbra/Collections/CollectionManager.cs @@ -115,7 +115,7 @@ public partial class ModCollection newCollection.Index = _collections.Count; _collections.Add( newCollection ); newCollection.Save(); - PluginLog.Debug( "Added collection {Name:l}.", newCollection.Name ); + PluginLog.Debug( "Added collection {Name:l}.", newCollection.AnonymizedName ); CollectionChanged.Invoke( CollectionType.Inactive, null, newCollection ); SetCollection( newCollection.Index, CollectionType.Current ); return true; @@ -154,8 +154,17 @@ public partial class ModCollection } var collection = _collections[ idx ]; + + // Clear own inheritances. + foreach(var inheritance in collection.Inheritance) + { + collection.ClearSubscriptions( inheritance ); + } + collection.Delete(); _collections.RemoveAt( idx ); + + // Clear external inheritances. foreach( var c in _collections ) { var inheritedIdx = c._inheritance.IndexOf( collection ); @@ -170,7 +179,7 @@ public partial class ModCollection } } - PluginLog.Debug( "Removed collection {Name:l}.", collection.Name ); + PluginLog.Debug( "Removed collection {Name:l}.", collection.AnonymizedName ); CollectionChanged.Invoke( CollectionType.Inactive, collection, null ); return true; } diff --git a/Penumbra/Collections/ModCollection.File.cs b/Penumbra/Collections/ModCollection.File.cs index 5c8aa521..6f76199b 100644 --- a/Penumbra/Collections/ModCollection.File.cs +++ b/Penumbra/Collections/ModCollection.File.cs @@ -67,7 +67,7 @@ public partial class ModCollection } catch( Exception e ) { - PluginLog.Error( $"Could not save collection {Name}:\n{e}" ); + PluginLog.Error( $"Could not save collection {AnonymizedName}:\n{e}" ); } } @@ -90,11 +90,11 @@ public partial class ModCollection try { file.Delete(); - PluginLog.Information( "Deleted collection file {File:l} for {Name:l}.", file.FullName, Name ); + PluginLog.Information( "Deleted collection file for {Name:l}.", AnonymizedName ); } catch( Exception e ) { - PluginLog.Error( $"Could not delete collection file {file.FullName} for {Name}:\n{e}" ); + PluginLog.Error( $"Could not delete collection file for {AnonymizedName}:\n{e}" ); } } @@ -105,7 +105,7 @@ public partial class ModCollection inheritance = Array.Empty< string >(); if( !file.Exists ) { - PluginLog.Error( $"Could not read collection because {file.FullName} does not exist." ); + PluginLog.Error( $"Could not read collection because file does not exist." ); return null; } @@ -123,7 +123,7 @@ public partial class ModCollection } catch( Exception e ) { - PluginLog.Error( $"Could not read collection information from {file.FullName}:\n{e}" ); + PluginLog.Error( $"Could not read collection information from file:\n{e}" ); } return null; diff --git a/Penumbra/Collections/ModCollection.Inheritance.cs b/Penumbra/Collections/ModCollection.Inheritance.cs index b778655b..12b5c054 100644 --- a/Penumbra/Collections/ModCollection.Inheritance.cs +++ b/Penumbra/Collections/ModCollection.Inheritance.cs @@ -88,13 +88,18 @@ public partial class ModCollection public void RemoveInheritance( int idx ) { var inheritance = _inheritance[ idx ]; - inheritance.ModSettingChanged -= OnInheritedModSettingChange; - inheritance.InheritanceChanged -= OnInheritedInheritanceChange; + ClearSubscriptions( inheritance ); _inheritance.RemoveAt( idx ); InheritanceChanged.Invoke( false ); PluginLog.Debug( "Removed {InheritedName:l} from {Name:l} inheritances.", inheritance.AnonymizedName, AnonymizedName ); } + private void ClearSubscriptions( ModCollection other ) + { + other.ModSettingChanged -= OnInheritedModSettingChange; + other.InheritanceChanged -= OnInheritedInheritanceChange; + } + // Order in the inheritance list is relevant. public void MoveInheritance( int from, int to ) { @@ -115,6 +120,13 @@ public partial class ModCollection ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true ); return; default: + if( modIdx < 0 || modIdx >= _settings.Count ) + { + PluginLog.Warning( + $"Collection state broken, Mod {modIdx} in inheritance does not exist. ({_settings.Count} mods exist)." ); + return; + } + if( _settings[ modIdx ] == null ) { ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true ); diff --git a/Penumbra/UI/ConfigWindow.ModsTab.cs b/Penumbra/UI/ConfigWindow.ModsTab.cs index adcd512d..5c9cb0e6 100644 --- a/Penumbra/UI/ConfigWindow.ModsTab.cs +++ b/Penumbra/UI/ConfigWindow.ModsTab.cs @@ -5,6 +5,7 @@ using Penumbra.Collections; using Penumbra.Mods; using Penumbra.UI.Classes; using System; +using System.Linq; using System.Numerics; using Dalamud.Logging; @@ -43,13 +44,13 @@ public partial class ConfigWindow { PluginLog.Error( $"Exception thrown during ModPanel Render:\n{e}" ); PluginLog.Error( $"{Penumbra.ModManager.Count} Mods\n" - + $"{Penumbra.CollectionManager.Current.Name} Current Collection\n" + + $"{Penumbra.CollectionManager.Current.AnonymizedName} Current Collection\n" + $"{Penumbra.CollectionManager.Current.Settings.Count} Settings\n" - + $"{_selector.SortMode} Sort Mode\n" + + $"{_selector.SortMode.Name} Sort Mode\n" + $"{_selector.SelectedLeaf?.Name ?? "NULL"} Selected Leaf\n" + $"{_selector.Selected?.Name ?? "NULL"} Selected Mod\n" - + $"{string.Join( ", ", Penumbra.CollectionManager.Current.Inheritance )} Inheritances\n" - + $"{_selector.SelectedSettingCollection.Name} Collection\n" ); + + $"{string.Join( ", ", Penumbra.CollectionManager.Current.Inheritance.Select(c => c.AnonymizedName) )} Inheritances\n" + + $"{_selector.SelectedSettingCollection.AnonymizedName} Collection\n" ); } }