Make meta parsing more robust.

This commit is contained in:
Ottermandias 2021-04-20 22:13:56 +02:00
parent a722acbc94
commit 5d97f77dc3
2 changed files with 19 additions and 10 deletions

View file

@ -140,10 +140,16 @@ namespace Penumbra.Importer
private void AddIfNotDefault( MetaManipulation manipulation )
{
if( !Service< MetaDefaults >.Get().CheckAgainstDefault( manipulation ) )
try
{
Service< MetaDefaults >.Get().CheckAgainstDefault( manipulation );
Manipulations.Add( manipulation );
if( !Service< MetaDefaults >.Get().CheckAgainstDefault( manipulation ) )
{
Manipulations.Add( manipulation );
}
}
catch( Exception e )
{
PluginLog.Debug("Skipped {Type}-manipulation:\n{e:l}", manipulation.Type, e );
}
}

View file

@ -9,6 +9,13 @@ using Penumbra.Mods;
namespace Penumbra.MetaData
{
public class InvalidImcVariantException : ArgumentOutOfRangeException
{
public InvalidImcVariantException()
: base("Trying to manipulate invalid variant.")
{ }
}
public static class ImcExtensions
{
public static bool Equal( this ImcFile.ImageChangeData lhs, ImcFile.ImageChangeData rhs )
@ -84,14 +91,10 @@ namespace Penumbra.MetaData
if( imc.Variant > parts[ idx ].Variants.Length )
{
PluginLog.Debug( "Trying to manipulate invalid variant {Variant} of {NumVariants} in file {FileName}.", imc.Variant,
parts[ idx ].Variants.Length, file.FilePath.Path );
return ref parts[ idx ].Variants[ parts[ idx ].Variants.Length - 1 ];
}
else
{
return ref parts[ idx ].Variants[ imc.Variant - 1 ];
throw new InvalidImcVariantException();
}
return ref parts[ idx ].Variants[ imc.Variant - 1 ];
}
public static ImcFile Clone( this ImcFile file )