Esempio n. 1
0
        static void Execute(Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
            {
                return;
            }

            var dialog = new System.Windows.Forms.OpenFileDialog()
            {
                Filter           = PickFilenameConstants.NetModuleFilter,
                RestoreDirectory = true,
            };

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (string.IsNullOrEmpty(dialog.FileName))
            {
                return;
            }

            var fm   = appService.DocumentTreeView.DocumentService;
            var file = fm.CreateDocument(DsDocumentInfo.CreateDocument(dialog.FileName), dialog.FileName, true);

            if (file.ModuleDef == null || file.AssemblyDef != null || !(file is IDsDotNetDocument))
            {
                MsgBox.Instance.Show(string.Format(dnSpy_AsmEditor_Resources.Error_NotNetModule, file.Filename), MsgBoxButton.OK);
                var id = file as IDisposable;
                if (id != null)
                {
                    id.Dispose();
                }
                return;
            }

            var node       = (DsDocumentNode)nodes[0];
            var newModNode = node.Context.DocumentTreeView.CreateModule((IDsDotNetDocument)file);
            var cmd        = new AddExistingNetModuleToAssemblyCommand(undoCommandService.Value, node, newModNode);

            undoCommandService.Value.Add(cmd);
            appService.DocumentTabService.FollowReference(cmd.modNode);
        }
Esempio n. 2
0
        static void Execute(Lazy <IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
            {
                return;
            }

            var dialog = new System.Windows.Forms.OpenFileDialog()
            {
                Filter           = PickFilenameConstants.NetModuleFilter,
                RestoreDirectory = true,
            };

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (string.IsNullOrEmpty(dialog.FileName))
            {
                return;
            }

            var fm   = appWindow.FileTreeView.FileManager;
            var file = DnSpyFile.CreateDnSpyFileFromFile(DnSpyFileInfo.CreateFile(dialog.FileName), dialog.FileName, fm.Settings.UseMemoryMappedIO, fm.Settings.LoadPDBFiles, fm.AssemblyResolver, true);

            if (file.ModuleDef == null || file.AssemblyDef != null || !(file is IDnSpyDotNetFile))
            {
                Shared.App.MsgBox.Instance.Show(string.Format(dnSpy_AsmEditor_Resources.Error_NotNetModule, file.Filename), MsgBoxButton.OK);
                var id = file as IDisposable;
                if (id != null)
                {
                    id.Dispose();
                }
                return;
            }

            var node       = (IDnSpyFileNode)nodes[0];
            var newModNode = node.Context.FileTreeView.CreateModule((IDnSpyDotNetFile)file);
            var cmd        = new AddExistingNetModuleToAssemblyCommand(undoCommandManager.Value, node, newModNode);

            undoCommandManager.Value.Add(cmd);
            appWindow.FileTabManager.FollowReference(cmd.modNode);
        }
Esempio n. 3
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
            {
                return;
            }

            var dialog = new System.Windows.Forms.OpenFileDialog()
            {
                Filter           = ".NET NetModules (*.netmodule)|*.netmodule|All files (*.*)|*.*",
                RestoreDirectory = true,
            };

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (string.IsNullOrEmpty(dialog.FileName))
            {
                return;
            }

            var asm = new LoadedAssembly(MainWindow.Instance.CurrentAssemblyList, dialog.FileName);

            if (asm.ModuleDefinition == null || asm.AssemblyDefinition != null)
            {
                MainWindow.Instance.ShowMessageBox(string.Format("{0} is not a NetModule", asm.FileName), System.Windows.MessageBoxButton.OK);
                asm.TheLoadedFile.Dispose();
                return;
            }

            var cmd = new AddExistingNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], asm);

            UndoCommandManager.Instance.Add(cmd);
            MainWindow.Instance.JumpToReference(cmd.modNode);
        }
Esempio n. 4
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
            {
                return;
            }

            var dialog = new System.Windows.Forms.OpenFileDialog()
            {
                Filter           = PickFilenameConstants.NetModuleFilter,
                RestoreDirectory = true,
            };

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (string.IsNullOrEmpty(dialog.FileName))
            {
                return;
            }

            var asm = MainWindow.Instance.DnSpyFileList.CreateDnSpyFile(dialog.FileName);

            if (asm.ModuleDef == null || asm.AssemblyDef != null)
            {
                MainWindow.Instance.ShowMessageBox(string.Format("{0} is not a NetModule", asm.Filename), System.Windows.MessageBoxButton.OK);
                asm.Dispose();
                return;
            }

            var cmd = new AddExistingNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], asm);

            UndoCommandManager.Instance.Add(cmd);
            MainWindow.Instance.JumpToReference(cmd.modNode);
        }
Esempio n. 5
0
 public override void Execute(AsmEditorContext context) => AddExistingNetModuleToAssemblyCommand.Execute(undoCommandService, appService, context.Nodes);
Esempio n. 6
0
 public override bool IsVisible(AsmEditorContext context) => AddExistingNetModuleToAssemblyCommand.CanExecute(context.Nodes);
Esempio n. 7
0
 public override void Execute(AsmEditorContext context)
 {
     AddExistingNetModuleToAssemblyCommand.Execute(undoCommandManager, appWindow, context.Nodes);
 }
Esempio n. 8
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
                return;

            var dialog = new System.Windows.Forms.OpenFileDialog() {
                Filter = ".NET NetModules (*.netmodule)|*.netmodule|All files (*.*)|*.*",
                RestoreDirectory = true,
            };
            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            if (string.IsNullOrEmpty(dialog.FileName))
                return;

            var asm = new LoadedAssembly(MainWindow.Instance.CurrentAssemblyList, dialog.FileName);
            if (asm.ModuleDefinition == null || asm.AssemblyDefinition != null) {
                MainWindow.Instance.ShowMessageBox(string.Format("{0} is not a NetModule", asm.FileName), System.Windows.MessageBoxButton.OK);
                asm.TheLoadedFile.Dispose();
                return;
            }

            var cmd = new AddExistingNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], asm);
            UndoCommandManager.Instance.Add(cmd);
            MainWindow.Instance.JumpToReference(cmd.modNode);
        }
Esempio n. 9
0
 protected override void ExecuteInternal(ILSpyTreeNode[] nodes)
 {
     AddExistingNetModuleToAssemblyCommand.Execute(nodes);
 }
Esempio n. 10
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes) {
			if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
				return;

			var dialog = new System.Windows.Forms.OpenFileDialog() {
				Filter = PickFilenameConstants.NetModuleFilter,
				RestoreDirectory = true,
			};
			if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
				return;
			if (string.IsNullOrEmpty(dialog.FileName))
				return;

			var fm = appWindow.FileTreeView.FileManager;
			var file = DnSpyFile.CreateDnSpyFileFromFile(DnSpyFileInfo.CreateFile(dialog.FileName), dialog.FileName, fm.Settings.UseMemoryMappedIO, fm.Settings.LoadPDBFiles, fm.AssemblyResolver, true);
			if (file.ModuleDef == null || file.AssemblyDef != null || !(file is IDnSpyDotNetFile)) {
				Shared.App.MsgBox.Instance.Show(string.Format(dnSpy_AsmEditor_Resources.Error_NotNetModule, file.Filename), MsgBoxButton.OK);
				var id = file as IDisposable;
				if (id != null)
					id.Dispose();
				return;
			}

			var node = (IDnSpyFileNode)nodes[0];
			var newModNode = node.Context.FileTreeView.CreateModule((IDnSpyDotNetFile)file);
			var cmd = new AddExistingNetModuleToAssemblyCommand(undoCommandManager.Value, node, newModNode);
			undoCommandManager.Value.Add(cmd);
			appWindow.FileTabManager.FollowReference(cmd.modNode);
		}
Esempio n. 11
0
		static void Execute(ILSpyTreeNode[] nodes) {
			if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
				return;

			var dialog = new System.Windows.Forms.OpenFileDialog() {
				Filter = PickFilenameConstants.NetModuleFilter,
				RestoreDirectory = true,
			};
			if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
				return;
			if (string.IsNullOrEmpty(dialog.FileName))
				return;

			var asm = MainWindow.Instance.DnSpyFileList.CreateDnSpyFile(dialog.FileName);
			if (asm.ModuleDef == null || asm.AssemblyDef != null) {
				MainWindow.Instance.ShowMessageBox(string.Format("{0} is not a NetModule", asm.Filename), System.Windows.MessageBoxButton.OK);
				asm.Dispose();
				return;
			}

			var cmd = new AddExistingNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], asm);
			UndoCommandManager.Instance.Add(cmd);
			MainWindow.Instance.JumpToReference(cmd.modNode);
		}
Esempio n. 12
0
		static void Execute(Lazy<IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes) {
			if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
				return;

			var dialog = new System.Windows.Forms.OpenFileDialog() {
				Filter = PickFilenameConstants.NetModuleFilter,
				RestoreDirectory = true,
			};
			if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
				return;
			if (string.IsNullOrEmpty(dialog.FileName))
				return;

			var fm = appService.DocumentTreeView.DocumentService;
			var file = fm.CreateDocument(DsDocumentInfo.CreateDocument(dialog.FileName), dialog.FileName, true);
			if (file.ModuleDef == null || file.AssemblyDef != null || !(file is IDsDotNetDocument)) {
				MsgBox.Instance.Show(string.Format(dnSpy_AsmEditor_Resources.Error_NotNetModule, file.Filename), MsgBoxButton.OK);
				var id = file as IDisposable;
				if (id != null)
					id.Dispose();
				return;
			}

			var node = (DsDocumentNode)nodes[0];
			var newModNode = node.Context.DocumentTreeView.CreateModule((IDsDotNetDocument)file);
			var cmd = new AddExistingNetModuleToAssemblyCommand(undoCommandService.Value, node, newModNode);
			undoCommandService.Value.Add(cmd);
			appService.DocumentTabService.FollowReference(cmd.modNode);
		}