diff --git a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj index 88aa520f9..8e2f0c90b 100644 --- a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj +++ b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj @@ -80,12 +80,8 @@ - - - - @@ -94,7 +90,6 @@ - diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs deleted file mode 100644 index b33379323..000000000 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) Cristian Civera (cristian@aspitalia.com) -// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; -using System.Text; -using System.IO; -using System.Linq; -using Microsoft.Win32; -using System.Threading; -using System.Security.Permissions; -using System.Security; - -namespace Ricciolo.StylesExplorer.MarkupReflection -{ - public delegate void AssemblyResolveEventHandler(object s, AssemblyResolveEventArgs e); - - public class AppDomainTypeResolver : MarshalByRefObject, ITypeResolver - { - private readonly AppDomain _domain; - private string baseDir; - - public event AssemblyResolveEventHandler AssemblyResolve; - - public static AppDomainTypeResolver GetIntoNewAppDomain(string baseDir) - { - AppDomainSetup info = new AppDomainSetup(); - info.ApplicationBase = Environment.CurrentDirectory; - AppDomain domain = AppDomain.CreateDomain("AppDomainTypeResolver", null, info, new PermissionSet(PermissionState.Unrestricted)); - AppDomainTypeResolver resolver = (AppDomainTypeResolver)domain.CreateInstanceAndUnwrap(typeof(AppDomainTypeResolver).Assembly.FullName, - typeof(AppDomainTypeResolver).FullName, false, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new object[] { domain, baseDir }, null, null, null); - - return resolver; - } - - Assembly domain_AssemblyResolve(object sender, ResolveEventArgs args) - { - // Cerco di risolvere automaticamente - AssemblyName name = new AssemblyName(args.Name); - string fileName = Path.Combine(this.baseDir, name.Name + ".exe"); - if (!File.Exists(fileName)) - fileName = Path.Combine(this.baseDir, name.Name + ".dll"); - - // Carico il percorso autocalcolato - if (File.Exists(fileName)) - return Assembly.LoadFile(fileName); - - if (AssemblyResolve != null) - { - AssemblyResolveEventArgs e = new AssemblyResolveEventArgs(args.Name, this.baseDir); - AssemblyResolve(this, e); - if (!String.IsNullOrEmpty(e.Location) && File.Exists(e.Location)) - return Assembly.LoadFile(e.Location); - } - - return null; - } - - public static void DestroyResolver(AppDomainTypeResolver resolver) - { - if (resolver == null) throw new ArgumentNullException("resolver"); - - ThreadPool.QueueUserWorkItem(delegate - { - AppDomain.Unload(resolver.Domain); - }); - } - - protected AppDomainTypeResolver(AppDomain domain, string baseDir) - { - _domain = domain; - this.baseDir = baseDir; - - domain.AssemblyResolve += new ResolveEventHandler(domain_AssemblyResolve); - } - - public BamlAssembly LoadAssembly(AssemblyName asm) - { - //return new BamlAssembly(Assembly.Load(asm)); - return new BamlAssembly(_domain.Load(asm)); - } - - public BamlAssembly LoadAssembly(string location) - { - Assembly asm = Assembly.LoadFile(location); - return new BamlAssembly(asm); - //return _domain.Load(System.IO.File.ReadAllBytes(location)); - //return Assembly.LoadFrom(location); - } - - public BamlAssembly[] GetReferencedAssemblies(BamlAssembly asm) - { - AssemblyName[] list = asm.Assembly.GetReferencedAssemblies(); - - return (from an in list - select this.LoadAssembly(an)).ToArray(); - } - - public AppDomain Domain - { - get { return _domain; } - } - - #region ITypeResolver Members - - public IType GetTypeByAssemblyQualifiedName(string name) - { - return new DotNetType(name); - } - - public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType) - { - if (name == null) throw new ArgumentNullException("name"); - if (ownerType == null) throw new ArgumentNullException("ownerType"); - if (targetType == null) throw new ArgumentNullException("targetType"); - - Type dOwnerType = ((DotNetType)ownerType).Type; - Type dTargetType = ((DotNetType)targetType).Type; - - try - { - DependencyPropertyDescriptor propertyDescriptor = DependencyPropertyDescriptor.FromName(name, dOwnerType, dTargetType); - if (propertyDescriptor != null) - return new WpfDependencyPropertyDescriptor(propertyDescriptor); - return null; - } - catch (Exception) - { - return null; - } - } - - public bool IsLocalAssembly(string name) - { - return false; - } - - public string RuntimeVersion { - get { - throw new NotImplementedException(); - } - } - - #endregion - - public override object InitializeLifetimeService() - { - return null; - } - } - - public class AssemblyResolveEventArgs : MarshalByRefObject - { - - private string _location; - private string _name; - private string _baseDir; - - public AssemblyResolveEventArgs(string name, string baseDir) - { - _name = name; - _baseDir = baseDir; - } - - public string Location - { - get { return _location; } - set { _location = value; } - } - - public string Name - { - get { return _name; } - } - - public string BaseDir - { - get { return _baseDir; } - } - } -} diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlAssembly.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlAssembly.cs deleted file mode 100644 index d9d71860f..000000000 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlAssembly.cs +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) Cristian Civera (cristian@aspitalia.com) -// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Reflection; -using System.Resources; -using System.Text; - -namespace Ricciolo.StylesExplorer.MarkupReflection -{ - public class BamlAssembly : MarshalByRefObject - { - private readonly string _filePath; - private Assembly _assembly; - private BamlFileList _bamlFile; - - public BamlAssembly(Assembly assembly) - { - _assembly = assembly; - _filePath = assembly.CodeBase; - - ReadBaml(); - } - - public BamlAssembly(string filePath) - { - this._filePath = Path.GetFullPath(filePath); - this._assembly = Assembly.LoadFile(this.FilePath); - if (String.Compare(this.Assembly.CodeBase, this.FilePath, true) != 0) - throw new ArgumentException("Cannot load filePath because Assembly is already loaded", "filePath"); - - ReadBaml(); - } - - private void ReadBaml() - { - // Get available names - string[] resources = this.Assembly.GetManifestResourceNames(); - foreach (string res in resources) - { - // Solo le risorse - if (String.Compare(Path.GetExtension(res), ".resources", true) != 0) continue; - - // Get stream - using (Stream stream = this.Assembly.GetManifestResourceStream(res)) - { - try - { - ResourceReader reader = new ResourceReader(stream); - foreach (DictionaryEntry entry in reader) - { - if (String.Compare(Path.GetExtension(entry.Key.ToString()), ".baml", true) == 0 && entry.Value is Stream) - { - BamlFile bm = new BamlFile(GetAssemblyResourceUri(entry.Key.ToString()), (Stream)entry.Value); - this.BamlFiles.Add(bm); - } - } - } - catch (ArgumentException) - {} - } - } - } - - private Uri GetAssemblyResourceUri(string resourceName) - { - AssemblyName asm = this.Assembly.GetName(); - byte[] data = asm.GetPublicKeyToken(); - StringBuilder token = new StringBuilder(data.Length * 2); - for (int x = 0; x < data.Length; x++) - { - token.Append(data[x].ToString("x", System.Globalization.CultureInfo.InvariantCulture)); - } - - return new Uri(String.Format(@"{0};V{1};{2};component\{3}", asm.Name, asm.Version, token, Path.ChangeExtension(resourceName, ".xaml")), UriKind.RelativeOrAbsolute); - } - - public string FilePath - { - get { return _filePath; } - } - - public Assembly Assembly - { - get { return _assembly; } - } - - public BamlFileList BamlFiles - { - get - { - if (_bamlFile == null) - _bamlFile = new BamlFileList(); - return _bamlFile; - } - } - - public override object InitializeLifetimeService() - { - return null; - } - } - - [Serializable()] - public class BamlFileList : Collection - {} - -} diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlFile.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlFile.cs deleted file mode 100644 index d4af6bb81..000000000 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlFile.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) Cristian Civera (cristian@aspitalia.com) -// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) - -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Resources; -using System.Text; -using System.Windows; - -namespace Ricciolo.StylesExplorer.MarkupReflection -{ - /// - /// Rappresenta un singole file Baml all'interno di un assembly - /// - public class BamlFile : Component - { - private Uri _uri; - private readonly Stream _stream; - - public BamlFile(Uri uri, Stream stream) - { - if (uri == null) - new ArgumentNullException("uri"); - if (stream == null) - throw new ArgumentNullException("stream"); - - _uri = uri; - _stream = stream; - } - - /// - /// Carica il Baml attraverso il motore di WPF con Application.LoadComponent - /// - /// - public object LoadContent() - { - try - { - return Application.LoadComponent(this.Uri); - } - catch (Exception e) - { - throw new InvalidOperationException("Invalid baml file.", e); - } - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - if (disposing) - this.Stream.Dispose(); - } - - public override object InitializeLifetimeService() - { - return null; - } - - /// - /// Restituisce lo stream originale contenente il Baml - /// - public Stream Stream - { - get { return _stream; } - } - - /// - /// Restituisce l'indirizzo secondo lo schema pack:// - /// - public Uri Uri - { - get { return _uri; } - } - - } -} diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs deleted file mode 100644 index 313863bd0..000000000 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Cristian Civera (cristian@aspitalia.com) -// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Ricciolo.StylesExplorer.MarkupReflection -{ - public class DotNetType : MarshalByRefObject, IType - { - private readonly string _assemblyQualifiedName; - private Type _type; - - public DotNetType(string assemblyQualifiedName) - { - if (assemblyQualifiedName == null) throw new ArgumentNullException("assemblyQualifiedName"); - - _assemblyQualifiedName = assemblyQualifiedName; - _type = Type.GetType(assemblyQualifiedName, false, true); - } - - #region IType Members - - public string AssemblyQualifiedName - { - get { return _assemblyQualifiedName; } - } - - public bool IsSubclassOf(IType type) - { - if (type == null) throw new ArgumentNullException("type"); - if (!(type is DotNetType)) throw new ArgumentException("type"); - if (_type == null) return false; - return this._type.IsSubclassOf(((DotNetType)type).Type); - } - - public bool Equals(IType type) - { - if (type == null) throw new ArgumentNullException("type"); - if (!(type is DotNetType)) throw new ArgumentException("type"); - if (_type == null) return false; - return this._type.Equals(((DotNetType)type).Type); - } - - public IType BaseType { - get { - return new DotNetType(this._type.BaseType.AssemblyQualifiedName); - } - } - - #endregion - - public Type Type - { - get { return _type; } - } - - public override object InitializeLifetimeService() - { - return null; - } - } -} diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/WpfDependencyPropertyDescriptor.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/WpfDependencyPropertyDescriptor.cs deleted file mode 100644 index 2ac19f1a5..000000000 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/WpfDependencyPropertyDescriptor.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Cristian Civera (cristian@aspitalia.com) -// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Text; - -namespace Ricciolo.StylesExplorer.MarkupReflection -{ - public class WpfDependencyPropertyDescriptor : MarshalByRefObject, IDependencyPropertyDescriptor - { - private readonly DependencyPropertyDescriptor _propertyDescriptor; - - public WpfDependencyPropertyDescriptor(DependencyPropertyDescriptor propertyDescriptor) - { - if (propertyDescriptor == null) throw new ArgumentNullException("propertyDescriptor"); - _propertyDescriptor = propertyDescriptor; - } - - #region IDependencyPropertyDescriptor Members - - public bool IsAttached - { - get { return _propertyDescriptor.IsAttached; } - } - - #endregion - - public override object InitializeLifetimeService() - { - return null; - } - } -} diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index eb5887901..36518286f 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -112,11 +112,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection public const string XWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml"; public const string DefaultWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; - public XmlBamlReader(Stream stream) : this (stream, AppDomainTypeResolver.GetIntoNewAppDomain(Environment.CurrentDirectory)) - { - - } - public XmlBamlReader(Stream stream, ITypeResolver resolver) { if (stream == null)