diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Descent/DataFormats/FileSystem/Descent/DescentHOGDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Descent/DataFormats/FileSystem/Descent/DescentHOGDataFormat.cs new file mode 100644 index 00000000..ce7a9382 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Descent/DataFormats/FileSystem/Descent/DescentHOGDataFormat.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.FileSystem.Descent +{ + public class DescentHOGDataFormat : 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("Descent HOG archive", new byte?[][] { new byte?[] { (byte)'D', (byte)'H', (byte)'F' } }, new string[] { "*.hog" }); + } + return _dfr; + } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + IO.Reader br = base.Accessor.Reader; + string DHF = br.ReadFixedLengthString(3); + if (DHF != "DHF") throw new InvalidDataFormatException("File does not begin with \"DHF\""); + + while (!br.EndOfStream) + { + string FileName = br.ReadFixedLengthString(13); + int length = br.ReadInt32(); + long offset = br.Accessor.Position; + + File file = new File(); + file.Name = FileName; + file.Size = length; + file.Properties.Add("reader", br); + file.Properties.Add("offset", offset); + file.DataRequest += file_DataRequest; + fsom.Files.Add(file); + + br.Accessor.Seek(length, IO.SeekOrigin.Current); + } + } + + private void file_DataRequest(object sender, DataRequestEventArgs e) + { + File file = (sender as File); + long offset = (long)file.Properties["offset"]; + IO.Reader reader = (IO.Reader)file.Properties["reader"]; + reader.Accessor.Seek(offset, IO.SeekOrigin.Begin); + e.Data = reader.ReadBytes(file.Size); + } + + protected override void SaveInternal(ObjectModel objectModel) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + IO.Writer bw = base.Accessor.Writer; + bw.WriteFixedLengthString("DHF"); + foreach (File file in fsom.Files) + { + bw.WriteFixedLengthString(file.Name, 13); + bw.WriteInt32((int)file.Size); + bw.WriteBytes(file.GetDataAsByteArray()); + } + bw.Flush(); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Descent/Properties/AssemblyInfo.cs b/CSharp/Plugins/UniversalEditor.Plugins.Descent/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..7fbbb0f9 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Descent/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.Descent")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("UniversalEditor.Plugins.Descent")] +[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("38142617-455a-4623-bcc6-2780711e6b72")] + +// 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.Descent/UniversalEditor.Plugins.Descent.csproj b/CSharp/Plugins/UniversalEditor.Plugins.Descent/UniversalEditor.Plugins.Descent.csproj new file mode 100644 index 00000000..96f72012 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Descent/UniversalEditor.Plugins.Descent.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2} + Library + Properties + UniversalEditor + UniversalEditor.Plugins.Descent + 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 65a20830..14ef5dcf 100644 --- a/CSharp/UniversalEditor.sln +++ b/CSharp/UniversalEditor.sln @@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Mul EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.ChaosWorks", "Plugins\UniversalEditor.Plugins.ChaosWorks\UniversalEditor.Plugins.ChaosWorks.csproj", "{30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Descent", "Plugins\UniversalEditor.Plugins.Descent\UniversalEditor.Plugins.Descent.csproj", "{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -123,6 +125,12 @@ Global {30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}.Release|Any CPU.ActiveCfg = Release|Any CPU {30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}.Release|Any CPU.Build.0 = Release|Any CPU {30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}.Release|x86.ActiveCfg = Release|Any CPU + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Debug|x86.ActiveCfg = Debug|Any CPU + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Release|Any CPU.Build.0 = Release|Any CPU + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -139,6 +147,7 @@ Global {BE4D0BA3-0888-42A5-9C09-FC308A4509D2} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {369CFD53-3E65-4A9E-8BDD-4CCD78BF3E33} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {30A2F772-8EC1-425A-8D5D-36A0BE4D6B66} = {71CFF024-26F7-4626-A526-B435FDF8D64E} + {3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2} = {71CFF024-26F7-4626-A526-B435FDF8D64E} {617D9EB5-CA93-45D6-AA6B-5A012B7698AC} = {46041F27-7C1C-4209-B72B-251EDB5D4C61} {FE016EA3-DC31-4A92-8B0A-8C746EC117E1} = {46041F27-7C1C-4209-B72B-251EDB5D4C61} EndGlobalSection