Skip to content
Permalink
Browse files
Add some properly typed Exception catching...
  • Loading branch information
AdmiralCurtiss committed Mar 25, 2015
1 parent c6e4a2d commit b526fae3e54cedbf4a9c86bb0b97b05579a022d8
Showing with 18 additions and 15 deletions.
  1. +7 −2 Program.cs
  2. +11 −13 blz.cs
@@ -123,7 +123,7 @@ class Program {
System.IO.File.WriteAllBytes( "arm9-dec.bin", decData );
#endif
}
} catch ( Exception ) {
} catch ( blzDecodingException ) {
compressed = false;
}
}
@@ -306,7 +306,12 @@ class Program {

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
@@ -4,6 +4,12 @@
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 @@ class blz {

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 );

0 comments on commit b526fae

Please sign in to comment.