diff --git a/Penumbra/Mods/Mod.BasePath.cs b/Penumbra/Mods/Mod.BasePath.cs index 9ce8d478..851ed943 100644 --- a/Penumbra/Mods/Mod.BasePath.cs +++ b/Penumbra/Mods/Mod.BasePath.cs @@ -80,9 +80,15 @@ public partial class Mod // Deletes the source files if delete is true. private void IncorporateAllMetaChanges( bool delete ) { + var changes = false; foreach( var subMod in AllSubMods.OfType< SubMod >() ) { - subMod.IncorporateMetaChanges( ModPath, delete ); + changes |= subMod.IncorporateMetaChanges( ModPath, delete ); + } + + if( changes ) + { + SaveAllGroups(); } } } \ No newline at end of file diff --git a/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs b/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs index fe0de7d0..0cdb9aa8 100644 --- a/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs +++ b/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs @@ -182,8 +182,11 @@ public partial class Mod // If .meta or .rgsp files are encountered, parse them and incorporate their meta changes into the mod. // If delete is true, the files are deleted afterwards. - public void IncorporateMetaChanges( DirectoryInfo basePath, bool delete ) + public bool IncorporateMetaChanges( DirectoryInfo basePath, bool delete ) { + var deleteList = new List< string >(); + var oldSize = ManipulationData.Count; + var deleteString = delete ? "with deletion." : "without deletion."; foreach( var (key, file) in Files.ToList() ) { var ext1 = key.Extension().AsciiToLower().ToString(); @@ -199,11 +202,8 @@ public partial class Mod } var meta = new TexToolsMeta( File.ReadAllBytes( file.FullName ) ); - if( delete ) - { - File.Delete( file.FullName ); - } - + Penumbra.Log.Verbose( $"Incorporating {file} as Metadata file of {meta.MetaManipulations.Count} manipulations {deleteString}" ); + deleteList.Add( file.FullName ); ManipulationData.UnionWith( meta.MetaManipulations ); } else if( ext1 == ".rgsp" || ext2 == ".rgsp" ) @@ -215,10 +215,8 @@ public partial class Mod } var rgsp = TexToolsMeta.FromRgspFile( file.FullName, File.ReadAllBytes( file.FullName ) ); - if( delete ) - { - File.Delete( file.FullName ); - } + Penumbra.Log.Verbose( $"Incorporating {file} as racial scaling file of {rgsp.MetaManipulations.Count} manipulations {deleteString}" ); + deleteList.Add( file.FullName ); ManipulationData.UnionWith( rgsp.MetaManipulations ); } @@ -228,6 +226,20 @@ public partial class Mod Penumbra.Log.Error( $"Could not incorporate meta changes in mod {basePath} from file {file.FullName}:\n{e}" ); } } + + foreach( var file in deleteList ) + { + try + { + File.Delete( file ); + } + catch( Exception e ) + { + Penumbra.Log.Error( $"Could not delete incorporated meta file {file}:\n{e}" ); + } + } + + return oldSize < ManipulationData.Count; } public void WriteTexToolsMeta( DirectoryInfo basePath, bool test = false ) @@ -254,7 +266,7 @@ public partial class Mod } } - [Conditional("DEBUG")] + [Conditional( "DEBUG" )] private void TestMetaWriting( Dictionary< string, byte[] > files ) { var meta = new HashSet< MetaManipulation >( Manipulations.Count );