From 6dc34d20a6f4c2d0f3da175b6871b2a9d4524201 Mon Sep 17 00:00:00 2001 From: barubary Date: Wed, 23 Nov 2011 10:35:29 +0000 Subject: [PATCH] C#: Nitro-formats will now also try to decompress files with a plaintext size of more than 0x180000. However the Supports method will first try to partially decompress the file. --- CSharp/DSDecmp/Formats/Nitro/NitroCFormat.cs | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/CSharp/DSDecmp/Formats/Nitro/NitroCFormat.cs b/CSharp/DSDecmp/Formats/Nitro/NitroCFormat.cs index 98cec2f..5621cfc 100644 --- a/CSharp/DSDecmp/Formats/Nitro/NitroCFormat.cs +++ b/CSharp/DSDecmp/Formats/Nitro/NitroCFormat.cs @@ -18,6 +18,8 @@ namespace DSDecmp.Formats.Nitro /// /// The maximum allowed size of the decompressed file (plaintext size) allowed for Nitro /// Decompressors. Only used when SkipLargePlaintexts = true. + /// If the expected plaintext size is larger that this, the 'Supports' method will partially + /// decompress the data to check if the file is OK. /// public static int MaxPlaintextSize = 0x180000; @@ -59,7 +61,24 @@ namespace DSDecmp.Formats.Nitro stream.Read(sizeBytes, 0, 4); outSize = (int)IOUtils.ToNDSu32(sizeBytes, 0); } - return outSize <= MaxPlaintextSize; + if (outSize <= MaxPlaintextSize) + return true; + + try + { + stream.Position = startPosition; + this.Decompress(stream, Math.Min(Math.Min(inLength, 0x80000), MaxPlaintextSize), new System.IO.MemoryStream()); + // we expect a NotEnoughDataException, since we're giving the decompressor only part of the file. + return false; + } + catch (NotEnoughDataException) + { + return true; + } + catch (Exception) + { + return false; + } } finally {