public override void Execute(object parameter) { MainWindow.Instance.TextView.RunWithCancellation(ct => Task <AvaloniaEditTextOutput> .Factory.StartNew(() => { AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); Parallel.ForEach(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = ct }, delegate(LoadedAssembly asm) { if (!asm.HasLoadError) { Stopwatch w = Stopwatch.StartNew(); Exception exception = null; using (var writer = new System.IO.StreamWriter("c:\\temp\\decompiled\\" + asm.ShortName + ".cs")) { try { //new CSharpLanguage().DecompileAssembly(asm, new Decompiler.PlainTextOutput(writer), new DecompilationOptions() { FullDecompilation = true, CancellationToken = ct }); } catch (Exception ex) { writer.WriteLine(ex.ToString()); exception = ex; } } lock (output) { output.Write(asm.ShortName + " - " + w.Elapsed); if (exception != null) { output.Write(" - "); output.Write(exception.GetType().Name); } output.WriteLine(); } } }); return(output); }, ct)).Then(output => MainWindow.Instance.TextView.ShowText(output)).HandleExceptions(); }
public override bool View(DecompilerTextView textView) { AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); IHighlightingDefinition highlighting = null; textView.RunWithCancellation( token => Task.Factory.StartNew( () => { try { // cache read XAML because stream will be closed after first read if (xml == null) { using (var reader = new StreamReader(Data)) { xml = reader.ReadToEnd(); } } output.Write(xml); highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml"); } catch (Exception ex) { output.Write(ex.ToString()); } return(output); }, token) ).Then(t => textView.ShowNode(t, this, highlighting)).HandleExceptions(); return(true); }
//protected override void OnStartup(StartupEventArgs e) //{ // var output = new StringBuilder(); // if (ILSpy.MainWindow.FormatExceptions(StartupExceptions.ToArray(), output)) // { // MessageBox.Show(output.ToString(), "Sorry we crashed!"); // Environment.Exit(1); // } // base.OnStartup(e); //} #endregion void Window_RequestNavigate(OpenUriRoutedEventArgs e) { if (e.Uri.Scheme == "resource") { AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); using (Stream s = typeof(App).Assembly.GetManifestResourceStream(typeof(App), e.Uri.AbsolutePath)) { using (StreamReader r = new StreamReader(s)) { string line; while ((line = r.ReadLine()) != null) { output.Write(line); output.WriteLine(); } } } ILSpy.MainWindow.Instance.TextView.ShowText(output); } else { ILSpy.MainWindow.OpenLink(e.Uri.ToString()); } e.Handled = true; }
public override bool View(DecompilerTextView textView) { EmbeddedResource er = r as EmbeddedResource; if (er != null) { Stream s = er.GetResourceStream(); if (s != null && s.Length < DecompilerTextView.DefaultOutputLengthLimit) { s.Position = 0; FileType type = GuessFileType.DetectFileType(s); if (type != FileType.Binary) { s.Position = 0; AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); output.Write(new StreamReader(s, Encoding.UTF8).ReadToEnd()); string ext; if (type == FileType.Xml) { ext = ".xml"; } else { ext = Path.GetExtension(DecompilerTextView.CleanUpName(er.Name)); } textView.ShowNode(output, this, HighlightingManager.Instance.GetDefinitionByExtension(ext)); return(true); } } } return(false); }
/// <summary> /// Handle exceptions by displaying the error message in the text view. /// </summary> public static void HandleExceptions(this Task task) { task.Catch <Exception>(exception => Dispatcher.UIThread.InvokeAsync(new Action(delegate { AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); output.Write(exception.ToString()); MainWindow.Instance.TextView.ShowText(output); }))).IgnoreExceptions(); }
public override void Execute(object parameter) { const int numRuns = 100; var language = MainWindow.Instance.CurrentLanguage; var nodes = MainWindow.Instance.SelectedNodes.ToArray(); var options = new DecompilationOptions(); MainWindow.Instance.TextView.RunWithCancellation(ct => Task <AvaloniaEditTextOutput> .Factory.StartNew(() => { options.CancellationToken = ct; Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < numRuns; ++i) { foreach (var node in nodes) { node.Decompile(language, new PlainTextOutput(), options); } } w.Stop(); AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); double msPerRun = w.Elapsed.TotalMilliseconds / numRuns; output.Write($"Average time: {msPerRun.ToString("f1")}ms\n"); return(output); }, ct)).Then(output => MainWindow.Instance.TextView.ShowText(output)).HandleExceptions(); }
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args) { if (nugetPackagesToLoad.Count > 0) { LoadAssemblies(nugetPackagesToLoad, commandLineLoadedAssemblies, focusNode: false); nugetPackagesToLoad.Clear(); } if (args.NavigateTo != null) { bool found = false; if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal)) { string namespaceName = args.NavigateTo.Substring(2); foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; SelectNode(nsNode); break; } } } } else { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { ModuleDefinition def = asm.GetModuleDefinitionOrNull(); if (def != null) { MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo); if (mr != null) { found = true; // Defer JumpToReference call to allow an assembly that was loaded while // resolving a type-forwarder in FindMemberByKey to appear in the assembly list. Dispatcher.UIThread.InvokeAsync(new Action(() => JumpToReference(mr)), DispatcherPriority.Loaded); break; } } } } if (!found) { AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo)); decompilerTextView.ShowText(output); } } else if (commandLineLoadedAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionOrNull()); } if (args.Search != null) { SearchPane.Instance.SearchTerm = args.Search; SearchPane.Instance.Show(); } commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore }