Пример #1
0
        static void Execute(Lazy <IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
            {
                return;
            }

            var asmNode = (IDnSpyFileNode)nodes[0];

            if (asmNode is IModuleFileNode)
            {
                asmNode = (IAssemblyFileNode)asmNode.TreeNode.Parent.Data;
            }

            var win  = new NetModuleOptionsDlg();
            var data = new NetModuleOptionsVM(asmNode.DnSpyFile.ModuleDef);

            win.DataContext = data;
            win.Owner       = appWindow.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            var options    = data.CreateNetModuleOptions();
            var newModule  = ModuleUtils.CreateNetModule(options.Name, options.Mvid, options.ClrVersion);
            var newFile    = DnSpyDotNetFile.CreateModule(DnSpyFileInfo.CreateFile(string.Empty), newModule, appWindow.FileTreeView.FileManager.Settings.LoadPDBFiles);
            var newModNode = asmNode.Context.FileTreeView.CreateModule(newFile);
            var cmd        = new AddNewNetModuleToAssemblyCommand(undoCommandManager.Value, (IDnSpyFileNode)nodes[0], newModNode);

            undoCommandManager.Value.Add(cmd);
            appWindow.FileTabManager.FollowReference(cmd.modNode);
        }
Пример #2
0
        static void Execute(Lazy <IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
            {
                return;
            }

            var asmNode = (DsDocumentNode)nodes[0];

            if (asmNode is ModuleDocumentNode)
            {
                asmNode = (AssemblyDocumentNode)asmNode.TreeNode.Parent.Data;
            }

            var win  = new NetModuleOptionsDlg();
            var data = new NetModuleOptionsVM(asmNode.Document.ModuleDef);

            win.DataContext = data;
            win.Owner       = appService.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            var options    = data.CreateNetModuleOptions();
            var newModule  = ModuleUtils.CreateNetModule(options.Name, options.Mvid, options.ClrVersion);
            var newFile    = DsDotNetDocument.CreateModule(DsDocumentInfo.CreateDocument(string.Empty), newModule, true);
            var newModNode = asmNode.Context.DocumentTreeView.CreateModule(newFile);
            var cmd        = new AddNewNetModuleToAssemblyCommand(undoCommandService.Value, (DsDocumentNode)nodes[0], newModNode);

            undoCommandService.Value.Add(cmd);
            appService.DocumentTabService.FollowReference(cmd.modNode);
        }
Пример #3
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
            {
                return;
            }

            var asmNode = (AssemblyTreeNode)nodes[0];

            if (asmNode.Parent is AssemblyTreeNode)
            {
                asmNode = (AssemblyTreeNode)asmNode.Parent;
            }

            var win  = new NetModuleOptionsDlg();
            var data = new NetModuleOptionsVM(asmNode.LoadedAssembly.ModuleDefinition);

            win.DataContext = data;
            win.Owner       = MainWindow.Instance;
            if (win.ShowDialog() != true)
            {
                return;
            }

            var cmd = new AddNewNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], data.CreateNetModuleOptions());

            UndoCommandManager.Instance.Add(cmd);
            MainWindow.Instance.JumpToReference(cmd.modNode);
        }
Пример #4
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;
            }

            UndoCommandManager.Instance.Add(new AddExistingNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], asm));
        }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
0
 protected override bool CanExecuteInternal(ILSpyTreeNode[] nodes)
 {
     return(AddNetModuleToAssemblyCommand.CanExecute(nodes));
 }