preliminary implementation of Binary eXtensible Application Markup Language

This commit is contained in:
Michael Becker 2020-08-28 16:56:01 -04:00
parent 2048e911e8
commit 39d84b0b3c
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
9 changed files with 649 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<UniversalEditor Version="4.0">
<Associations>
<Association>
<Filters>
<Filter Title="XAML document (compiled)">
<FileNameFilters>
<FileNameFilter>*.baml</FileNameFilter>
</FileNameFilters>
</Filter>
</Filters>
<ObjectModels>
<ObjectModel TypeName="UniversalEditor.Plugins.Microsoft.Xaml.ObjectModels.XAML.XAMLObjectModel" />
</ObjectModels>
<DataFormats>
<DataFormat TypeName="UniversalEditor.Plugins.Microsoft.Xaml.DataFormats.BAML.BAMLDataFormat" />
</DataFormats>
</Association>
</Associations>
</UniversalEditor>

View File

@ -583,6 +583,7 @@
<Content Include="Editors\Database\Views\ScriptView.glade" />
<Content Include="Editors\Database\Views\DesignView.glade" />
<Content Include="Editors\Documentation\DocumentationEditor.glade" />
<Content Include="Extensions\Microsoft\Extensions\Xaml\Associations\BAML.uexml" />
<Content Include="Editors\Multimedia\VectorImage\VectorImageEditor.glade" />
<Content Include="Extensions\Amiga\Associations\VectorImage\AmigaKickstartVectorImage.uexml" />
<Content Include="Extensions\GraphicDesigner\Associations\VectorImage\SVG.uexml" />
@ -654,6 +655,9 @@
<Folder Include="Editors\Setup\" />
<Folder Include="Editors\Setup\BootstrapScript\" />
<Folder Include="Editors\Database\Views\" />
<Folder Include="Extensions\Microsoft\Extensions\" />
<Folder Include="Extensions\Microsoft\Extensions\Xaml\" />
<Folder Include="Extensions\Microsoft\Extensions\Xaml\Associations\" />
<Folder Include="Extensions\Amiga\Associations\VectorImage\" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,125 @@
//
// BAMLDataFormat.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
using System;
using UniversalEditor;
using UniversalEditor.IO;
using UniversalEditor.Plugins.Microsoft.Xaml.ObjectModels.XAML;
namespace UniversalEditor.Plugins.Microsoft.Xaml.DataFormats.BAML
{
public class BAMLDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
protected override DataFormatReference MakeReferenceInternal()
{
if (_dfr == null)
{
_dfr = base.MakeReferenceInternal();
_dfr.Capabilities.Add(typeof(XAMLObjectModel), DataFormatCapabilities.All);
}
return _dfr;
}
public string FeatureID { get; set; } = "MSBAML";
public Version ReaderVersion { get; set; } = new Version(0, 96);
public Version UpdaterVersion { get; set; } = new Version(0, 96);
public Version WriterVersion { get; set; } = new Version(0, 96);
protected override void LoadInternal(ref ObjectModel objectModel)
{
Reader reader = Accessor.Reader;
uint signatureLength = reader.ReadUInt32();
byte[] signatureData = reader.ReadBytes(signatureLength);
string signature = System.Text.Encoding.Unicode.GetString(signatureData);
FeatureID = signature;
ReaderVersion = Read2xUInt16Version(reader);
UpdaterVersion = Read2xUInt16Version(reader);
WriterVersion = Read2xUInt16Version(reader);
while (!reader.EndOfStream)
{
BAMLRecordType recordType = (BAMLRecordType)reader.ReadByte();
switch (recordType)
{
case BAMLRecordType.DocumentStart:
{
byte zero1 = reader.ReadByte();
int neg1 = reader.ReadInt32();
byte zero2 = reader.ReadByte();
break;
}
case BAMLRecordType.AssemblyInfo:
{
ushort unknown4a = reader.ReadUInt16();
byte unknown5a = reader.ReadByte();
string assemblyName = reader.ReadLengthPrefixedString();
Console.WriteLine("Assembly name: {0}", assemblyName);
break;
}
case BAMLRecordType.TypeInfo:
{
byte u = reader.ReadByte();
uint unknown4 = reader.ReadUInt32();
string typename = reader.ReadLengthPrefixedString();
Console.WriteLine("typename is {0}", typename);
break;
}
case BAMLRecordType.ElementStart:
{
byte u = reader.ReadByte();
ushort u1 = reader.ReadUInt16();
break;
}
}
}
}
private Version Read2xUInt16Version(Reader reader)
{
ushort majorVer = reader.ReadUInt16();
ushort minorVer = reader.ReadUInt16();
return new Version(majorVer, minorVer);
}
private void Write2xUInt16Version(Writer writer, Version value)
{
writer.WriteUInt16((ushort)value.Major);
writer.WriteUInt16((ushort)value.Minor);
}
protected override void SaveInternal(ObjectModel objectModel)
{
Writer writer = Accessor.Writer;
string signature = FeatureID;
byte[] signatureData = System.Text.Encoding.Unicode.GetBytes(signature);
writer.WriteUInt32((uint)signatureData.Length);
Write2xUInt16Version(writer, ReaderVersion);
Write2xUInt16Version(writer, UpdaterVersion);
Write2xUInt16Version(writer, WriterVersion);
}
}
}

View File

@ -0,0 +1,28 @@
//
// BAMLRecord.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.Plugins.Microsoft.Xaml.DataFormats.BAML
{
public abstract class BAMLRecord
{
public abstract BAMLRecordType RecordType { get; }
}
}

View File

@ -0,0 +1,308 @@
//
// BAMLRecord.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
namespace UniversalEditor.Plugins.Microsoft.Xaml.DataFormats.BAML
{
public enum BAMLRecordType : byte
{
Unknown = 0,
DocumentStart = 1,
DocumentEnd = 2,
/// <summary>
/// Start Element Node, which may be a CLR object or a DependencyObject
/// </summary>
ElementStart = 3,
ElementEnd = 4,
/// <summary>
/// Property Node, which may be a CLR property or a DependencyProperty
/// </summary>
Property = 5,
/// <summary>
/// Binary serialization of a property
/// </summary>
PropertyCustom = 6,
/// <summary>
/// Complex Property Node
/// </summary>
PropertyComplexStart = 7,
/// <summary>
/// End Complex Property Node
/// </summary>
PropertyComplexEnd = 8,
/// <summary>
/// Start Array Property Node
/// </summary>
PropertyArrayStart = 9,
/// <summary>
/// End Array Property Node
/// </summary>
PropertyArrayEnd = 10,
/// <summary>
/// Star IList Property Node
/// </summary>
PropertyIListStart = 11,
/// <summary>
/// End PropertyIListStart Node
/// </summary>
PropertyIListEnd = 12,
/// <summary>
/// Start IDictionary Property Node
/// </summary>
PropertyIDictionaryStart = 13,
/// <summary>
/// End IDictionary Property Node
/// </summary>
PropertyIDictionaryEnd = 14,
/// <summary>
/// LiteralContent Node
/// </summary>
LiteralContent = 15,
/// <summary>
/// Text Node
/// </summary>
Text = 16,
/// <summary>
/// Text that has an associated custom typeconverter
/// </summary>
TextWithConverter = 17,
/// <summary>
/// RoutedEventNode
/// </summary>
RoutedEvent = 18,
/// <summary>
/// ClrEvent Node
/// </summary>
ClrEvent = 19,
/// <summary>
/// XmlnsProperty Node
/// </summary>
XmlnsProperty = 20,
/// <summary>
/// XmlAttribute Node
/// </summary>
XmlAttribute = 21,
/// <summary>
/// Processing Intstruction Node
/// </summary>
ProcessingInstruction = 22,
/// <summary>
/// Comment Node
/// </summary>
Comment = 23,
/// <summary>
/// DefTag Node
/// </summary>
DefTag = 24,
/// <summary>
/// x:name="value" attribute. One typical use of this
/// attribute is to define a key to use when inserting an item into an IDictionary
/// </summary>
DefAttribute = 25,
/// <summary>
/// EndAttributes Node
/// </summary>
EndAttributes = 26,
/// <summary>
/// PI xml - clr namespace mapping
/// </summary>
PIMapping = 27,
/// <summary>
/// Assembly information
/// </summary>
AssemblyInfo = 28,
/// <summary>
/// Type information
/// </summary>
TypeInfo = 29,
/// <summary>
/// Type information for a Type that has an associated custom serializer
/// </summary>
TypeSerializerInfo = 30,
/// <summary>
/// Attribute (eg - properties and events) information
/// </summary>
AttributeInfo = 31,
/// <summary>
/// Resource information
/// </summary>
StringInfo = 32,
/// <summary>
/// Property Resource Reference
/// </summary>
PropertyStringReference = 33,
/// <summary>
/// Record for setting a property to a Type reference. This is used for
/// properties that are of type "Type"
/// </summary>
PropertyTypeReference = 34,
/// <summary>
/// Property that has a simple MarkupExtension value.
/// </summary>
PropertyWithExtension = 35, // 35
/// <summary>
/// Property that has an associated custom typeconverter
/// </summary>
PropertyWithConverter = 36,
/// <summary>
/// Start a deferable content block
/// </summary>
DeferableContentStart = 37,
/// <summary>
/// x:name="value" attribute when used within a defer load
/// dictionary. These keys are hoisted to the front of the dictionary when
/// written to baml.
/// </summary>
DefAttributeKeyString = 38,
/// <summary>
/// Implied key that is a Type attribute when used within a defer load
/// dictionary. These keys are hoisted to the front of the dictionary when
/// written to baml.
/// </summary>
DefAttributeKeyType = 39,
/// <summary>
/// This marks the start of an element tree that is used as the key in
/// an IDictionary.
/// </summary>
KeyElementStart = 40,
/// <summary>
/// This marks the end of an element tree that is used as the key in
/// an IDictionary.
/// </summary>
KeyElementEnd = 41,
/// <summary>
/// Record marks the start of a section containing constructor parameters
/// </summary>
ConstructorParametersStart = 42,
/// <summary>
/// Record marks the end of a section containing constructor parameters
/// </summary>
ConstructorParametersEnd = 43,
/// <summary>
/// Constructor parameter that has been resolved to a Type.
/// </summary>
ConstructorParameterType = 44,
/// <summary>
/// Record that has info about which event or id to connect to in an object tree.
/// </summary>
ConnectionId = 45,
/// <summary>
/// Record that set the conntent property context for the element
/// </summary>
ContentProperty = 46,
/// <summary>
/// ElementStartRecord that also carries an element name.
/// </summary>
NamedElementStart = 47,
/// <summary>
/// Start of StaticResourceExtension within the header of a deferred section.
/// </summary>
StaticResourceStart = 48,
/// <summary>
/// End of a StaticResourceExtension within the header of a deferred section.
/// </summary>
StaticResourceEnd = 49,
/// <summary>
/// BamlRecord that carries an identifier for a StaticResourceExtension
/// within the header of a deferred section.
/// </summary>
StaticResourceId = 50,
/// <summary>
/// This is a TextRecord that holds an Id for the String value it represents.
/// </summary>
TextWithId = 51,
/// <summary>
/// PresentationOptions:Freeze="value" attribute. Used for ignorable
/// WPF-specific parsing options
/// </summary>
PresentationOptionsAttribute = 52,
/// <summary>
/// Debugging information record that holds the source XAML linenumber.
/// </summary>
LineNumberAndPosition = 53,
/// <summary>
/// Debugging information record that holds the source XAML line position.
/// </summary>
LinePosition = 54,
/// <summary>
/// OptimizedStaticResourceExtension within the header of a deferred section.
/// </summary>
OptimizedStaticResource = 55,
/// <summary>
/// BamlPropertyRecord that carries an identifier for a StaticResourceExtension
/// within the header of a deferred section.
/// </summary>
PropertyWithStaticResourceId = 56
}
}

View File

@ -0,0 +1,29 @@
//
// BAMLAssemblyInfoRecord.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.Plugins.Microsoft.Xaml.DataFormats.BAML.Records
{
public class BAMLAssemblyInfoRecord : BAMLRecord
{
public override BAMLRecordType RecordType => BAMLRecordType.AssemblyInfo;
}
}

View File

@ -0,0 +1,34 @@
//
// XamlObjectModel.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.Plugins.Microsoft.Xaml.ObjectModels.XAML
{
public class XAMLObjectModel : ObjectModel
{
public override void Clear()
{
}
public override void CopyTo(ObjectModel where)
{
}
}
}

View File

@ -0,0 +1,46 @@
//
// AssemblyInfo.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("UniversalEditor.Plugins.Microsoft.Xaml")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mike Becker's Software")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Mike Becker's Software")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{71BA711E-BF60-4E5E-8E8D-14DCB6CE2AAF}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>UniversalEditor.Plugins.Microsoft.Xaml</RootNamespace>
<AssemblyName>UniversalEditor.Plugins.Microsoft.Xaml</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<ReleaseVersion>4.0.2019.12</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="DataFormats\BAML\Records\BAMLAssemblyInfoRecord.cs" />
<Compile Include="DataFormats\BAML\BAMLRecord.cs" />
<Compile Include="DataFormats\BAML\BAMLDataFormat.cs" />
<Compile Include="DataFormats\BAML\BAMLRecordType.cs" />
<Compile Include="ObjectModels\XAML\XAMLObjectModel.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="DataFormats\" />
<Folder Include="DataFormats\BAML\" />
<Folder Include="DataFormats\BAML\Records\" />
<Folder Include="ObjectModels\" />
<Folder Include="ObjectModels\XAML\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
<Project>{2D4737E6-6D95-408A-90DB-8DFF38147E85}</Project>
<Name>UniversalEditor.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>