Added BGA plugin for BZA and GZA archives

This commit is contained in:
Michael Becker 2014-08-08 15:48:52 -04:00
parent 7ae8940226
commit b16bfb98d2
3 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.DataFormats.FileSystem.BGA
{
public enum BGACompressionMethod
{
None = 0,
Bzip2 = 1,
Gzip = 2
}
}

View File

@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniversalEditor.Compression;
using UniversalEditor.IO;
using UniversalEditor.ObjectModels.FileSystem;
namespace UniversalEditor.DataFormats.FileSystem.BGA
{
public class BGADataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All);
_dfr.Filters.Add("IZArc BGA archive", new byte?[][] { new byte?[] { null, null, null, null, (byte)'B', (byte)'Z', (byte)'2', (byte)0 } }, new string[] { "*.bza" });
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null) throw new ObjectModelNotSupportedException();
Reader reader = base.Accessor.Reader;
while (!reader.EndOfStream)
{
uint unknown1 = reader.ReadUInt32();
string compressionType = reader.ReadFixedLengthString(4);
if (compressionType == "BZ2\0")
{
}
else
{
throw new InvalidDataFormatException("Compression type " + compressionType + " not supported!");
}
uint compressedSize = reader.ReadUInt32();
uint decompressedSize = reader.ReadUInt32();
uint checksum /*?*/ = reader.ReadUInt32();
ushort unknown2 = reader.ReadUInt16();
ushort unknown3 = reader.ReadUInt16();
ushort unknown4 = reader.ReadUInt16();
ushort fileNameLength = reader.ReadUInt16();
string fileName = reader.ReadFixedLengthString(fileNameLength);
long offset = reader.Accessor.Position;
reader.Accessor.Seek(compressedSize, SeekOrigin.Current);
File file = fsom.AddFile(fileName);
file.Size = decompressedSize;
file.Properties.Add("offset", offset);
file.Properties.Add("CompressedSize", compressedSize);
file.Properties.Add("DecompressedSize", decompressedSize);
file.Properties.Add("checksum", checksum);
file.Properties.Add("reader", reader);
file.DataRequest += file_DataRequest;
}
}
private void file_DataRequest(object sender, DataRequestEventArgs e)
{
File file = (sender as File);
Reader reader = (Reader)file.Properties["reader"];
long offset = (long)file.Properties["offset"];
uint compressedSize = (uint)file.Properties["CompressedSize"];
uint decompressedSize = (uint)file.Properties["DecompressedSize"];
uint checksum = (uint)file.Properties["checksum"];
BGACompressionMethod compressionMethod = (BGACompressionMethod)file.Properties["CompressionMethod"];
reader.Seek(offset, SeekOrigin.Begin);
byte[] compressedData = reader.ReadBytes(compressedSize);
byte[] decompressedData = compressedData;
switch (compressionMethod)
{
case BGACompressionMethod.Bzip2:
{
decompressedData = CompressionModule.FromKnownCompressionMethod(CompressionMethod.Bzip2).Decompress(compressedData);
break;
}
case BGACompressionMethod.Gzip:
{
decompressedData = CompressionModule.FromKnownCompressionMethod(CompressionMethod.Gzip).Decompress(compressedData);
break;
}
}
e.Data = decompressedData;
}
protected override void SaveInternal(ObjectModel objectModel)
{
throw new NotImplementedException();
}
}
}

View File

@ -55,6 +55,8 @@
<Compile Include="DataFormats\FileSystem\ARJ\Internal\ARJFileHeader.cs" />
<Compile Include="DataFormats\FileSystem\AR\ARDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\BAG\BAGDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\BGA\BGACompressionMethod.cs" />
<Compile Include="DataFormats\FileSystem\BGA\BGADataFormat.cs" />
<Compile Include="DataFormats\FileSystem\Box\BoxDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\BPlus\BPlusFileSystemDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\BPlus\Internal\BTREEINDEXHEADER.cs" />