Automatically incorporate all .meta and .rgsp files when adding mods via API.

This commit is contained in:
Ottermandias 2022-09-20 15:42:09 +02:00
parent ea023ebb5c
commit 1c97b52179
7 changed files with 27 additions and 11 deletions

View file

@ -202,7 +202,7 @@ public unsafe partial class PathResolver
var resolveData = GetResolveData( human );
using var eqp = resolveData.Valid ? resolveData.ModCollection.TemporarilySetEqpFile() : null;
using var decals = resolveData.Valid
? new CharacterUtility.DecalReverter( resolveData.ModCollection, DrawObjectState.UsesDecal(0, data) )
? new CharacterUtility.DecalReverter( resolveData.ModCollection, DrawObjectState.UsesDecal( 0, data ) )
: null;
return _changeCustomize.Original( human, data, skipEquipment );
}

View file

@ -273,7 +273,7 @@ public partial class Mod
try
{
var mod = new Mod( modDirectory );
mod.Reload( out _ );
mod.Reload( true, out _ );
var editor = new Editor( mod, mod.Default );
editor.DuplicatesFinished = false;
editor.CheckDuplicates( editor.AvailableFiles.OrderByDescending( f => f.FileSize ).ToArray() );

View file

@ -267,7 +267,7 @@ public partial class Mod
if( deletions > 0 )
{
_mod.Reload( out _ );
_mod.Reload( false, out _ );
UpdateFiles();
}
}

View file

@ -60,7 +60,7 @@ public partial class Mod
dir.Refresh();
mod.ModPath = dir;
if( !mod.Reload( out var metaChange ) )
if( !mod.Reload( false, out var metaChange ) )
{
Penumbra.Log.Error( $"Error reloading moved mod {mod.Name}." );
return;
@ -81,7 +81,7 @@ public partial class Mod
var oldName = mod.Name;
ModPathChanged.Invoke( ModPathChangeType.StartingReload, mod, mod.ModPath, mod.ModPath );
if( !mod.Reload( out var metaChange ) )
if( !mod.Reload( true, out var metaChange ) )
{
Penumbra.Log.Warning( mod.Name.Length == 0
? $"Reloading mod {oldName} has failed, new name is empty. Deleting instead."
@ -135,7 +135,7 @@ public partial class Mod
return;
}
var mod = LoadMod( modFolder );
var mod = LoadMod( modFolder, true );
if( mod == null )
{
return;

View file

@ -84,7 +84,7 @@ public sealed partial class Mod
{
foreach( var modFolder in BasePath.EnumerateDirectories() )
{
var mod = LoadMod( modFolder );
var mod = LoadMod( modFolder, false );
if( mod == null )
{
continue;

View file

@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
namespace Penumbra.Mods;
@ -26,7 +27,7 @@ public partial class Mod
_default = new SubMod( this );
}
private static Mod? LoadMod( DirectoryInfo modPath )
private static Mod? LoadMod( DirectoryInfo modPath, bool incorporateMetaChanges )
{
modPath.Refresh();
if( !modPath.Exists )
@ -36,7 +37,7 @@ public partial class Mod
}
var mod = new Mod( modPath );
if( !mod.Reload( out _ ) )
if( !mod.Reload( incorporateMetaChanges, out _ ) )
{
// Can not be base path not existing because that is checked before.
Penumbra.Log.Error( $"Mod at {modPath} without name is not supported." );
@ -46,7 +47,7 @@ public partial class Mod
return mod;
}
private bool Reload( out MetaChangeType metaChange )
private bool Reload( bool incorporateMetaChanges, out MetaChangeType metaChange )
{
metaChange = MetaChangeType.Deletion;
ModPath.Refresh();
@ -63,8 +64,23 @@ public partial class Mod
LoadDefaultOption();
LoadAllGroups();
if( incorporateMetaChanges )
{
IncorporateAllMetaChanges( true );
}
ComputeChangedItems();
SetCounts();
return true;
}
// Convert all .meta and .rgsp files to their respective meta changes and add them to their options.
// Deletes the source files if delete is true.
private void IncorporateAllMetaChanges( bool delete )
{
foreach( var subMod in AllSubMods.OfType< SubMod >() )
{
subMod.IncorporateMetaChanges( ModPath, delete );
}
}
}

View file

@ -122,7 +122,7 @@ public partial class Mod
internal static void CreateDefaultFiles( DirectoryInfo directory )
{
var mod = new Mod( directory );
mod.Reload( out _ );
mod.Reload( false, out _ );
foreach( var file in mod.FindUnusedFiles() )
{
if( Utf8GamePath.FromFile( new FileInfo( file.FullName ), directory, out var gamePath, true ) )