Skip to content

Commit

Permalink
Implement Save as .resources and .resx for .resources node
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Dec 2, 2016
1 parent bdfc390 commit f7a7e96
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs
Expand Up @@ -27,6 +27,8 @@

using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.Controls;
using ICSharpCode.ILSpy.TextView;
using Microsoft.Win32;
using Mono.Cecil;

namespace ICSharpCode.ILSpy.TreeNodes
Expand Down Expand Up @@ -111,6 +113,37 @@ private void ProcessResourceEntry(DictionaryEntry entry)
otherEntries.Add(new SerializedObjectRepresentation(keyString, entryType, entry.Value.ToString()));
}
}

public override bool Save(DecompilerTextView textView)
{
EmbeddedResource er = this.Resource as EmbeddedResource;
if (er != null) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = DecompilerTextView.CleanUpName(er.Name);
dlg.Filter = "Resources file (*.resources)|*.resources|Resource XML file|*.resx";
if (dlg.ShowDialog() == true) {
Stream s = er.GetResourceStream();
s.Position = 0;
switch (dlg.FilterIndex) {
case 1:
using (var fs = dlg.OpenFile()) {
s.CopyTo(fs);
}
break;
case 2:
var reader = new ResourceReader(s);
using (var writer = new ResXResourceWriter(dlg.OpenFile())) {
foreach (DictionaryEntry entry in reader) {
writer.AddResource(entry.Key.ToString(), entry.Value);
}
}
break;
}
}
return true;
}
return false;
}

public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
Expand Down

0 comments on commit f7a7e96

Please sign in to comment.