Added Abomination plugin

This commit is contained in:
Michael Becker 2014-06-04 19:16:44 -04:00
parent 2bf2fc1d26
commit 71ececb10f
5 changed files with 275 additions and 2 deletions

View File

@ -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();
}
}
}

View File

@ -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());
}
}
}
}

View File

@ -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")]

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D4D9C9A6-04A4-46AD-8238-2493A455723F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UniversalEditor</RootNamespace>
<AssemblyName>UniversalEditor.Plugins.Abomination</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataFormats\FileSystem\Abomination\AWFDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\Abomination\CLTDataFormat.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
<Project>{2d4737e6-6d95-408a-90db-8dff38147e85}</Project>
<Name>UniversalEditor.Core</Name>
</ProjectReference>
<ProjectReference Include="..\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
<Project>{30467e5c-05bc-4856-aadc-13906ef4cadd}</Project>
<Name>UniversalEditor.Essential</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -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