From 37a56c56af417c84a31cc0d89ac5d9b8c5c48c9b Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 3 Dec 2022 14:37:48 +0100 Subject: [PATCH] Fix bug with collections with inheritance saving on every launch. --- Penumbra/Collections/CollectionManager.cs | 2 +- Penumbra/Collections/ModCollection.File.cs | 1 + Penumbra/Collections/ModCollection.Inheritance.cs | 8 ++++++-- Penumbra/UI/ConfigWindow.CollectionsTab.Inheritance.cs | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Penumbra/Collections/CollectionManager.cs b/Penumbra/Collections/CollectionManager.cs index 66db1d1d..261a91be 100644 --- a/Penumbra/Collections/CollectionManager.cs +++ b/Penumbra/Collections/CollectionManager.cs @@ -339,7 +339,7 @@ public partial class ModCollection changes = true; Penumbra.Log.Warning( $"Inherited collection {subCollectionName} for {collection.Name} does not exist, removed." ); } - else if( !collection.AddInheritance( subCollection ) ) + else if( !collection.AddInheritance( subCollection, false ) ) { changes = true; Penumbra.Log.Warning( $"{collection.Name} can not inherit from {subCollectionName}, removed." ); diff --git a/Penumbra/Collections/ModCollection.File.cs b/Penumbra/Collections/ModCollection.File.cs index a9cef608..150382ad 100644 --- a/Penumbra/Collections/ModCollection.File.cs +++ b/Penumbra/Collections/ModCollection.File.cs @@ -25,6 +25,7 @@ public partial class ModCollection { try { + Penumbra.Log.Debug( $"Saving collection {AnonymizedName}..." ); var file = FileName; file.Directory?.Create(); using var s = file.Exists ? file.Open( FileMode.Truncate ) : file.Open( FileMode.CreateNew ); diff --git a/Penumbra/Collections/ModCollection.Inheritance.cs b/Penumbra/Collections/ModCollection.Inheritance.cs index 44403758..d9eecdbd 100644 --- a/Penumbra/Collections/ModCollection.Inheritance.cs +++ b/Penumbra/Collections/ModCollection.Inheritance.cs @@ -69,7 +69,7 @@ public partial class ModCollection // Add a new collection to the inheritance list. // We do not check if this collection would be visited before, // only that it is unique in the list itself. - public bool AddInheritance( ModCollection collection ) + public bool AddInheritance( ModCollection collection, bool invokeEvent ) { if( CheckValidInheritance( collection ) != ValidInheritance.Valid ) { @@ -80,7 +80,11 @@ public partial class ModCollection // Changes in inherited collections may need to trigger further changes here. collection.ModSettingChanged += OnInheritedModSettingChange; collection.InheritanceChanged += OnInheritedInheritanceChange; - InheritanceChanged.Invoke( false ); + if( invokeEvent ) + { + InheritanceChanged.Invoke( false ); + } + Penumbra.Log.Debug( $"Added {collection.AnonymizedName} to {AnonymizedName} inheritances." ); return true; } diff --git a/Penumbra/UI/ConfigWindow.CollectionsTab.Inheritance.cs b/Penumbra/UI/ConfigWindow.CollectionsTab.Inheritance.cs index e344a303..fd64093f 100644 --- a/Penumbra/UI/ConfigWindow.CollectionsTab.Inheritance.cs +++ b/Penumbra/UI/ConfigWindow.CollectionsTab.Inheritance.cs @@ -194,7 +194,7 @@ public partial class ConfigWindow }; if( ImGuiUtil.DrawDisabledButton( FontAwesomeIcon.Plus.ToIconString(), _window._iconButtonSize, tt, inheritance != ModCollection.ValidInheritance.Valid, true ) - && Penumbra.CollectionManager.Current.AddInheritance( _newInheritance! ) ) + && Penumbra.CollectionManager.Current.AddInheritance( _newInheritance!, true ) ) { _newInheritance = null; }