コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: zhoujiezeus/ILSpy
 void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
 {
     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;
                         JumpToReference(mr);
                         break;
                     }
                 }
             }
         }
         if (!found)
         {
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             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
 }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: shalang/ILSpy
 void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
 {
     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)
             {
                 AssemblyDefinition def = asm.AssemblyDefinition;
                 if (def != null)
                 {
                     MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def.MainModule, args.NavigateTo);
                     if (mr != null)
                     {
                         found = true;
                         JumpToReference(mr);
                         break;
                     }
                 }
             }
         }
         if (!found)
         {
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             output.Write("Cannot find " + args.NavigateTo);
             decompilerTextView.ShowText(output);
         }
     }
     commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
 }
コード例 #3
0
        public NamespaceTreeNodeCreator(string ns, AssemblyTreeNode asmNode)
        {
            Debug.Assert(asmNode.IsModule);
            if (!asmNode.IsModule)
            {
                throw new InvalidOperationException();
            }

            this.asmNode = asmNode;
            this.nsNode  = asmNode.FindNamespaceNode(ns);
            if (this.nsNode == null)
            {
                this.nsNode        = new NamespaceTreeNode(ns);
                this.nsNodeCreated = true;
            }
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: zguorong/ILSpy
        async void NavigateOnLaunch(string navigateTo, string[] activeTreeViewPath, ILSpySettings spySettings, List <LoadedAssembly> relevantAssemblies)
        {
            var initialSelection = treeView.SelectedItem;

            if (navigateTo != null)
            {
                bool found = false;
                if (navigateTo.StartsWith("N:", StringComparison.Ordinal))
                {
                    string namespaceName = navigateTo.Substring(2);
                    foreach (LoadedAssembly asm in relevantAssemblies)
                    {
                        AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm);
                        if (asmNode != null)
                        {
                            // FindNamespaceNode() blocks the UI if the assembly is not yet loaded,
                            // so use an async wait instead.
                            await asm.GetPEFileAsync().Catch <Exception>(ex => { });

                            NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
                            if (nsNode != null)
                            {
                                found = true;
                                if (treeView.SelectedItem == initialSelection)
                                {
                                    SelectNode(nsNode);
                                }
                                break;
                            }
                        }
                    }
                }
                else if (navigateTo == "none")
                {
                    // Don't navigate anywhere; start empty.
                    // Used by ILSpy VS addin, it'll send us the real location to navigate to via IPC.
                    found = true;
                }
                else
                {
                    IEntity mr = await Task.Run(() => FindEntityInRelevantAssemblies(navigateTo, relevantAssemblies));

                    if (mr != null && mr.ParentModule.PEFile != null)
                    {
                        found = true;
                        if (treeView.SelectedItem == initialSelection)
                        {
                            JumpToReference(mr);
                        }
                    }
                }
                if (!found && treeView.SelectedItem == initialSelection)
                {
                    AvalonEditTextOutput output = new AvalonEditTextOutput();
                    output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", navigateTo));
                    decompilerTextView.ShowText(output);
                }
            }
            else if (relevantAssemblies.Count == 1)
            {
                // NavigateTo == null and an assembly was given on the command-line:
                // Select the newly loaded assembly
                AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(relevantAssemblies[0]);
                if (asmNode != null && treeView.SelectedItem == initialSelection)
                {
                    SelectNode(asmNode);
                }
            }
            else if (spySettings != null)
            {
                SharpTreeNode node = null;
                if (activeTreeViewPath?.Length > 0)
                {
                    foreach (var asm in assemblyList.GetAssemblies())
                    {
                        if (asm.FileName == activeTreeViewPath[0])
                        {
                            // FindNodeByPath() blocks the UI if the assembly is not yet loaded,
                            // so use an async wait instead.
                            await asm.GetPEFileAsync().Catch <Exception>(ex => { });
                        }
                    }
                    node = FindNodeByPath(activeTreeViewPath, true);
                }
                if (treeView.SelectedItem == initialSelection)
                {
                    if (node != null)
                    {
                        SelectNode(node);

                        // only if not showing the about page, perform the update check:
                        await ShowMessageIfUpdatesAvailableAsync(spySettings);
                    }
                    else
                    {
                        AboutPage.Display(decompilerTextView);
                    }
                }
            }
        }
コード例 #5
0
 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
 }
コード例 #6
0
 void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
 {
     // if a SaveDirectory is given, do not start a second concurrent decompilation
     // by executing JumpoToReference (leads to https://github.com/icsharpcode/ILSpy/issues/710)
     if (!string.IsNullOrEmpty(args.SaveDirectory))
     {
         foreach (var x in commandLineLoadedAssemblies)
         {
             x.ContinueWhenLoaded((Task <ModuleDefinition> moduleTask) => {
                 OnExportAssembly(moduleTask, args.SaveDirectory);
             }, TaskScheduler.FromCurrentSynchronizationContext());
         }
     }
     else 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.ModuleDefinition;
                 if (def != null)
                 {
                     MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo);
                     if (mr != null)
                     {
                         found = true;
                         JumpToReference(mr);
                         break;
                     }
                 }
             }
         }
         if (!found)
         {
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             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].ModuleDefinition);
     }
     if (args.Search != null)
     {
         SearchPane.Instance.SearchTerm = args.Search;
         SearchPane.Instance.Show();
     }
     commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
 }
コード例 #7
0
        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
                {
                    ITypeReference   typeRef   = null;
                    IMemberReference memberRef = null;
                    if (args.NavigateTo.StartsWith("T:", StringComparison.Ordinal))
                    {
                        typeRef = IdStringProvider.ParseTypeName(args.NavigateTo);
                    }
                    else
                    {
                        memberRef = IdStringProvider.ParseMemberIdString(args.NavigateTo);
                        typeRef   = memberRef.DeclaringTypeReference;
                    }
                    foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
                    {
                        var module = asm.GetPEFileOrNull();
                        if (CanResolveTypeInPEFile(module, typeRef, out var typeHandle))
                        {
                            IEntity      mr          = null;
                            ICompilation compilation = typeHandle.Kind == HandleKind.ExportedType
                                                                ? new DecompilerTypeSystem(module, module.GetAssemblyResolver())
                                                                : new SimpleCompilation(module, MinimalCorlib.Instance);
                            mr = memberRef == null
                                                                ? typeRef.Resolve(new SimpleTypeResolveContext(compilation)) as ITypeDefinition
                                                                : (IEntity)memberRef.Resolve(new SimpleTypeResolveContext(compilation));

                            if (mr != null && mr.ParentModule.PEFile != 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.BeginInvoke(new Action(() => JumpToReference(mr)), DispatcherPriority.Loaded);
                                break;
                            }
                        }
                    }
                }
                if (!found)
                {
                    AvalonEditTextOutput output = new AvalonEditTextOutput();
                    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].GetPEFileOrNull());
            }
            if (args.Search != null)
            {
                SearchPane.Instance.SearchTerm = args.Search;
                SearchPane.Instance.Show();
            }
            commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
        }