Browse Source

Remove UIHelper.cs

pull/848/head
Siegfried Pammer 8 years ago
parent
commit
2f31d6f55a
  1. 1
      ILSpy/ILSpy.csproj
  2. 47
      ILSpy/Languages/CSharpLanguage.cs
  3. 1
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  4. 1
      ILSpy/TreeNodes/EventTreeNode.cs
  5. 1
      ILSpy/TreeNodes/FieldTreeNode.cs
  6. 1
      ILSpy/TreeNodes/MethodTreeNode.cs
  7. 1
      ILSpy/TreeNodes/NamespaceTreeNode.cs
  8. 1
      ILSpy/TreeNodes/PropertyTreeNode.cs
  9. 1
      ILSpy/TreeNodes/TypeTreeNode.cs
  10. 48
      ILSpy/TreeNodes/UIHelper.cs

1
ILSpy/ILSpy.csproj

@ -205,7 +205,6 @@ @@ -205,7 +205,6 @@
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyOverridesTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyTreeNode.cs" />
<Compile Include="TreeNodes\SearchMsdnContextMenuEntry.cs" />
<Compile Include="TreeNodes\UIHelper.cs" />
<EmbeddedResource Include="..\README.txt">
<Link>README.txt</Link>
</EmbeddedResource>

47
ILSpy/Languages/CSharpLanguage.cs

@ -31,6 +31,9 @@ using ICSharpCode.Decompiler.CSharp; @@ -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 @@ -46,10 +49,6 @@ namespace ICSharpCode.ILSpy
bool showAllMembers = false;
int transformCount = int.MaxValue;
public CSharpLanguage()
{
}
#if DEBUG
internal static IEnumerable<CSharpLanguage> GetDebugLanguages()
{
@ -106,6 +105,7 @@ namespace ICSharpCode.ILSpy @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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<ReferenceFolderTreeNode>().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 @@ -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) {

1
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -260,7 +260,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -260,7 +260,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
throw;
}
}
UIHelper.AddReferenceWarningMessage(this, output, language);
language.DecompileAssembly(assembly, output, options);
}

1
ILSpy/TreeNodes/EventTreeNode.cs

@ -108,7 +108,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -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);
}

1
ILSpy/TreeNodes/FieldTreeNode.cs

@ -120,7 +120,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -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);
}

1
ILSpy/TreeNodes/MethodTreeNode.cs

@ -132,7 +132,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -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);
}

1
ILSpy/TreeNodes/NamespaceTreeNode.cs

@ -58,7 +58,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -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<TypeTreeNode>().Select(t => t.TypeDefinition), output, options);
}
}

1
ILSpy/TreeNodes/PropertyTreeNode.cs

@ -177,7 +177,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -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);
}

1
ILSpy/TreeNodes/TypeTreeNode.cs

@ -123,7 +123,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -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);
}

48
ILSpy/TreeNodes/UIHelper.cs

@ -1,48 +0,0 @@ @@ -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<AssemblyTreeNode>().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<ReferenceFolderTreeNode>().First());
});
fancyOutput.WriteLine();
} else {
language.WriteCommentLine(output, line1);
language.WriteCommentLine(output, line2);
}
}
}
}
Loading…
Cancel
Save