mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-23 13:03:15 +00:00
42f6b670e0
Fix zlib compression corrupting the file. Fix sarc and msbt format descriptions. Adjust when a file in an IArchiveFile gets saved. Porgress on MTA 0X50 compression type. not finished atm. Start on ICompressionFormat interface. Will soon be the way compression formats are all handled.
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Threading.Tasks;
|
|
using Switch_Toolbox.Library.IO;
|
|
|
|
namespace Switch_Toolbox.Library
|
|
{
|
|
public class ZCMP : ICompressionFormat
|
|
{
|
|
public string[] Description { get; set; } = new string[] { "ZLIB Compression (ZCMP)" };
|
|
public string[] Extension { get; set; } = new string[] { "*.cmp" };
|
|
|
|
public bool Identify(Stream stream)
|
|
{
|
|
using (var reader = new FileReader(stream, true))
|
|
{
|
|
return reader.CheckSignature(4, "ZCMP");
|
|
}
|
|
}
|
|
|
|
public bool CanCompress { get; } = true;
|
|
|
|
public Stream Decompress(Stream stream)
|
|
{
|
|
using (var br = new FileReader(stream, 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;
|
|
}
|
|
}
|
|
|
|
public Stream Compress(Stream stream)
|
|
{
|
|
var mem = new MemoryStream();
|
|
mem.Write(new byte[] { 0x78, 0xDA }, 0, 2);
|
|
using (var zipStream = new DeflateStream(mem, CompressionMode.Compress))
|
|
{
|
|
zipStream.CopyTo(stream);
|
|
return mem;
|
|
}
|
|
}
|
|
}
|
|
}
|