mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-22 07:47:48 +01:00
Improve IMC Exception Handling.
This commit is contained in:
parent
b3814e61d1
commit
1be3b06292
5 changed files with 56 additions and 20 deletions
|
|
@ -5,6 +5,7 @@ using Penumbra.GameData.ByteString;
|
|||
using Penumbra.GameData.Enums;
|
||||
using Penumbra.GameData.Util;
|
||||
using Penumbra.Interop.Structs;
|
||||
using Penumbra.Meta.Manipulations;
|
||||
|
||||
namespace Penumbra.Meta.Files;
|
||||
|
||||
|
|
@ -54,6 +55,24 @@ public readonly struct ImcEntry : IEquatable< ImcEntry >
|
|||
}
|
||||
}
|
||||
|
||||
public class ImcException : Exception
|
||||
{
|
||||
public readonly ImcManipulation Manipulation;
|
||||
public readonly string GamePath;
|
||||
|
||||
public ImcException( ImcManipulation manip, Utf8GamePath path )
|
||||
{
|
||||
Manipulation = manip;
|
||||
GamePath = path.ToString();
|
||||
}
|
||||
|
||||
public override string Message
|
||||
=> "Could not obtain default Imc File.\n"
|
||||
+ " Either the default file does not exist (possibly for offhand files from TexTools) or the installation is corrupted.\n"
|
||||
+ $" Game Path: {GamePath}\n"
|
||||
+ $" Manipulation: {Manipulation}";
|
||||
}
|
||||
|
||||
public unsafe class ImcFile : MetaBaseFile
|
||||
{
|
||||
private const int PreambleSize = 4;
|
||||
|
|
@ -174,16 +193,14 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
}
|
||||
}
|
||||
|
||||
public ImcFile( Utf8GamePath path )
|
||||
public ImcFile( ImcManipulation manip )
|
||||
: base( 0 )
|
||||
{
|
||||
Path = path;
|
||||
var file = Dalamud.GameData.GetFile( path.ToString() );
|
||||
Path = manip.GamePath();
|
||||
var file = Dalamud.GameData.GetFile( Path.ToString() );
|
||||
if( file == null )
|
||||
{
|
||||
throw new Exception(
|
||||
"Could not obtain default Imc File.\n"
|
||||
+ "Either the default file does not exist (possibly for offhand files from TexTools) or the installation is corrupted." );
|
||||
throw new ImcException( manip, Path );
|
||||
}
|
||||
|
||||
fixed( byte* ptr = file.Data )
|
||||
|
|
@ -211,6 +228,7 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
exists = true;
|
||||
return *entry;
|
||||
}
|
||||
|
||||
return new ImcEntry();
|
||||
}
|
||||
}
|
||||
|
|
@ -221,9 +239,10 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
var newData = Penumbra.MetaFileManager.AllocateDefaultMemory( ActualLength, 8 );
|
||||
if( newData == null )
|
||||
{
|
||||
Penumbra.Log.Error($"Could not replace loaded IMC data at 0x{(ulong) resource:X}, allocation failed." );
|
||||
Penumbra.Log.Error( $"Could not replace loaded IMC data at 0x{( ulong )resource:X}, allocation failed." );
|
||||
return;
|
||||
}
|
||||
|
||||
Functions.MemCpyUnchecked( newData, Data, ActualLength );
|
||||
|
||||
Penumbra.MetaFileManager.Free( data, length );
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public partial class MetaManager
|
|||
{
|
||||
if( !_imcFiles.TryGetValue( path, out var file ) )
|
||||
{
|
||||
file = new ImcFile( path );
|
||||
file = new ImcFile( manip );
|
||||
}
|
||||
|
||||
if( !manip.Apply( file ) )
|
||||
|
|
@ -75,12 +75,17 @@ public partial class MetaManager
|
|||
|
||||
return true;
|
||||
}
|
||||
catch( ImcException e )
|
||||
{
|
||||
Penumbra.ImcExceptions.Add( e );
|
||||
Penumbra.Log.Error( e.ToString() );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
++Penumbra.ImcExceptions;
|
||||
Penumbra.Log.Error( $"Could not apply IMC Manipulation:\n{e}" );
|
||||
return false;
|
||||
Penumbra.Log.Error( $"Could not apply IMC Manipulation {manip}:\n{e}" );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool RevertMod( ImcManipulation m )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue