Ejemplo n.º 1
0
		public App()
		{
			var cmdArgs = Environment.GetCommandLineArgs().Skip(1);
			App.CommandLineArguments = new CommandLineArguments(cmdArgs);
			if (App.CommandLineArguments.SingleInstance ?? true) {
				cmdArgs = cmdArgs.Select(FullyQualifyPath);
				string message = string.Join(Environment.NewLine, cmdArgs);
				if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate)) {
					Environment.Exit(0);
				}
			}
			InitializeComponent();
			
			var catalog = new AggregateCatalog();
			catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
			catalog.Catalogs.Add(new DirectoryCatalog(".", "*.Plugin.dll"));
			
			compositionContainer = new CompositionContainer(catalog);
			
			Languages.Initialize(compositionContainer);
			
			if (!Debugger.IsAttached) {
				AppDomain.CurrentDomain.UnhandledException += ShowErrorBox;
				Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
			}
			
			EventManager.RegisterClassHandler(typeof(Window),
			                                  Hyperlink.RequestNavigateEvent,
			                                  new RequestNavigateEventHandler(Window_RequestNavigate));
		}
Ejemplo n.º 2
0
        public App()
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            // Add Ctrl+Shift+Z as a redo command. Don't know why it isn't enabled by default.
            ApplicationCommands.Redo.InputGestures.Add(new KeyGesture(Key.Z, ModifierKeys.Control | ModifierKeys.Shift));

            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);
            App.CommandLineArguments = new CommandLineArguments(cmdArgs);
            if (App.CommandLineArguments.SingleInstance ?? true) {
                cmdArgs = cmdArgs.Select(FullyQualifyPath);
                string message = string.Join(Environment.NewLine, cmdArgs);
                if (SendToPreviousInstance("dnSpy:\r\n" + message, !App.CommandLineArguments.NoActivate)) {
                    Environment.Exit(0);
                }
            }
            InitializeComponent();

            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
            // Don't use DirectoryCatalog, that causes problems if the plugins are from the Internet zone
            // see http://stackoverflow.com/questions/8063841/mef-loading-plugins-from-a-network-shared-folder
            string appPath = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName);
            foreach (string plugin in Directory.GetFiles(appPath, "*.Plugin.dll")) {
                string shortName = Path.GetFileNameWithoutExtension(plugin);
                try {
                    var asm = Assembly.Load(shortName);
                    asm.GetTypes();
                    catalog.Catalogs.Add(new AssemblyCatalog(asm));
                } catch (Exception ex) {
                    // Cannot show MessageBox here, because WPF would crash with a XamlParseException
                    // Remember and show exceptions in text output, once MainWindow is properly initialized
                    StartupExceptions.Add(new ExceptionData { Exception = ex, PluginName = shortName });
                }
            }

            compositionContainer = new CompositionContainer(catalog);

            Languages.Initialize(compositionContainer);

            if (!System.Diagnostics.Debugger.IsAttached) {
                AppDomain.CurrentDomain.UnhandledException += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }
            TaskScheduler.UnobservedTaskException += DotNet40_UnobservedTaskException;

            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));

            FixEditorContextMenuStyle();

            try {
                DebuggerService.SetDebugger(compositionContainer.GetExport<IDebugger>());
            } catch {
                // unable to find a IDebugger
            }
        }
Ejemplo n.º 3
0
		public App()
		{
			var cmdArgs = Environment.GetCommandLineArgs().Skip(1);
			App.CommandLineArguments = new CommandLineArguments(cmdArgs);
			if (App.CommandLineArguments.SingleInstance ?? true) {
				cmdArgs = cmdArgs.Select(FullyQualifyPath);
				string message = string.Join(Environment.NewLine, cmdArgs);
				if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate)) {
					Environment.Exit(0);
				}
			}

            InitializeComponent();
			
			var catalog = new AggregateCatalog();
			catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
			// Don't use DirectoryCatalog, that causes problems if the plugins are from the Internet zone
			// see http://stackoverflow.com/questions/8063841/mef-loading-plugins-from-a-network-shared-folder
			string appPath = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName);
			foreach (string plugin in Directory.GetFiles(appPath, "*.Plugin.dll")) {
				string shortName = Path.GetFileNameWithoutExtension(plugin);
				try {
					catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load(shortName)));
				} catch (Exception ex) {
					MessageBox.Show(ex.ToString(), "Error loading plugin " + shortName);
				}
			}
			
			compositionContainer = new CompositionContainer(catalog);
			
			Languages.Initialize(compositionContainer);
			
			if (!System.Diagnostics.Debugger.IsAttached) {
				AppDomain.CurrentDomain.UnhandledException += ShowErrorBox;
				Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
			}
			
			EventManager.RegisterClassHandler(typeof(Window),
			                                  Hyperlink.RequestNavigateEvent,
			                                  new RequestNavigateEventHandler(Window_RequestNavigate));
			
			try {
				DebuggerService.SetDebugger(compositionContainer.GetExport<IDebugger>());
			} catch {
				// unable to find a IDebugger
			}
		}
Ejemplo n.º 4
0
		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.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();
			}
			if (!string.IsNullOrEmpty(args.SaveDirectory)) {
				foreach (var x in commandLineLoadedAssemblies) {
					x.ContinueWhenLoaded( (Task<ModuleDefinition> moduleTask) => {
						OnExportAssembly(moduleTask, args.SaveDirectory);
					}, TaskScheduler.FromCurrentSynchronizationContext());
				}
			}
			commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore
		}
Ejemplo n.º 5
0
		bool HandleCommandLineArguments(CommandLineArguments args)
		{
			foreach (string file in args.AssembliesToLoad) {
				commandLineLoadedAssemblies.Add(assemblyList.OpenAssembly(file));
			}
			if (args.Language != null)
				sessionSettings.FilterSettings.Language = Languages.GetLanguage(args.Language);
			return true;
		}
Ejemplo n.º 6
0
		unsafe IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
		{
			if (msg == NativeMethods.WM_COPYDATA) {
				CopyDataStruct* copyData = (CopyDataStruct*)lParam;
				string data = new string((char*)copyData->Buffer, 0, copyData->Size / sizeof(char));
				if (data.StartsWith("ILSpy:\r\n", StringComparison.Ordinal)) {
					data = data.Substring(8);
					List<string> lines = new List<string>();
					using (StringReader r = new StringReader(data)) {
						string line;
						while ((line = r.ReadLine()) != null)
							lines.Add(line);
					}
					var args = new CommandLineArguments(lines);
					if (HandleCommandLineArguments(args)) {
						if (!args.NoActivate && WindowState == WindowState.Minimized)
							WindowState = WindowState.Normal;
						HandleCommandLineArgumentsAfterShowList(args);
						handled = true;
						return (IntPtr)1;
					}
				}
			}
			return IntPtr.Zero;
		}
Ejemplo n.º 7
0
		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
		}
Ejemplo n.º 8
0
		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.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);
			}
			commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore
		}
Ejemplo n.º 9
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
 }
Ejemplo n.º 10
0
		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 (DnSpyFile asm in commandLineLoadedFiles) {
						AssemblyTreeNode asmNode = dnSpyFileListTreeNode.FindAssemblyNode(asm);
						if (asmNode != null) {
							NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
							if (nsNode != null) {
								found = true;
								SelectNode(nsNode);
								break;
							}
						}
					}
				}
				else {
					foreach (DnSpyFile asm in commandLineLoadedFiles) {
						ModuleDef def = asm.ModuleDef;
						if (def != null) {
							IMemberRef 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), TextTokenType.Text);
					SafeActiveTextView.ShowText(output);
				}
			}
			else if (commandLineLoadedFiles.Count == 1) {
				// NavigateTo == null and an assembly was given on the command-line:
				// Select the newly loaded assembly
				JumpToReference(commandLineLoadedFiles[0].ModuleDef);
			}
			if (args.Search != null) {
				SearchPane.Instance.SearchTerm = args.Search;
				SearchPane.Instance.Show();
			}
			if (!string.IsNullOrEmpty(args.SaveDirectory)) {
				foreach (var x in commandLineLoadedFiles)
					OnExportAssembly(x, args.SaveDirectory);
			}
			commandLineLoadedFiles.Clear(); // clear references once we don't need them anymore
		}
Ejemplo n.º 11
0
        public App()
        {
            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);

            App.CommandLineArguments = new CommandLineArguments(cmdArgs);
            if ((App.CommandLineArguments.SingleInstance ?? true) && !MiscSettingsPanel.CurrentMiscSettings.AllowMultipleInstances)
            {
                cmdArgs = cmdArgs.Select(FullyQualifyPath);
                string message = string.Join(Environment.NewLine, cmdArgs);
                if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate))
                {
                    Environment.Exit(0);
                }
            }
            InitializeComponent();

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }
            TaskScheduler.UnobservedTaskException += DotNet40_UnobservedTaskException;

            // Cannot show MessageBox here, because WPF would crash with a XamlParseException
            // Remember and show exceptions in text output, once MainWindow is properly initialized
            try {
                // Set up VS MEF. For now, only do MEF1 part discovery, since that was in use before.
                // To support both MEF1 and MEF2 parts, just change this to:
                // var discovery = PartDiscovery.Combine(new AttributedPartDiscoveryV1(Resolver.DefaultInstance),
                //                                       new AttributedPartDiscovery(Resolver.DefaultInstance));
                var discovery = new AttributedPartDiscoveryV1(Resolver.DefaultInstance);
                var catalog   = ComposableCatalog.Create(Resolver.DefaultInstance);
                var pluginDir = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName);
                if (pluginDir != null)
                {
                    foreach (var plugin in Directory.GetFiles(pluginDir, "*.Plugin.dll"))
                    {
                        var name = Path.GetFileNameWithoutExtension(plugin);
                        try {
                            var asm   = Assembly.Load(name);
                            var parts = discovery.CreatePartsAsync(asm).GetAwaiter().GetResult();
                            catalog = catalog.AddParts(parts);
                        } catch (Exception ex) {
                            StartupExceptions.Add(new ExceptionData {
                                Exception = ex, PluginName = name
                            });
                        }
                    }
                }
                // Add the built-in parts
                catalog = catalog.AddParts(discovery.CreatePartsAsync(Assembly.GetExecutingAssembly()).GetAwaiter().GetResult());
                // If/When the project switches to .NET Standard/Core, this will be needed to allow metadata interfaces (as opposed
                // to metadata classes). When running on .NET Framework, it's automatic.
                //   catalog.WithDesktopSupport();
                // If/When any part needs to import ICompositionService, this will be needed:
                //   catalog.WithCompositionService();
                var config = CompositionConfiguration.Create(catalog);
                exportProviderFactory = config.CreateExportProviderFactory();
                exportProvider        = exportProviderFactory.CreateExportProvider();
                // This throws exceptions for composition failures. Alternatively, the configuration's CompositionErrors property
                // could be used to log the errors directly. Used at the end so that it does not prevent the export provider setup.
                config.ThrowOnErrors();
            } catch (Exception ex) {
                StartupExceptions.Add(new ExceptionData {
                    Exception = ex
                });
            }

            Languages.Initialize(exportProvider);

            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));
            ILSpyTraceListener.Install();
        }
Ejemplo n.º 12
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
        }
Ejemplo n.º 13
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.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].GetModuleDefinitionOrNull());
     }
     if (args.Search != null)
     {
         SearchPane.Instance.SearchTerm = args.Search;
         SearchPane.Instance.Show();
     }
     commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
 }
Ejemplo n.º 14
0
        public App()
        {
            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);

            App.CommandLineArguments = new CommandLineArguments(cmdArgs);
            if (App.CommandLineArguments.SingleInstance ?? true)
            {
                cmdArgs = cmdArgs.Select(FullyQualifyPath);
                string message = string.Join(Environment.NewLine, cmdArgs);
                if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate))
                {
                    Environment.Exit(0);
                }
            }
            InitializeComponent();

            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
            // Don't use DirectoryCatalog, that causes problems if the plugins are from the Internet zone
            // see http://stackoverflow.com/questions/8063841/mef-loading-plugins-from-a-network-shared-folder
            string appPath = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName);

            foreach (string plugin in Directory.GetFiles(appPath, "*.Plugin.dll"))
            {
                string shortName = Path.GetFileNameWithoutExtension(plugin);
                try
                {
                    var asm = Assembly.Load(shortName);
                    asm.GetTypes();
                    catalog.Catalogs.Add(new AssemblyCatalog(asm));
                }
                catch (Exception ex)
                {
                    // Cannot show MessageBox here, because WPF would crash with a XamlParseException
                    // Remember and show exceptions in text output, once MainWindow is properly initialized
                    StartupExceptions.Add(new ExceptionData {
                        Exception = ex, PluginName = shortName
                    });
                }
            }

            compositionContainer = new CompositionContainer(catalog);

            Languages.Initialize(compositionContainer);

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }
            TaskScheduler.UnobservedTaskException += DotNet40_UnobservedTaskException;

            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));
            try
            {
                DebuggerService.SetDebugger(compositionContainer.GetExport <IDebugger>());
            }
            catch
            {
                // unable to find a IDebugger
            }
        }
Ejemplo n.º 15
0
		void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args)
		{
			if (args.NavigateTo != null) {
				bool found = false;
				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
		}