public override bool View(TabPageModel tabPage) { Stream s = Resource.TryOpenStream(); if (s != null && s.Length < DecompilerTextView.DefaultOutputLengthLimit) { s.Position = 0; FileType type = GuessFileType.DetectFileType(s); if (type != FileType.Binary) { s.Position = 0; AvalonEditTextOutput output = new AvalonEditTextOutput(); output.Title = Resource.Name; output.Write(FileReader.OpenStream(s, Encoding.UTF8).ReadToEnd()); string ext; if (type == FileType.Xml) { ext = ".xml"; } else { ext = Path.GetExtension(WholeProjectDecompiler.SanitizeFileName(Resource.Name)); } tabPage.ShowTextView(textView => textView.ShowNode(output, this, HighlightingManager.Instance.GetDefinitionByExtension(ext))); tabPage.SupportsLanguageSwitching = false; return(true); } } return(false); }
public void Execute(TextViewContext context) { // Get all assemblies in the selection that are stored inside a package. var selectedNodes = context.SelectedTreeNodes.OfType <AssemblyTreeNode>() .Where(asm => asm.PackageEntry != null).ToArray(); // Get root assembly to infer the initial directory for the save dialog. var bundleNode = selectedNodes.FirstOrDefault()?.Ancestors().OfType <AssemblyTreeNode>() .FirstOrDefault(asm => asm.PackageEntry == null); if (bundleNode == null) { return; } var assembly = selectedNodes[0].PackageEntry; SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = Path.GetFileName(WholeProjectDecompiler.SanitizeFileName(assembly.Name)); dlg.Filter = ".NET assemblies|*.dll;*.exe;*.winmd" + Resources.AllFiles; dlg.InitialDirectory = Path.GetDirectoryName(bundleNode.LoadedAssembly.FileName); if (dlg.ShowDialog() != true) { return; } string fileName = dlg.FileName; string outputFolderOrFileName = fileName; if (selectedNodes.Length > 1) { outputFolderOrFileName = Path.GetDirectoryName(outputFolderOrFileName); } Docking.DockWorkspace.Instance.RunWithCancellation(ct => Task <AvalonEditTextOutput> .Factory.StartNew(() => { AvalonEditTextOutput output = new AvalonEditTextOutput(); Stopwatch stopwatch = Stopwatch.StartNew(); stopwatch.Stop(); if (selectedNodes.Length == 1) { SaveEntry(output, selectedNodes[0].PackageEntry, outputFolderOrFileName); } else { foreach (var node in selectedNodes) { var fileName = Path.GetFileName(WholeProjectDecompiler.SanitizeFileName(node.PackageEntry.Name)); SaveEntry(output, node.PackageEntry, Path.Combine(outputFolderOrFileName, fileName)); } } output.WriteLine(Resources.GenerationCompleteInSeconds, stopwatch.Elapsed.TotalSeconds.ToString("F1")); output.WriteLine(); output.AddButton(null, Resources.OpenExplorer, delegate { Process.Start("explorer", "/select,\"" + fileName + "\""); }); output.WriteLine(); return(output); }, ct)).Then(output => Docking.DockWorkspace.Instance.ShowText(output)).HandleExceptions(); }
public override bool Save(ViewModels.TabPageModel tabPage) { SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = Path.GetFileName(WholeProjectDecompiler.SanitizeFileName(key)); if (dlg.ShowDialog() == true) { using var data = OpenStream(); using var fs = dlg.OpenFile(); data.CopyTo(fs); } return(true); }
public override bool Save(TabPageModel tabPage) { Stream s = Resource.TryOpenStream(); if (s == null) { return(false); } SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = Path.GetFileName(WholeProjectDecompiler.SanitizeFileName(Resource.Name)); dlg.Filter = Resources.ResourcesFileFilter; if (dlg.ShowDialog() == true) { s.Position = 0; switch (dlg.FilterIndex) { case 1: using (var fs = dlg.OpenFile()) { s.CopyTo(fs); } break; case 2: try { using (var fs = dlg.OpenFile()) using (var writer = new ResXResourceWriter(fs)) { foreach (var entry in new ResourcesFile(s)) { writer.AddResource(entry.Key, entry.Value); } } } catch (BadImageFormatException) { // ignore errors } catch (EndOfStreamException) { // ignore errors } break; } } return(true); }
public override bool Save(TabPageModel tabPage) { Stream s = Resource.TryOpenStream(); if (s == null) { return(false); } SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = Path.GetFileName(WholeProjectDecompiler.SanitizeFileName(Resource.Name)); if (dlg.ShowDialog() == true) { s.Position = 0; using (var fs = dlg.OpenFile()) { s.CopyTo(fs); } } return(true); }