From ad6d7dbbf0850b1e86950b2763c175dc62913d67 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 13 Aug 2020 22:20:05 -0400 Subject: [PATCH] preliminary implementation of ARCV data format --- .../FileSystem/Associations/ARCV.uexml | 25 ++++ ...lEditor.Content.PlatformIndependent.csproj | 1 + .../FileSystem/ARCV/ARCVDataFormat.cs | 115 ++++++++++++++++++ .../UniversalEditor.Plugins.FileSystem.csproj | 2 + 4 files changed, 143 insertions(+) create mode 100644 Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/ARCV.uexml create mode 100644 Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/ARCV/ARCVDataFormat.cs diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/ARCV.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/ARCV.uexml new file mode 100644 index 00000000..c6c0df2b --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/ARCV.uexml @@ -0,0 +1,25 @@ + + + + + + + + *.$00 + + + + ARCV + + + + + + + + + + + + + \ No newline at end of file diff --git a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 047622d3..542b4bb3 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -575,6 +575,7 @@ + diff --git a/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/ARCV/ARCVDataFormat.cs b/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/ARCV/ARCVDataFormat.cs new file mode 100644 index 00000000..b8b05d57 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.FileSystem/DataFormats/FileSystem/ARCV/ARCVDataFormat.cs @@ -0,0 +1,115 @@ +// +// ARCVDataFormat.cs - provides a DataFormat for manipulating compressed files in ARCV format +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.FileSystem.ARCV +{ + /// + /// Provides a for manipulating compressed files in ARCV format. + /// + public class ARCVDataFormat : DataFormat + { + private static DataFormatReference _dfr = null; + protected override DataFormatReference MakeReferenceInternal() + { + if (_dfr == null) + { + _dfr = base.MakeReferenceInternal(); + _dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All); + } + return _dfr; + } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) + throw new ObjectModelNotSupportedException(); + + Reader reader = Accessor.Reader; + + string signature = reader.ReadFixedLengthString(4); + if (signature != "ARCV") + throw new InvalidDataFormatException("file does not begin with 'ARCV'"); + + uint unknown1 = reader.ReadUInt32(); + uint unknown2 = reader.ReadUInt32(); + string filename = reader.ReadLengthPrefixedString(); + + uint decompressedLength = reader.ReadUInt32(); + uint compressedLength = reader.ReadUInt32(); + uint unknown5 = reader.ReadUInt32(); + uint unknown6_maybeChecksum = reader.ReadUInt32(); + + uint reserved1 = reader.ReadUInt32(); + uint reserved2 = reader.ReadUInt32(); + + ushort unknown7 = reader.ReadUInt16(); + uint unknown8 = reader.ReadUInt32(); + uint unknown9 = reader.ReadUInt32(); + + string chnk = reader.ReadFixedLengthString(4); + if (chnk != "CHNK") + { + throw new InvalidDataFormatException(); + } + + + uint unknown11 = reader.ReadUInt32(); + uint unknown12 = reader.ReadUInt32(); + uint unknown13 = reader.ReadUInt32(); + + File f = fsom.AddFile(filename); + f.Properties["reader"] = reader; + f.Properties["offset"] = Accessor.Position; + f.Properties["compressedLength"] = compressedLength; + f.Properties["decompressedLength"] = decompressedLength; + f.Size = decompressedLength; + f.DataRequest += F_DataRequest; + } + + void F_DataRequest(object sender, DataRequestEventArgs e) + { + File f = (sender as File); + Reader reader = (Reader)f.Properties["reader"]; + long offset = (long)f.Properties["offset"]; + + uint compressedLength = (uint)f.Properties["compressedLength"]; + uint decompressedLength = (uint)f.Properties["decompressedLength"]; + + reader.Seek(offset, SeekOrigin.Begin); + byte[] compressedData = reader.ReadBytes(compressedLength); + byte[] decompressedData = compressedData; // TODO: decompress the data + e.Data = decompressedData; + } + + protected override void SaveInternal(ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) + throw new ObjectModelNotSupportedException(); + + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj b/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj index 22febb32..74f472fa 100644 --- a/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj +++ b/Plugins/UniversalEditor.Plugins.FileSystem/UniversalEditor.Plugins.FileSystem.csproj @@ -251,6 +251,7 @@ + @@ -300,6 +301,7 @@ +