From 35da00c4f7d25034dc592c03d3e0a575a24ba59b Mon Sep 17 00:00:00 2001 From: alcexhim Date: Wed, 14 Oct 2015 14:13:10 -0400 Subject: [PATCH] Add POD archive file format used in Microsoft's Hellbender video game --- .../Associations/Microsoft/POD.uexml | 20 +++++ ...lEditor.Content.PlatformIndependent.csproj | 3 + .../FileSystem/Microsoft/POD/PODDataFormat.cs | 76 +++++++++++++++++++ .../UniversalEditor.Plugins.Microsoft.csproj | 1 + 4 files changed, 100 insertions(+) create mode 100644 CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/Microsoft/POD.uexml create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Microsoft/DataFormats/FileSystem/Microsoft/POD/PODDataFormat.cs diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/Microsoft/POD.uexml b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/Microsoft/POD.uexml new file mode 100644 index 00000000..48214c33 --- /dev/null +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/FileSystem/Associations/Microsoft/POD.uexml @@ -0,0 +1,20 @@ + + + + + + + + *.pod + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 9c4147b4..100e5b5a 100644 --- a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -658,6 +658,9 @@ + + + diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Microsoft/DataFormats/FileSystem/Microsoft/POD/PODDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Microsoft/DataFormats/FileSystem/Microsoft/POD/PODDataFormat.cs new file mode 100644 index 00000000..9d6c81e7 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Microsoft/DataFormats/FileSystem/Microsoft/POD/PODDataFormat.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.FileSystem; +using UniversalEditor.ObjectModels.FileSystem.FileSources; + +namespace UniversalEditor.DataFormats.FileSystem.Microsoft.POD +{ + public class PODDataFormat : 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; + } + + private string mvarComment = String.Empty; + public string Comment { get { return mvarComment; } set { mvarComment = value; } } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) throw new ObjectModelNotSupportedException(); + + Reader reader = base.Accessor.Reader; + int fileCount = reader.ReadInt32(); + mvarComment = reader.ReadFixedLengthString(80).TrimNull(); + + for (int i = 0; i < fileCount; i++) + { + string fileName = reader.ReadFixedLengthString(32).TrimNull(); + + int length = reader.ReadInt32(); + int offset = reader.ReadInt32(); + + File file = fsom.AddFile(fileName); + file.Size = length; + file.Source = new EmbeddedFileSource(reader, offset, length); + } + } + + protected override void SaveInternal(ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) throw new ObjectModelNotSupportedException(); + + Writer writer = base.Accessor.Writer; + + File[] files = fsom.GetAllFiles(); + writer.WriteInt32(files.Length); + + writer.WriteFixedLengthString(mvarComment, 80); + + int offset = 84 + (40 * files.Length); + + foreach (File file in files) + { + writer.WriteFixedLengthString(file.Name, 32); + + int length = (int)file.Source.GetLength(); + writer.WriteInt32(length); + writer.WriteInt32(offset); + + offset += length; + } + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Microsoft/UniversalEditor.Plugins.Microsoft.csproj b/CSharp/Plugins/UniversalEditor.Plugins.Microsoft/UniversalEditor.Plugins.Microsoft.csproj index d2d686de..ce7aaf39 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.Microsoft/UniversalEditor.Plugins.Microsoft.csproj +++ b/CSharp/Plugins/UniversalEditor.Plugins.Microsoft/UniversalEditor.Plugins.Microsoft.csproj @@ -51,6 +51,7 @@ +