Browse Source

Fix build.

pull/881/merge
Daniel Grunwald 8 years ago
parent
commit
1d029b36cb
  1. 1
      ICSharpCode.Decompiler/IL/ILReader.cs
  2. 3
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  3. 16
      ILSpy.BamlDecompiler/BamlResourceEntryNode.cs
  4. 2
      ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs
  5. 10
      ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs

1
ICSharpCode.Decompiler/IL/ILReader.cs

@ -312,6 +312,7 @@ namespace ICSharpCode.Decompiler.IL @@ -312,6 +312,7 @@ namespace ICSharpCode.Decompiler.IL
/// </summary>
public ILFunction ReadIL(Cil.MethodBody body, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
Init(body);
ReadInstructions(cancellationToken);
var blockBuilder = new BlockBuilder(body, typeSystem, variableByExceptionHandler);

3
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

@ -6,6 +6,7 @@ using System.Collections; @@ -6,6 +6,7 @@ using System.Collections;
using System.IO;
using System.Linq;
using System.Resources;
using System.Threading;
using System.Xml.Linq;
using ICSharpCode.Decompiler.Tests.Helpers;
using Mono.Cecil;
@ -113,7 +114,7 @@ namespace ILSpy.BamlDecompiler.Tests @@ -113,7 +114,7 @@ namespace ILSpy.BamlDecompiler.Tests
Resource res = assembly.MainModule.Resources.First();
Stream bamlStream = LoadBaml(res, name + ".baml");
Assert.IsNotNull(bamlStream);
XDocument document = BamlResourceEntryNode.LoadIntoDocument(resolver, assembly, bamlStream);
XDocument document = BamlResourceEntryNode.LoadIntoDocument(resolver, assembly, bamlStream, CancellationToken.None);
XamlIsEqual(File.ReadAllText(sourcePath), document.ToString());
}

16
ILSpy.BamlDecompiler/BamlResourceEntryNode.cs

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
@ -32,7 +33,7 @@ namespace ILSpy.BamlDecompiler @@ -32,7 +33,7 @@ namespace ILSpy.BamlDecompiler
() => {
AvalonEditTextOutput output = new AvalonEditTextOutput();
try {
if (LoadBaml(output))
if (LoadBaml(output, token))
highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
} catch (Exception ex) {
output.Write(ex.ToString());
@ -44,33 +45,34 @@ namespace ILSpy.BamlDecompiler @@ -44,33 +45,34 @@ namespace ILSpy.BamlDecompiler
return true;
}
bool LoadBaml(AvalonEditTextOutput output)
bool LoadBaml(AvalonEditTextOutput output, CancellationToken cancellationToken)
{
var asm = this.Ancestors().OfType<AssemblyTreeNode>().FirstOrDefault().LoadedAssembly;
Data.Position = 0;
XDocument xamlDocument = LoadIntoDocument(asm.GetAssemblyResolver(), asm.AssemblyDefinition, Data);
XDocument xamlDocument = LoadIntoDocument(asm.GetAssemblyResolver(), asm.AssemblyDefinition, Data, cancellationToken);
output.Write(xamlDocument.ToString());
return true;
}
internal static XDocument LoadIntoDocument(IAssemblyResolver resolver, AssemblyDefinition asm, Stream stream)
internal static XDocument LoadIntoDocument(IAssemblyResolver resolver, AssemblyDefinition asm, Stream stream, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
XDocument xamlDocument;
using (XmlBamlReader reader = new XmlBamlReader(stream, new CecilTypeResolver(resolver, asm))) {
xamlDocument = XDocument.Load(reader);
ConvertConnectionIds(xamlDocument, asm);
ConvertConnectionIds(xamlDocument, asm, cancellationToken);
ConvertToEmptyElements(xamlDocument.Root);
MoveNamespacesToRoot(xamlDocument, reader.XmlnsDefinitions);
return xamlDocument;
}
}
static void ConvertConnectionIds(XDocument xamlDocument, AssemblyDefinition asm)
static void ConvertConnectionIds(XDocument xamlDocument, AssemblyDefinition asm, CancellationToken cancellationToken)
{
var attr = xamlDocument.Root.Attribute(XName.Get("Class", XmlBamlReader.XWPFNamespace));
if (attr != null) {
string fullTypeName = attr.Value;
var mappings = new ConnectMethodDecompiler(asm).DecompileEventMappings(fullTypeName);
var mappings = new ConnectMethodDecompiler(asm).DecompileEventMappings(fullTypeName, cancellationToken);
RemoveConnectionIds(xamlDocument.Root, mappings);
}
}

2
ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs

@ -35,7 +35,7 @@ namespace ILSpy.BamlDecompiler @@ -35,7 +35,7 @@ namespace ILSpy.BamlDecompiler
public string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, DecompilationOptions options)
{
var document = BamlResourceEntryNode.LoadIntoDocument(assembly.GetAssemblyResolver(), assembly.AssemblyDefinition, stream);
var document = BamlResourceEntryNode.LoadIntoDocument(assembly.GetAssemblyResolver(), assembly.AssemblyDefinition, stream, options.CancellationToken);
fileName = Path.ChangeExtension(fileName, ".xaml");
document.Save(Path.Combine(options.SaveAsProjectDirectory, fileName));
return fileName;

10
ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.IL;
@ -34,7 +34,7 @@ namespace ILSpy.BamlDecompiler @@ -34,7 +34,7 @@ namespace ILSpy.BamlDecompiler
this.assembly = assembly;
}
public Dictionary<long, EventRegistration[]> DecompileEventMappings(string fullTypeName)
public Dictionary<long, EventRegistration[]> DecompileEventMappings(string fullTypeName, CancellationToken cancellationToken)
{
var result = new Dictionary<long, EventRegistration[]>();
TypeDefinition type = this.assembly.MainModule.GetType(fullTypeName);
@ -57,9 +57,11 @@ namespace ILSpy.BamlDecompiler @@ -57,9 +57,11 @@ namespace ILSpy.BamlDecompiler
// decompile method and optimize the switch
var typeSystem = new DecompilerTypeSystem(method.Module);
var ilReader = new ILReader(typeSystem);
var function = ilReader.ReadIL(method.Body);
var function = ilReader.ReadIL(method.Body, cancellationToken);
var context = new ILTransformContext { Settings = new DecompilerSettings(), TypeSystem = typeSystem };
var context = new ILTransformContext(function, typeSystem) {
CancellationToken = cancellationToken
};
function.RunTransforms(CSharpDecompiler.GetILTransforms(), context);
var block = function.Body.Children.OfType<Block>().First();

Loading…
Cancel
Save