mirror of
https://github.com/AdmiralCurtiss/WfcPatcher.git
synced 2026-03-21 18:04:23 -05:00
Add some properly typed Exception catching...
This commit is contained in:
parent
c6e4a2d6e3
commit
b526fae3e5
|
|
@ -123,7 +123,7 @@ namespace WfcPatcher {
|
|||
System.IO.File.WriteAllBytes( "arm9-dec.bin", decData );
|
||||
#endif
|
||||
}
|
||||
} catch ( Exception ) {
|
||||
} catch ( blzDecodingException ) {
|
||||
compressed = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -306,7 +306,12 @@ namespace WfcPatcher {
|
|||
|
||||
bool compressed = ( compressedBitmask & 0x01 ) == 0x01;
|
||||
if ( compressed ) {
|
||||
decData = blz.BLZ_Decode( data );
|
||||
try {
|
||||
decData = blz.BLZ_Decode( data );
|
||||
} catch ( blzDecodingException ) {
|
||||
decData = data;
|
||||
compressed = false;
|
||||
}
|
||||
} else {
|
||||
decData = data;
|
||||
}
|
||||
|
|
|
|||
24
blz.cs
24
blz.cs
|
|
@ -4,6 +4,12 @@ using System.Linq;
|
|||
using System.Text;
|
||||
|
||||
namespace WfcPatcher {
|
||||
class blzDecodingException : Exception {
|
||||
public blzDecodingException() : base() { }
|
||||
public blzDecodingException( string message ) : base( message ) { }
|
||||
public blzDecodingException( string message, Exception inner ) : base( message, inner ) { }
|
||||
}
|
||||
|
||||
class blz {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*-- blz.c - Bottom LZ coding for Nintendo GBA/DS --*/
|
||||
|
|
@ -168,25 +174,17 @@ namespace WfcPatcher {
|
|||
|
||||
inc_len = BitConverter.ToUInt32( pak_buffer, (int)pak_len - 4 );
|
||||
if ( inc_len == 0 ) {
|
||||
throw new Exception( "Not coded file!" );
|
||||
enc_len = 0;
|
||||
dec_len = pak_len;
|
||||
pak_len = 0;
|
||||
raw_len = dec_len;
|
||||
|
||||
fileWasNotCompressed = true;
|
||||
//Console.WriteLine();
|
||||
return pak_buffer;
|
||||
throw new blzDecodingException( "Not coded file!" );
|
||||
} else {
|
||||
if ( pak_len < 8 ) throw new Exception( "File has a bad header" );
|
||||
if ( pak_len < 8 ) throw new blzDecodingException( "File has a bad header" );
|
||||
hdr_len = pak_buffer[pak_len - 5];
|
||||
if ( ( hdr_len < 0x08 ) || ( hdr_len > 0x0B ) ) throw new Exception( "Bad header length" );
|
||||
if ( pak_len <= hdr_len ) throw new Exception( "Bad length" );
|
||||
if ( ( hdr_len < 0x08 ) || ( hdr_len > 0x0B ) ) throw new blzDecodingException( "Bad header length" );
|
||||
if ( pak_len <= hdr_len ) throw new blzDecodingException( "Bad length" );
|
||||
enc_len = BitConverter.ToUInt32( pak_buffer, (int)pak_len - 8 ) & 0x00FFFFFF;
|
||||
dec_len = pak_len - enc_len;
|
||||
pak_len = enc_len - hdr_len;
|
||||
raw_len = dec_len + enc_len + inc_len;
|
||||
if ( raw_len > RAW_MAXIM ) throw new Exception( "Bad decoded length" );
|
||||
if ( raw_len > RAW_MAXIM ) throw new blzDecodingException( "Bad decoded length" );
|
||||
}
|
||||
|
||||
raw_buffer = Memory( (int)raw_len, 1 );
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user