2020-04-10 03:10:50 +02:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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);
|
2020-06-14 18:00:36 +02:00
|
|
|
|
return reader.ReadByte() == 0x11;
|
2020-04-10 03:10:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-26 20:59:49 +02:00
|
|
|
|
public bool CanCompress { get; } = false;
|
2020-04-10 03:10:50 +02:00
|
|
|
|
|
|
|
|
|
private bool UseLZMAMagicHeader = true;
|
|
|
|
|
|
|
|
|
|
public Stream Decompress(Stream stream)
|
|
|
|
|
{
|
2020-04-10 21:32:49 +02:00
|
|
|
|
using (var reader = new FileReader(stream, true))
|
2020-04-10 03:10:50 +02:00
|
|
|
|
{
|
2020-06-14 18:00:36 +02:00
|
|
|
|
reader.SeekBegin(12);
|
|
|
|
|
byte type = reader.ReadByte();
|
|
|
|
|
if (type == 0x11)
|
2020-04-10 03:10:50 +02:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Stream Compress(Stream stream)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream mem = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|