From 815daaad45646b83ba6fa05b6265065e00497756 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Thu, 9 Apr 2020 21:10:50 -0400 Subject: [PATCH] Fix some erorrs --- .../Compression/Formats/LZ77.cs | 65 +++++++++++++++++++ Switch_Toolbox_Library/Toolbox_Library.csproj | 1 + 2 files changed, 66 insertions(+) create mode 100644 Switch_Toolbox_Library/Compression/Formats/LZ77.cs diff --git a/Switch_Toolbox_Library/Compression/Formats/LZ77.cs b/Switch_Toolbox_Library/Compression/Formats/LZ77.cs new file mode 100644 index 00000000..ee9e8767 --- /dev/null +++ b/Switch_Toolbox_Library/Compression/Formats/LZ77.cs @@ -0,0 +1,65 @@ +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", }; + + bool isType11; + 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); + isType11 = reader.ReadByte() == 0x11; + return isType11; + } + } + return false; + } + + public bool CanCompress { get; } = true; + + private bool UseLZMAMagicHeader = true; + + public Stream Decompress(Stream stream) + { + using (var reader = new FileReader(stream)) + { + if (isType11) + { + 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; + } + } +} diff --git a/Switch_Toolbox_Library/Toolbox_Library.csproj b/Switch_Toolbox_Library/Toolbox_Library.csproj index 52eede1a..91152c36 100644 --- a/Switch_Toolbox_Library/Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Toolbox_Library.csproj @@ -232,6 +232,7 @@ +