diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Abomination/DataFormats/FileSystem/Abomination/AWFDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/DataFormats/FileSystem/Abomination/AWFDataFormat.cs new file mode 100644 index 00000000..a6aebcb4 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/DataFormats/FileSystem/Abomination/AWFDataFormat.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.FileSystem.Abomination +{ + public class AWFDataFormat : 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("Abomination: The Nemesis Project AWF archive", new string[] { "*.awf" }); + } + 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; + uint fileCount = reader.ReadUInt32(); + + for (uint i = 0; i < fileCount; i++) + { + uint offset = reader.ReadUInt32(); + string fileName = reader.ReadFixedLengthString(260); + + uint length = reader.PeekUInt32(); + length -= offset; + + File file = fsom.AddFile(fileName); + file.Size = length; + file.Properties.Add("offset", offset); + file.Properties.Add("length", length); + file.Properties.Add("reader", reader); + file.DataRequest += file_DataRequest; + } + } + + private void file_DataRequest(object sender, DataRequestEventArgs e) + { + File file = (sender as File); + uint offset = (uint)file.Properties["offset"]; + uint length = (uint)file.Properties["length"]; + Reader reader = (Reader)file.Properties["reader"]; + + reader.Seek(offset, SeekOrigin.Current); + byte[] data = reader.ReadBytes(length); + e.Data = data; + } + + protected override void SaveInternal(ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) throw new ObjectModelNotSupportedException(); + + File[] files = fsom.GetAllFiles(); + Writer writer = base.Accessor.Writer; + writer.WriteUInt32((uint)files.Length); + + uint offset = (uint)(4 + ((4 + 260) * files.Length)); + foreach (File file in files) + { + writer.WriteUInt32(offset); + writer.WriteFixedLengthString(file.Name, 260); + offset += (uint)file.Size; + } + foreach (File file in files) + { + writer.WriteBytes(file.GetDataAsByteArray()); + } + writer.Flush(); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Abomination/DataFormats/FileSystem/Abomination/CLTDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/DataFormats/FileSystem/Abomination/CLTDataFormat.cs new file mode 100644 index 00000000..60ce2ef7 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/DataFormats/FileSystem/Abomination/CLTDataFormat.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.FileSystem.Abomination +{ + public class CLTDataFormat : 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("Abomination: The Nemesis Project CLT archive", new byte?[][] { new byte?[] { (byte)'A', (byte)'W', (byte)'A', (byte)'D' } }, new string[] { "*.clt" }); + } + 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; + string AWAD = reader.ReadFixedLengthString(4); + if (AWAD != "AWAD") throw new InvalidDataFormatException("File does not begin with 'AWAD'"); + + uint fileCount = reader.ReadUInt32(); + for (uint i = 0; i < fileCount; i++) + { + string fileName = reader.ReadFixedLengthString(260); + uint length = reader.ReadUInt32(); + uint offset = reader.ReadUInt32(); + + File file = fsom.AddFile(fileName); + file.Size = length; + file.Properties.Add("length", length); + file.Properties.Add("offset", offset); + file.Properties.Add("reader", reader); + file.DataRequest += file_DataRequest; + } + } + + private void file_DataRequest(object sender, DataRequestEventArgs e) + { + File file = (sender as File); + uint length = (uint)file.Properties["length"]; + uint offset = (uint)file.Properties["offset"]; + Reader reader = (Reader)file.Properties["reader"]; + reader.Seek(offset, SeekOrigin.Begin); + byte[] data = reader.ReadBytes(length); + e.Data = data; + } + + protected override void SaveInternal(ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + if (fsom == null) throw new ObjectModelNotSupportedException(); + + Writer writer = base.Accessor.Writer; + writer.WriteFixedLengthString("AWAD"); + + File[] files = fsom.GetAllFiles(); + writer.WriteUInt32((uint)files.Length); + uint offset = (uint)(8 + ((260 + 4 + 4) * files.Length)); + + foreach (File file in files) + { + writer.WriteFixedLengthString(file.Name, 260); + writer.WriteUInt32((uint)file.Size); + writer.WriteUInt32(offset); + } + foreach (File file in files) + { + writer.WriteBytes(file.GetDataAsByteArray()); + } + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Abomination/Properties/AssemblyInfo.cs b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..68b54d99 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UniversalEditor.Plugins.Abomination")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("UniversalEditor.Plugins.Abomination")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ad44d24e-73c8-42cc-825b-081edd7b1712")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Abomination/UniversalEditor.Plugins.Abomination.csproj b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/UniversalEditor.Plugins.Abomination.csproj new file mode 100644 index 00000000..a5d29aa1 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Abomination/UniversalEditor.Plugins.Abomination.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {D4D9C9A6-04A4-46AD-8238-2493A455723F} + Library + Properties + UniversalEditor + UniversalEditor.Plugins.Abomination + v3.5 + 512 + + + + true + full + false + ..\..\Output\Debug\Plugins\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\Output\Release\Plugins\ + TRACE + prompt + 4 + + + + + + + + + + + + + {2d4737e6-6d95-408a-90db-8dff38147e85} + UniversalEditor.Core + + + {30467e5c-05bc-4856-aadc-13906ef4cadd} + UniversalEditor.Essential + + + + + \ No newline at end of file diff --git a/CSharp/UniversalEditor.sln b/CSharp/UniversalEditor.sln index 24ec82d8..e6f5a599 100644 --- a/CSharp/UniversalEditor.sln +++ b/CSharp/UniversalEditor.sln @@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.UserInterfa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.NewWorldComputing.UserInterface.WindowsForms", "Environments\WindowsForms\Plugins\UniversalEditor.Plugins.NewWorldComputing.UserInterface.WindowsForms\UniversalEditor.Plugins.NewWorldComputing.UserInterface.WindowsForms.csproj", "{4250B20B-2DC9-432F-B0C2-BD20B80B4970}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Abomination", "Plugins\UniversalEditor.Plugins.Abomination\UniversalEditor.Plugins.Abomination.csproj", "{D4D9C9A6-04A4-46AD-8238-2493A455723F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -191,6 +193,12 @@ Global {4250B20B-2DC9-432F-B0C2-BD20B80B4970}.Release|Any CPU.ActiveCfg = Release|Any CPU {4250B20B-2DC9-432F-B0C2-BD20B80B4970}.Release|Any CPU.Build.0 = Release|Any CPU {4250B20B-2DC9-432F-B0C2-BD20B80B4970}.Release|x86.ActiveCfg = Release|Any CPU + {D4D9C9A6-04A4-46AD-8238-2493A455723F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4D9C9A6-04A4-46AD-8238-2493A455723F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4D9C9A6-04A4-46AD-8238-2493A455723F}.Debug|x86.ActiveCfg = Debug|Any CPU + {D4D9C9A6-04A4-46AD-8238-2493A455723F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4D9C9A6-04A4-46AD-8238-2493A455723F}.Release|Any CPU.Build.0 = Release|Any CPU + {D4D9C9A6-04A4-46AD-8238-2493A455723F}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -211,14 +219,15 @@ Global {19AEFD28-37E8-4FFD-B879-FEE57824689D} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {76FD1306-9CA4-428F-993B-B7E4EEEACBF3} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {26095090-3F7D-4DB5-A9BF-4C687230FC0F} = {71CFF024-26F7-4626-A526-B435FDF8D64E} + {D4D9C9A6-04A4-46AD-8238-2493A455723F} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {FE016EA3-DC31-4A92-8B0A-8C746EC117E1} = {46041F27-7C1C-4209-B72B-251EDB5D4C61} {C1F34183-7A2F-41A6-9958-F6F329099654} = {A846CA33-9CAA-4237-B14F-8721DBA89442} - {2013757E-4240-4E07-AD22-91219AD9B74F} = {C1F34183-7A2F-41A6-9958-F6F329099654} {5A423A3E-51C5-4188-8AD5-FB5C0CB76C6A} = {C1F34183-7A2F-41A6-9958-F6F329099654} + {2013757E-4240-4E07-AD22-91219AD9B74F} = {C1F34183-7A2F-41A6-9958-F6F329099654} {D3CE7A47-3989-4B6D-9867-0EA3C8DD7AB1} = {C1F34183-7A2F-41A6-9958-F6F329099654} {54990D5E-CE09-459F-916E-AF13101765B4} = {C1F34183-7A2F-41A6-9958-F6F329099654} - {BCBB72BD-0ECB-4FF2-8D91-E466361FB6F9} = {2013757E-4240-4E07-AD22-91219AD9B74F} {617D9EB5-CA93-45D6-AA6B-5A012B7698AC} = {5A423A3E-51C5-4188-8AD5-FB5C0CB76C6A} + {BCBB72BD-0ECB-4FF2-8D91-E466361FB6F9} = {2013757E-4240-4E07-AD22-91219AD9B74F} {4250B20B-2DC9-432F-B0C2-BD20B80B4970} = {D3CE7A47-3989-4B6D-9867-0EA3C8DD7AB1} {118E40C4-323E-4B4B-8EF4-38EED6CC5E83} = {54990D5E-CE09-459F-916E-AF13101765B4} EndGlobalSection