mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
[WIP] Decompile to XML
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Humanizer;
|
||||
using Microsoft.Iris.Asm;
|
||||
using Microsoft.Iris.Asm.Models;
|
||||
using Microsoft.Iris.DecompXml.Mock;
|
||||
using Microsoft.Iris.Markup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,6 +19,7 @@ public class Decompiler
|
||||
private readonly MarkupLoadResult _dataTableLoadResult;
|
||||
private readonly Dictionary<string, XNamespace> _namespaces;
|
||||
private readonly Dictionary<string, string> _uriAliasMap;
|
||||
private Instruction[] _instructions;
|
||||
|
||||
private Decompiler(MarkupLoadResult loadResult, MarkupLoadResult dataTableLoadResult = null)
|
||||
{
|
||||
@@ -68,6 +70,10 @@ public class Decompiler
|
||||
|
||||
GetNamespaces();
|
||||
|
||||
_instructions = ObjectSection.Decode(_loadResult.ObjectSection)
|
||||
.OfType<Instruction>()
|
||||
.ToArray();
|
||||
|
||||
XNamespace nsUix = XNamespace.Get("http://schemas.microsoft.com/2007/uix");
|
||||
XElement xRoot = new(nsUix + "UIX", new XAttribute("xmlns", nsUix));
|
||||
|
||||
@@ -82,6 +88,16 @@ public class Decompiler
|
||||
new XAttribute("Name", name),
|
||||
new XAttribute("Base", baseTypeName));
|
||||
|
||||
var initPropOffset = export.InitializePropertiesOffset;
|
||||
|
||||
var defaultType = export.ConstructDefault();
|
||||
var initializedType = export.ConstructDefault();
|
||||
try
|
||||
{
|
||||
export.InitializeInstance(ref initializedType);
|
||||
}
|
||||
catch { }
|
||||
|
||||
var propertyElements = new XElement[export.Properties.Length];
|
||||
for (int i = 0; i < export.Properties.Length; i++)
|
||||
{
|
||||
@@ -92,6 +108,11 @@ public class Decompiler
|
||||
XElement xProperty = new(typeName,
|
||||
new XAttribute("Name", property.Name));
|
||||
|
||||
var defaultValue = property.GetValue(defaultType);
|
||||
var initializedValue = property.GetValue(initializedType);
|
||||
if (defaultValue != initializedValue)
|
||||
xProperty.Add(new XAttribute("TODO_DEFAULT", initializedValue));
|
||||
|
||||
propertyElements[i] = xProperty;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
using Microsoft.Iris.Library;
|
||||
using Microsoft.Iris.Markup;
|
||||
using Microsoft.Iris.Session;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.Iris.DecompXml.Mock;
|
||||
|
||||
internal class MockMarkupType : IMarkupTypeBase
|
||||
{
|
||||
private static readonly DeferredHandler s_executePendingScriptsHandler = ExecutePendingScripts;
|
||||
|
||||
private readonly Dictionary<string, object> _propertyStorage = [];
|
||||
private readonly Dictionary<SymbolReference, object> _symbolStorage = [];
|
||||
private readonly MarkupTypeSchema _typeSchema;
|
||||
|
||||
private List<IDisposableObject> _disposables = null;
|
||||
private ScriptRunScheduler _scriptRunScheduler = new();
|
||||
|
||||
public MockMarkupType(MarkupTypeSchema typeSchema)
|
||||
{
|
||||
_typeSchema = typeSchema;
|
||||
}
|
||||
|
||||
public TypeSchema TypeSchema => _typeSchema;
|
||||
|
||||
public MarkupListeners Listeners { get; set; }
|
||||
|
||||
public bool ScriptEnabled => true;
|
||||
|
||||
public Dictionary<object, object> Storage { get; } = [];
|
||||
|
||||
public IReadOnlyDictionary<string, object> Properties => _propertyStorage;
|
||||
|
||||
public IReadOnlyDictionary<SymbolReference, object> SymbolReferences => _symbolStorage;
|
||||
|
||||
public object GetProperty(string name) => _propertyStorage[name];
|
||||
|
||||
public void SetProperty(string name, object value) => _propertyStorage[name] = value;
|
||||
|
||||
public void NotifyInitialized() { }
|
||||
|
||||
public void NotifyScriptErrors() { }
|
||||
|
||||
public object ReadSymbol(SymbolReference symbolRef) => _symbolStorage[symbolRef];
|
||||
|
||||
public void WriteSymbol(SymbolReference symbolRef, object value) => _symbolStorage[symbolRef] = value;
|
||||
|
||||
public object RunScript(uint scriptId, bool ignoreErrors, ParameterContext parameterContext) => _typeSchema.Run(this, scriptId, ignoreErrors, parameterContext);
|
||||
|
||||
public void ScheduleScriptRun(uint scriptId, bool ignoreErrors)
|
||||
{
|
||||
if (!_scriptRunScheduler.Pending)
|
||||
DeferredCall.Post(DispatchPriority.Script, s_executePendingScriptsHandler, this);
|
||||
_scriptRunScheduler.ScheduleRun(scriptId, ignoreErrors);
|
||||
}
|
||||
|
||||
private static void ExecutePendingScripts(object args)
|
||||
{
|
||||
var mockType = (MockMarkupType)args;
|
||||
mockType._scriptRunScheduler.Execute(mockType);
|
||||
}
|
||||
|
||||
public void RegisterDisposable(IDisposableObject disposable)
|
||||
{
|
||||
_disposables ??= [];
|
||||
_disposables.Add(disposable);
|
||||
}
|
||||
|
||||
public bool UnregisterDisposable(ref IDisposableObject disposable)
|
||||
{
|
||||
if (_disposables != null)
|
||||
{
|
||||
int index = _disposables.IndexOf(disposable);
|
||||
if (index != -1)
|
||||
{
|
||||
disposable = _disposables[index];
|
||||
_disposables.RemoveAt(index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user