mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 20:43:09 +00:00
Add decompressing zlib method (Works with ZCMP files too)
This commit is contained in:
parent
a4fb55b5e7
commit
cb0d680b9d
5 changed files with 27 additions and 2 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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));
|
||||
|
|
|
@ -60,11 +60,32 @@ 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;
|
||||
using (var ds = new DeflateStream(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length - 6)), CompressionMode.Decompress))
|
||||
ds.CopyTo(ms);
|
||||
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 = 2;
|
||||
using (var ds = new DeflateStream(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length - 6)), CompressionMode.Decompress))
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue