mirror of https://github.com/icsharpcode/ILSpy.git
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							44 lines
						
					
					
						
							1.5 KiB
						
					
					
				
			
		
		
	
	
							44 lines
						
					
					
						
							1.5 KiB
						
					
					
				// Copyright (c) AlphaSierraPapa for the SharpDevelop Team | 
						|
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) | 
						|
 | 
						|
using System; | 
						|
using System.ComponentModel.Composition; | 
						|
using System.IO; | 
						|
 | 
						|
using ICSharpCode.ILSpy.TreeNodes; | 
						|
using ICSharpCode.ILSpy; | 
						|
 | 
						|
namespace ILSpy.BamlDecompiler | 
						|
{ | 
						|
	[Export(typeof(IResourceNodeFactory))] | 
						|
	public sealed class BamlResourceNodeFactory : IResourceNodeFactory | 
						|
	{ | 
						|
		public ILSpyTreeNode CreateNode(Mono.Cecil.Resource resource) | 
						|
		{ | 
						|
			return null; | 
						|
		} | 
						|
		 | 
						|
		public ILSpyTreeNode CreateNode(string key, object data) | 
						|
		{ | 
						|
			if (key.EndsWith(".baml", StringComparison.OrdinalIgnoreCase) && data is Stream) | 
						|
				return new BamlResourceEntryNode(key, (Stream)data); | 
						|
			else | 
						|
				return null; | 
						|
		} | 
						|
	} | 
						|
 | 
						|
	[Export(typeof(IResourceFileHandler))] | 
						|
	public sealed class BamlResourceFileHandler : IResourceFileHandler | 
						|
	{ | 
						|
		public string EntryType => "Page"; | 
						|
		public bool CanHandle(string name, DecompilationOptions options) => name.EndsWith(".baml", StringComparison.OrdinalIgnoreCase); | 
						|
 | 
						|
		public string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, DecompilationOptions options) | 
						|
		{ | 
						|
			var document = BamlResourceEntryNode.LoadIntoDocument(assembly.GetAssemblyResolver(), assembly.GetAssemblyDefinitionAsync().Result, stream, options.CancellationToken); | 
						|
			fileName = Path.ChangeExtension(fileName, ".xaml"); | 
						|
			document.Save(Path.Combine(options.SaveAsProjectDirectory, fileName)); | 
						|
			return fileName; | 
						|
		} | 
						|
	} | 
						|
}
 | 
						|
 |