Browse Source

read .reaources files as ResourceSet

- support viewing single images
pull/37/head
Siegfried Pammer 15 years ago
parent
commit
10ee9895da
  1. 100
      ILSpy/TreeNodes/ResourceListTreeNode.cs

100
ILSpy/TreeNodes/ResourceListTreeNode.cs

@ -2,10 +2,17 @@ @@ -2,10 +2,17 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.IO;
using System.Resources;
using System.Text;
using System.Windows;
using System.Windows.Baml2006;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using System.Xaml;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Utils;
using ICSharpCode.Decompiler;
@ -66,6 +73,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -66,6 +73,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public ResourceTreeNode(Resource r)
{
this.LazyLoading = true;
this.r = r;
}
@ -144,5 +152,95 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -144,5 +152,95 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
return false;
}
protected override void LoadChildren()
{
EmbeddedResource er = r as EmbeddedResource;
if (er != null) {
try {
Stream s = er.GetResourceStream();
ResourceSet set = new ResourceSet(s);
foreach (DictionaryEntry entry in set) {
if (entry.Value is Stream) {
Children.Add(new ResourceEntryNode(entry.Key.ToString(), entry.Value as Stream));
}
}
} catch (Exception) {
// MessageBox.Show(ex.ToString());
}
}
}
}
class ResourceEntryNode : ILSpyTreeNode
{
string key;
Stream value;
public override object Text {
get { return key.ToString(); }
}
public override object Icon {
get { return Images.Resource; }
}
public ResourceEntryNode(string key, Stream value)
{
this.key = key;
this.value = value;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, string.Format("{0} = {1}", key, value));
}
internal override bool View(DecompilerTextView textView)
{
AvalonEditTextOutput output = new AvalonEditTextOutput();
if (LoadImage(output))
textView.Show(output, null);
else if (LoadBaml(output))
textView.Show(output, null);
else
return false;
return true;
}
bool LoadImage(AvalonEditTextOutput output)
{
try {
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = value;
image.EndInit();
output.AddUIElement(() => new Image { Source = image });
output.WriteLine();
output.AddButton(Images.Save, "Save", delegate { Save(); });
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
return false;
}
return true;
}
bool LoadBaml(AvalonEditTextOutput output)
{
return false;
}
public override bool Save()
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = Path.GetFileName(DecompilerTextView.CleanUpName(key));
if (dlg.ShowDialog() == true) {
value.Position = 0;
using (var fs = dlg.OpenFile()) {
value.CopyTo(fs);
}
}
return true;
}
}
}

Loading…
Cancel
Save