Add decompressing zlib method (Works with ZCMP files too)

This commit is contained in:
KillzXGaming 2019-06-30 20:03:04 -04:00
parent a4fb55b5e7
commit cb0d680b9d
5 changed files with 27 additions and 2 deletions

Binary file not shown.

View file

@ -24,6 +24,7 @@ namespace Switch_Toolbox.Library.IO
items.Add(new ToolStripMenuItem("lZ4"));
items.Add(new ToolStripMenuItem("lZ4F"));
items.Add(new ToolStripMenuItem("ZSTD"));
items.Add(new ToolStripMenuItem("ZLIB"));
SetFunctions(items);
return items;
@ -71,6 +72,8 @@ namespace Switch_Toolbox.Library.IO
OpenFileForCompression(CompressionType.Lz4f, Compress);
else if (Name == "ZSTD")
OpenFileForCompression(CompressionType.Zstb, Compress);
else if (Name == "ZLIB")
OpenFileForCompression(CompressionType.Zlib, Compress);
else throw new Exception("Unimplimented Type! " + Name);
}
@ -107,6 +110,7 @@ namespace Switch_Toolbox.Library.IO
SaveFileForCompression(EveryFileExplorer.YAZ0.Decompress(data));
break;
case CompressionType.Zlib:
SaveFileForCompression(STLibraryCompression.ZLIB.Decompress(data));
break;
case CompressionType.Gzip:
SaveFileForCompression(STLibraryCompression.GZIP.Decompress(data));

View file

@ -61,6 +61,12 @@ namespace Switch_Toolbox.Library.IO
public static byte[] Decompress(byte[] b)
{
using (var br = new FileReader(new MemoryStream(b), true))
{
if (br.ReadString(4) == "ZCMP")
{
return DecompressZCMP(b);
}
else
{
var ms = new System.IO.MemoryStream();
br.BaseStream.Position = 2;
@ -69,6 +75,21 @@ namespace Switch_Toolbox.Library.IO
return ms.ToArray();
}
}
}
public static Byte[] DecompressZCMP(byte[] b)
{
Console.WriteLine("DecompressZCMP");
using (var br = new FileReader(new MemoryStream(b), true))
{
var ms = new System.IO.MemoryStream();
br.BaseStream.Position = 130;
using (var ds = new DeflateStream(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length - 80)), CompressionMode.Decompress))
ds.CopyTo(ms);
return ms.ToArray();
}
}
public static byte[] Compress(byte[] b, uint Position = 0)
{