mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-02 13:53:42 +01:00
Add functions to re-export meta changes to TexTools .meta and .rgsp formats.
This commit is contained in:
parent
7a09d561e9
commit
3391a8ce71
7 changed files with 383 additions and 24 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
|
@ -59,6 +60,37 @@ public partial class Mod
|
|||
}
|
||||
}
|
||||
|
||||
public void WriteAllTexToolsMeta()
|
||||
{
|
||||
try
|
||||
{
|
||||
_default.WriteTexToolsMeta( ModPath );
|
||||
foreach( var group in Groups )
|
||||
{
|
||||
var dir = NewOptionDirectory( ModPath, group.Name );
|
||||
if( !dir.Exists )
|
||||
{
|
||||
dir.Create();
|
||||
}
|
||||
|
||||
foreach( var option in group.OfType< SubMod >() )
|
||||
{
|
||||
var optionDir = NewOptionDirectory( dir, option.Name );
|
||||
if( !optionDir.Exists )
|
||||
{
|
||||
optionDir.Create();
|
||||
}
|
||||
|
||||
option.WriteTexToolsMeta( optionDir );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Penumbra.Log.Error( $"Error writing TexToolsMeta:\n{e}" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// A sub mod is a collection of
|
||||
// - file replacements
|
||||
|
|
@ -197,5 +229,70 @@ public partial class Mod
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteTexToolsMeta( DirectoryInfo basePath, bool test = false )
|
||||
{
|
||||
var files = TexToolsMeta.ConvertToTexTools( Manipulations );
|
||||
|
||||
foreach( var (file, data) in files )
|
||||
{
|
||||
var path = Path.Combine( basePath.FullName, file );
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory( Path.GetDirectoryName( path )! );
|
||||
File.WriteAllBytes( path, data );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
Penumbra.Log.Error( $"Could not write meta file {path}:\n{e}" );
|
||||
}
|
||||
}
|
||||
|
||||
if( test )
|
||||
{
|
||||
TestMetaWriting( files );
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void TestMetaWriting( Dictionary< string, byte[] > files )
|
||||
{
|
||||
var meta = new HashSet< MetaManipulation >( Manipulations.Count );
|
||||
foreach( var (file, data) in files )
|
||||
{
|
||||
try
|
||||
{
|
||||
var x = file.EndsWith( "rgsp" ) ? TexToolsMeta.FromRgspFile( file, data ) : new TexToolsMeta( data );
|
||||
meta.UnionWith( x.MetaManipulations );
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
if( !Manipulations.SetEquals( meta ) )
|
||||
{
|
||||
Penumbra.Log.Information( "Meta Sets do not equal." );
|
||||
foreach( var (m1, m2) in Manipulations.Zip( meta ) )
|
||||
{
|
||||
Penumbra.Log.Information( $"{m1} {m1.EntryToString()} | {m2} {m2.EntryToString()}" );
|
||||
}
|
||||
|
||||
foreach( var m in Manipulations.Skip( meta.Count ) )
|
||||
{
|
||||
Penumbra.Log.Information( $"{m} {m.EntryToString()} " );
|
||||
}
|
||||
|
||||
foreach( var m in meta.Skip( Manipulations.Count ) )
|
||||
{
|
||||
Penumbra.Log.Information( $"{m} {m.EntryToString()} " );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Penumbra.Log.Information( "Meta Sets are equal." );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue