mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 20:43:09 +00:00
1306a91050
This pull request adds the ability to compress files to the .lz format of type 11 for Wii. This functionality has been enabled in the Tools > Compressions > LZ77(Wii type 11) > Compress tab. It has been successfully tested with the game Paper Mario: Color Splash for the Wii U. It is important to note that this is a modified version of dsdecmp. Also changed was the SaveFileForCompression method to remove the file extension when decompressing files with multiple extensions. Previously, the method would add a ".dec" extension to the file name when decompressing it. With this change, the method now removes the original file extension when decompressing a file with multiple extensions. These changes should improve the usability of the SaveFileForCompression method by ensuring that decompressed files with multiple extensions are saved with the correct file name.
72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Threading.Tasks;
|
|
using Toolbox.Library.IO;
|
|
using Toolbox.Library.Forms;
|
|
using System.Runtime.InteropServices;
|
|
using Toolbox.Library.Compression.LZ77_wii_11_compresss.Formats.Nitro;
|
|
|
|
namespace Toolbox.Library
|
|
{
|
|
public class LZ77 : ICompressionFormat
|
|
{
|
|
public string[] Description { get; set; } = new string[] { "LZ77 Compressed" };
|
|
public string[] Extension { get; set; } = new string[] { "*.lz", };
|
|
|
|
public bool Identify(Stream stream, string fileName)
|
|
{
|
|
if (stream.Length < 16)
|
|
return false;
|
|
|
|
using (var reader = new FileReader(stream, true))
|
|
{
|
|
if(Utils.GetExtension(fileName) == ".lz")
|
|
{
|
|
reader.SeekBegin(12);
|
|
return reader.ReadByte() == 0x11;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool CanCompress { get; } = false;
|
|
|
|
private bool UseLZMAMagicHeader = true;
|
|
|
|
public Stream Decompress(Stream stream)
|
|
{
|
|
using (var reader = new FileReader(stream, true))
|
|
{
|
|
reader.SeekBegin(12);
|
|
byte type = reader.ReadByte();
|
|
if (type == 0x11)
|
|
{
|
|
uint decomp_size = reader.ReadUInt32();
|
|
|
|
var sub = new SubStream(stream, 16);
|
|
return new MemoryStream(LZ77_WII.Decompress11(sub.ToArray(), (int)decomp_size));
|
|
}
|
|
else
|
|
{
|
|
return new MemoryStream();
|
|
}
|
|
}
|
|
}
|
|
// A modified version of dsdecmp for compressing files into the Wii LZ77 type 11 .lz -Adapted by:DanielSvoboda
|
|
public Stream Compress(Stream stream)
|
|
{
|
|
using (var reader = new FileReader(stream, true))
|
|
{
|
|
using (MemoryStream outstream = new MemoryStream())
|
|
{
|
|
LZ11 lz11 = new LZ11();
|
|
int compressedSize = lz11.Compress(stream, stream.Length, outstream);
|
|
return new MemoryStream(outstream.ToArray());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|