diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index a9437f6c1..a16cc4b54 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -205,7 +205,6 @@ - README.txt diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 5e6e08e13..e3a642d81 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -31,6 +31,9 @@ using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp.OutputVisitor; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.TypeSystem; +using System.Windows; +using System.Windows.Controls; +using ICSharpCode.ILSpy.TreeNodes; namespace ICSharpCode.ILSpy { @@ -46,10 +49,6 @@ namespace ICSharpCode.ILSpy bool showAllMembers = false; int transformCount = int.MaxValue; - public CSharpLanguage() - { - } - #if DEBUG internal static IEnumerable GetDebugLanguages() { @@ -106,6 +105,7 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) { + AddReferenceWarningMessage(method.Module.Assembly, output); WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(method.Module, options); WriteCode(output, options.DecompilerSettings, decompiler.Decompile(method), decompiler.TypeSystem); @@ -161,6 +161,7 @@ namespace ICSharpCode.ILSpy public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) { + AddReferenceWarningMessage(property.Module.Assembly, output); WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(property.Module, options); WriteCode(output, options.DecompilerSettings, decompiler.Decompile(property), decompiler.TypeSystem); @@ -168,6 +169,7 @@ namespace ICSharpCode.ILSpy /* public override void DecompileField(FieldDefinition field, ITextOutput output, DecompilationOptions options) { + AddReferenceWarningMessage(output); WriteCommentLine(output, TypeToString(field.DeclaringType, includeNamespace: true)); AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: field.DeclaringType, isSingleMember: true); if (field.IsLiteral) { @@ -216,6 +218,7 @@ namespace ICSharpCode.ILSpy */ public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options) { + AddReferenceWarningMessage(ev.Module.Assembly, output); WriteCommentLine(output, TypeToString(ev.DeclaringType, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(ev.Module, options); WriteCode(output, options.DecompilerSettings, decompiler.Decompile(ev), decompiler.TypeSystem); @@ -223,6 +226,7 @@ namespace ICSharpCode.ILSpy public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options) { + AddReferenceWarningMessage(type.Module.Assembly, output); WriteCommentLine(output, TypeToString(type, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(type.Module, options); WriteCode(output, options.DecompilerSettings, decompiler.Decompile(type), decompiler.TypeSystem); @@ -282,6 +286,40 @@ namespace ICSharpCode.ILSpy return null; } + void AddReferenceWarningMessage(AssemblyDefinition assembly, ITextOutput output) + { + var loadedAssembly = MainWindow.Instance.CurrentAssemblyList.GetAssemblies().FirstOrDefault(la => la.AssemblyDefinition == assembly); + if (loadedAssembly == null || !loadedAssembly.LoadedAssemblyReferencesInfo.Any(i => i.Value.HasErrors)) + return; + const string line1 = "Warning: Some assembly references could not be loaded. This might lead to incorrect decompilation of some parts,"; + const string line2 = "for ex. property getter/setter access. To get optimal decompilation results, please manually add the references to the list of loaded assemblies."; + if (output is ISmartTextOutput fancyOutput) { + fancyOutput.AddUIElement(() => new StackPanel { + Margin = new Thickness(5), + Orientation = Orientation.Horizontal, + Children = { + new Image { + Width = 32, + Height = 32, + Source = Images.LoadImage(this, "Images/Warning.png") + }, + new TextBlock { + Margin = new Thickness(5, 0, 0, 0), + Text = line1 + Environment.NewLine + line2 + } + } + }); + fancyOutput.WriteLine(); + fancyOutput.AddButton(Images.ViewCode, "Show assembly load log", delegate { + MainWindow.Instance.SelectNode(MainWindow.Instance.FindTreeNode(assembly).Children.OfType().First()); + }); + fancyOutput.WriteLine(); + } else { + WriteCommentLine(output, line1); + WriteCommentLine(output, line2); + } + } + public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options) { if (options.FullDecompilation && options.SaveAsProjectDirectory != null) { @@ -290,6 +328,7 @@ namespace ICSharpCode.ILSpy decompiler.DecompileProject(assembly.ModuleDefinition, options.SaveAsProjectDirectory, new TextOutputWriter(output), options.CancellationToken); } else { base.DecompileAssembly(assembly, output, options); + AddReferenceWarningMessage(assembly.AssemblyDefinition, output); output.WriteLine(); ModuleDefinition mainModule = assembly.ModuleDefinition; if (mainModule.Types.Count > 0) { diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index fdf99ce51..25a11a227 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -260,7 +260,6 @@ namespace ICSharpCode.ILSpy.TreeNodes throw; } } - UIHelper.AddReferenceWarningMessage(this, output, language); language.DecompileAssembly(assembly, output, options); } diff --git a/ILSpy/TreeNodes/EventTreeNode.cs b/ILSpy/TreeNodes/EventTreeNode.cs index ad216cde3..9b32e0339 100644 --- a/ILSpy/TreeNodes/EventTreeNode.cs +++ b/ILSpy/TreeNodes/EventTreeNode.cs @@ -108,7 +108,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - UIHelper.AddReferenceWarningMessage(this, output, language); language.DecompileEvent(ev, output, options); } diff --git a/ILSpy/TreeNodes/FieldTreeNode.cs b/ILSpy/TreeNodes/FieldTreeNode.cs index e4e508158..ea331015f 100644 --- a/ILSpy/TreeNodes/FieldTreeNode.cs +++ b/ILSpy/TreeNodes/FieldTreeNode.cs @@ -120,7 +120,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - UIHelper.AddReferenceWarningMessage(this, output, language); language.DecompileField(field, output, options); } diff --git a/ILSpy/TreeNodes/MethodTreeNode.cs b/ILSpy/TreeNodes/MethodTreeNode.cs index ca84cb21c..afe1c3998 100644 --- a/ILSpy/TreeNodes/MethodTreeNode.cs +++ b/ILSpy/TreeNodes/MethodTreeNode.cs @@ -132,7 +132,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - UIHelper.AddReferenceWarningMessage(this, output, language); language.DecompileMethod(method, output, options); } diff --git a/ILSpy/TreeNodes/NamespaceTreeNode.cs b/ILSpy/TreeNodes/NamespaceTreeNode.cs index 688c07028..5d7d4b448 100644 --- a/ILSpy/TreeNodes/NamespaceTreeNode.cs +++ b/ILSpy/TreeNodes/NamespaceTreeNode.cs @@ -58,7 +58,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - UIHelper.AddReferenceWarningMessage(this, output, language); language.DecompileNamespace(name, this.Children.OfType().Select(t => t.TypeDefinition), output, options); } } diff --git a/ILSpy/TreeNodes/PropertyTreeNode.cs b/ILSpy/TreeNodes/PropertyTreeNode.cs index 2bcbb4dfe..13d61ff52 100644 --- a/ILSpy/TreeNodes/PropertyTreeNode.cs +++ b/ILSpy/TreeNodes/PropertyTreeNode.cs @@ -177,7 +177,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - UIHelper.AddReferenceWarningMessage(this, output, language); language.DecompileProperty(property, output, options); } diff --git a/ILSpy/TreeNodes/TypeTreeNode.cs b/ILSpy/TreeNodes/TypeTreeNode.cs index dca97a7a4..3259db299 100644 --- a/ILSpy/TreeNodes/TypeTreeNode.cs +++ b/ILSpy/TreeNodes/TypeTreeNode.cs @@ -123,7 +123,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - UIHelper.AddReferenceWarningMessage(this, output, language); language.DecompileType(type, output, options); } diff --git a/ILSpy/TreeNodes/UIHelper.cs b/ILSpy/TreeNodes/UIHelper.cs deleted file mode 100644 index e61c8687c..000000000 --- a/ILSpy/TreeNodes/UIHelper.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using ICSharpCode.Decompiler; - -namespace ICSharpCode.ILSpy.TreeNodes -{ - public static class UIHelper - { - public static void AddReferenceWarningMessage(ILSpyTreeNode node, ITextOutput output, Language language) - { - var assemblyNode = node.AncestorsAndSelf().OfType().First(); - if (!assemblyNode.LoadedAssembly.LoadedAssemblyReferencesInfo.Any(i => i.Value.HasErrors)) - return; - const string line1 = "Warning: Some assembly references could not be loaded. This might lead to incorrect decompilation of some parts,"; - const string line2 = "for ex. property getter/setter access. To get optimal decompilation results, please manually add the references to the list of loaded assemblies."; - if (output is ISmartTextOutput fancyOutput) { - fancyOutput.AddUIElement(() => new StackPanel { - Margin = new Thickness(5), - Orientation = Orientation.Horizontal, - Children = { - new Image { - Width = 32, - Height = 32, - Source = Images.LoadImage(language, "Images/Warning.png") - }, - new TextBlock { - Margin = new Thickness(5, 0, 0, 0), - Text = line1 + Environment.NewLine + line2 - } - } - }); - fancyOutput.WriteLine(); - fancyOutput.AddButton(Images.ViewCode, "Show assembly load log", delegate { - MainWindow.Instance.SelectNode(assemblyNode.Children.OfType().First()); - }); - fancyOutput.WriteLine(); - } else { - language.WriteCommentLine(output, line1); - language.WriteCommentLine(output, line2); - } - } - } -}