C#: added built-in check for arm9.bin in LZ-Overlay decompression, as it has some extra bytes that should be ignored when decompressing. Only the file-based methods can handle that of course. Perhaps the extra bytes should also be copied to the output file however, which is currently not the case.

This commit is contained in:
barubary 2011-04-21 14:16:59 +00:00
parent 167300d5b8
commit 69cd6ee199
2 changed files with 37 additions and 3 deletions

View File

@ -19,7 +19,7 @@ namespace DSDecmp.Formats
/// <param name="file">The name of the file to check.</param>
/// <returns>False if the file can certainly not be decompressed using this decompressor.
/// True if the file may potentially be decompressed using this decompressor.</returns>
public bool Supports(string file)
public virtual bool Supports(string file)
{
// open the file, and delegate to the decompressor-specific code.
using (FileStream fstr = new FileStream(file, FileMode.Open))
@ -49,7 +49,7 @@ namespace DSDecmp.Formats
/// </summary>
/// <param name="infile">The file to decompress.</param>
/// <param name="outfile">The target location of the decompressed file.</param>
public void Decompress(string infile, string outfile)
public virtual void Decompress(string infile, string outfile)
{
// make sure the output directory exists
string outDirectory = Path.GetDirectoryName(outfile);

View File

@ -9,10 +9,24 @@ namespace DSDecmp.Formats
/// The LZ-Overlay compression format. Compresses part of the file from end to start.
/// Is used for the 'overlay' files in NDS games, as well as arm9.bin.
/// Note that the last 12 bytes should not be included in the 'inLength' argument when
/// decompressing arm9.bin.
/// decompressing arm9.bin. This is done automatically if a file is given instead of a stream.
/// </summary>
public class LZOvl : CompressionFormat
{
#region Method: Supports(string file)
public override bool Supports(string file)
{
using (FileStream fstr = File.OpenRead(file))
{
long fLength = fstr.Length;
// arm9.bin is special in the sense that the last 12 bytes should/can be ignored.
if (Path.GetFileName(file) == "arm9.bin")
fLength -= 0xC;
return this.Supports(fstr, fLength);
}
}
#endregion
#region Method: Supports(Stream, long)
public override bool Supports(System.IO.Stream stream, long inLength)
{
@ -56,6 +70,26 @@ namespace DSDecmp.Formats
}
#endregion
#region Method: Decompress(string, string)
public override void Decompress(string infile, string outfile)
{
// make sure the output directory exists
string outDirectory = Path.GetDirectoryName(outfile);
if (!Directory.Exists(outDirectory))
Directory.CreateDirectory(outDirectory);
// open the two given files, and delegate to the format-specific code.
using (FileStream inStream = new FileStream(infile, FileMode.Open),
outStream = new FileStream(outfile, FileMode.Create))
{
long fLength = inStream.Length;
// arm9.bin needs special attention
if (Path.GetFileName(infile) == "arm9.bin")
fLength -= 0xC;
this.Decompress(inStream, fLength, outStream);
}
}
#endregion
public override void Decompress(System.IO.Stream instream, long inLength, System.IO.Stream outstream)
{
#region Format description