From b60dbc74af8f8c78c39b95273c8826cce89c732c Mon Sep 17 00:00:00 2001 From: Ed Harvey Date: Mon, 28 Nov 2011 10:03:34 +1100 Subject: [PATCH] enhanced resource decompilation --- ILSpy/Controls/ResourceStringTable.xaml.cs | 6 +- .../ResourceNodes/ResourceEntryNode.cs | 8 +- .../ResourceNodes/ResourcesFileTreeNode.cs | 77 ++++++++++++++----- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/ILSpy/Controls/ResourceStringTable.xaml.cs b/ILSpy/Controls/ResourceStringTable.xaml.cs index b3aab0049..635cde341 100644 --- a/ILSpy/Controls/ResourceStringTable.xaml.cs +++ b/ILSpy/Controls/ResourceStringTable.xaml.cs @@ -23,13 +23,13 @@ namespace ICSharpCode.ILSpy.Controls /// public partial class ResourceStringTable : UserControl { - public ResourceStringTable(IEnumerable strings) + public ResourceStringTable(IEnumerable strings,Size maxSize) { InitializeComponent(); // set size to fit decompiler window // TODO: there should be a more transparent way to do this - MaxWidth = MainWindow.Instance.mainPane.ActualWidth-20; - MaxHeight = MainWindow.Instance.mainPane.ActualHeight-100; + MaxWidth = maxSize.Width; + MaxHeight = maxSize.Height; resourceListView.ItemsSource = strings; } diff --git a/ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs b/ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs index da58bde8f..6f746c6bb 100644 --- a/ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs +++ b/ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs @@ -68,9 +68,13 @@ namespace ICSharpCode.ILSpy.TreeNodes foreach (var factory in App.CompositionContainer.GetExportedValues()) { result = factory.CreateNode(key, data); if (result != null) - break; + return result; } - return result ?? new ResourceEntryNode(key, data as Stream); + var streamData = data as Stream; + if(streamData !=null) + result = new ResourceEntryNode(key, data as Stream); + + return result; } public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) diff --git a/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs b/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs index 94f279b5a..e4e73893d 100644 --- a/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs +++ b/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs @@ -48,10 +48,11 @@ namespace ICSharpCode.ILSpy.TreeNodes return null; } } - + sealed class ResourcesFileTreeNode : ResourceTreeNode { - ICollection> filteredEntries = new ObservableCollection>(); + ICollection> stringTableEntries = new ObservableCollection>(); + ICollection> otherEntries = new ObservableCollection>(); public ResourcesFileTreeNode(EmbeddedResource er) : base(er) @@ -78,30 +79,68 @@ namespace ICSharpCode.ILSpy.TreeNodes return; } foreach (DictionaryEntry entry in reader.Cast().OrderBy(e => e.Key.ToString())) { - if (entry.Value is String) - filteredEntries.Add(new KeyValuePair(entry.Key.ToString(), (string)entry.Value)); - else if (entry.Value is byte[]) - Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), new MemoryStream((byte[])entry.Value))); - else - Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), entry.Value)); + ProcessResourceEntry(entry); } } } - + + private void ProcessResourceEntry(DictionaryEntry entry) + { + var keyString = entry.Key.ToString(); + + if (entry.Value is String) { + stringTableEntries.Add(new KeyValuePair(keyString, (string)entry.Value)); + return; + } + + if (entry.Value is byte[]) { + Children.Add(ResourceEntryNode.Create(keyString, new MemoryStream((byte[])entry.Value))); + return; + } + + var node = ResourceEntryNode.Create(keyString, entry.Value); + if (node != null) { + Children.Add(node); + return; + } + + if (entry.Value is System.Globalization.CultureInfo) { + otherEntries.Add(new KeyValuePair(keyString, ((System.Globalization.CultureInfo)entry.Value).DisplayName)); + } else { + otherEntries.Add(new KeyValuePair(keyString, entry.Value.ToString())); + } + } + public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { + EnsureLazyChildren(); base.Decompile(language, output, options); - if (filteredEntries.Count == 0) - return; - ISmartTextOutput smartOutput = output as ISmartTextOutput; - if (null != smartOutput) { - smartOutput.AddUIElement( - delegate { - return new ResourceStringTable(filteredEntries); - } - ); + if (stringTableEntries.Count != 0) { + ISmartTextOutput smartOutput = output as ISmartTextOutput; + if (null != smartOutput) { + smartOutput.AddUIElement( + delegate { + return new ResourceStringTable(stringTableEntries, + new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 40, + MainWindow.Instance.mainPane.ActualHeight - 100)); + } + ); + } + output.WriteLine(); + } + if (otherEntries.Count != 0) { + ISmartTextOutput smartOutput = output as ISmartTextOutput; + if (null != smartOutput) { + smartOutput.AddUIElement( + delegate { + return new ResourceStringTable(otherEntries, + new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 40, + MainWindow.Instance.mainPane.ActualHeight - 100)); + } + ); + } + output.WriteLine(); } - output.WriteLine(); } } }