public bool Save(IEnumerable <object> docs) { var objsAry = Distinct(docs).ToArray(); if (objsAry.Length == 0) { return(true); } if (objsAry.Length == 1) { SaveOptionsVM options; if (objsAry[0] is IDsDocument document) { var optsData = new SaveModuleOptionsVM(document); var optsWin = new SaveModuleOptionsDlg(); optsWin.Owner = appWindow.MainWindow; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) { return(false); } options = optsData; } else { var buffer = objsAry[0] as HexBuffer; Debug.Assert(!(buffer is null)); var optsData = new SaveHexOptionsVM(buffer); var optsWin = new SaveHexOptionsDlg(); optsWin.Owner = appWindow.MainWindow; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) { return(false); } options = optsData; } var data = new SaveMultiModuleVM(mmapDisabler.Value, Dispatcher.CurrentDispatcher, options); var win = new SaveSingleModuleDlg(); win.Owner = appWindow.MainWindow; win.DataContext = data; data.Save(); win.ShowDialog(); return(MarkAsSaved(data, objsAry)); } else { var data = new SaveMultiModuleVM(mmapDisabler.Value, Dispatcher.CurrentDispatcher, objsAry); var win = new SaveMultiModuleDlg(); win.Owner = appWindow.MainWindow; win.DataContext = data; win.ShowDialog(); return(MarkAsSaved(data, objsAry)); } }
/// <summary> /// Saves all asms/hex docs and returns true if all of them were saved to disk /// </summary> /// <param name="objs">All objects to save</param> /// <returns></returns> public static bool SaveAssemblies(IEnumerable <IUndoObject> objs) { var objsAry = objs.ToArray(); if (objsAry.Length == 0) { return(true); } if (objsAry.Length == 1) { SaveOptionsVM options; var asm = objsAry[0] as LoadedAssembly; if (asm != null) { var optsData = new SaveModuleOptionsVM(asm); var optsWin = new SaveModuleOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) { return(false); } options = optsData; } else { var doc = (AsmEdHexDocument)objsAry[0]; var optsData = new SaveHexOptionsVM(doc); var optsWin = new SaveHexOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) { return(false); } options = optsData; } var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, options); var win = new SaveSingleModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; data.Save(); win.ShowDialog(); return(MarkAsSaved(data, objsAry)); } else { var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, objsAry); var win = new SaveMultiModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; win.ShowDialog(); return(MarkAsSaved(data, objsAry)); } }
bool MarkAsSaved(SaveMultiModuleVM vm, object[] docs) { bool allSaved = true; foreach (var doc in docs) { if (!vm.WasSaved(doc)) { allSaved = false; } else { undoCommandService.Value.MarkAsSaved(undoCommandService.Value.GetUndoObject(doc) !); if (doc is IDsDocument document && string.IsNullOrEmpty(document.Filename)) { var filename = vm.GetSavedFileName(doc); if (!string.IsNullOrWhiteSpace(filename) && !(document.ModuleDef is null)) { document.ModuleDef.Location = filename; document.Filename = filename; var modNode = documentTabService.DocumentTreeView.FindNode(document.ModuleDef) as ModuleDocumentNode; Debug.Assert(!(modNode is null)); if (!(modNode is null)) { modNode.TreeNode.RefreshUI(); documentTabService.RefreshModifiedDocument(modNode.Document); } } } } } return(allSaved); }
bool MarkAsSaved(SaveMultiModuleVM vm, object[] docs) { bool allSaved = true; foreach (var doc in docs) { if (!vm.WasSaved(doc)) { allSaved = false; } else { undoCommandManager.Value.MarkAsSaved(undoCommandManager.Value.GetUndoObject(doc)); var file = doc as IDnSpyFile; if (file != null && string.IsNullOrEmpty(file.Filename)) { var filename = vm.GetSavedFileName(doc); if (!string.IsNullOrWhiteSpace(filename) && file.ModuleDef != null) { file.ModuleDef.Location = filename; file.Filename = filename; var modNode = fileTabManager.FileTreeView.FindNode(file.ModuleDef) as IModuleFileNode; Debug.Assert(modNode != null); if (modNode != null) { modNode.TreeNode.RefreshUI(); fileTabManager.RefreshModifiedFile(modNode.DnSpyFile); } } } } } return(allSaved); }
/// <summary> /// Saves all asms/hex docs and returns true if all of them were saved to disk /// </summary> /// <param name="objs">All objects to save</param> /// <returns></returns> public static bool SaveAssemblies(IEnumerable<IUndoObject> objs) { var objsAry = objs.ToArray(); if (objsAry.Length == 0) return true; if (objsAry.Length == 1) { SaveOptionsVM options; var asm = objsAry[0] as LoadedAssembly; if (asm != null) { var optsData = new SaveModuleOptionsVM(asm); var optsWin = new SaveModuleOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) return false; options = optsData; } else { var doc = (AsmEdHexDocument)objsAry[0]; var optsData = new SaveHexOptionsVM(doc); var optsWin = new SaveHexOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) return false; options = optsData; } var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, options); var win = new SaveSingleModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; data.Save(); win.ShowDialog(); return MarkAsSaved(data, objsAry); } else { var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, objsAry); var win = new SaveMultiModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; win.ShowDialog(); return MarkAsSaved(data, objsAry); } }
static bool MarkAsSaved(SaveMultiModuleVM vm, IUndoObject[] objs) { bool setNewFileName = false; bool allSaved = true; foreach (var obj in objs) { if (!vm.WasSaved(obj)) { allSaved = false; } else { UndoCommandManager.Instance.MarkAsSaved(obj); var file = UndoCommandManager.Instance.TryGetDnSpyFile(obj); if (file != null && string.IsNullOrEmpty(file.Filename)) { var filename = vm.GetSavedFileName(obj); if (!string.IsNullOrWhiteSpace(filename) && file.ModuleDef != null) { file.ModuleDef.Location = filename; file.Filename = filename; setNewFileName = true; var asmNode = MainWindow.Instance.FindTreeNode(file.ModuleDef) as AssemblyTreeNode; Debug.Assert(asmNode != null); if (asmNode != null) { asmNode.OnFileNameChanged(); Utils.NotifyModifiedAssembly(file); } } } } } if (setNewFileName) { MainWindow.Instance.DnSpyFileListManager.RefreshSave(MainWindow.Instance.DnSpyFileList); } return(allSaved); }
static bool MarkAsSaved(SaveMultiModuleVM vm, IUndoObject[] objs) { bool setNewFileName = false; bool allSaved = true; foreach (var obj in objs) { if (!vm.WasSaved(obj)) { allSaved = false; } else { UndoCommandManager.Instance.MarkAsSaved(obj); var asm = obj as LoadedAssembly; if (asm != null && string.IsNullOrEmpty(asm.FileName)) { var filename = vm.GetSavedFileName(asm); if (!string.IsNullOrWhiteSpace(filename) && asm.ModuleDefinition != null) { asm.ModuleDefinition.Location = filename; asm.FileName = filename; setNewFileName = true; var asmNode = MainWindow.Instance.FindTreeNode(asm.ModuleDefinition) as AssemblyTreeNode; Debug.Assert(asmNode != null); if (asmNode != null) { asmNode.OnFileNameChanged(); Utils.NotifyModifiedAssembly(asm); } } } } } if (setNewFileName) { MainWindow.Instance.CurrentAssemblyList.RefreshSave(); } return(allSaved); }
static bool MarkAsSaved(SaveMultiModuleVM vm, IUndoObject[] objs) { bool setNewFileName = false; bool allSaved = true; foreach (var obj in objs) { if (!vm.WasSaved(obj)) allSaved = false; else { UndoCommandManager.Instance.MarkAsSaved(obj); var asm = obj as LoadedAssembly; if (asm != null && string.IsNullOrEmpty(asm.FileName)) { var filename = vm.GetSavedFileName(asm); if (!string.IsNullOrWhiteSpace(filename)) { asm.ModuleDefinition.Location = filename; asm.FileName = filename; setNewFileName = true; var asmNode = MainWindow.Instance.FindTreeNode(asm.ModuleDefinition) as AssemblyTreeNode; Debug.Assert(asmNode != null); if (asmNode != null) { asmNode.OnFileNameChanged(); Utils.NotifyModifiedAssembly(asm); } } } } } if (setNewFileName) MainWindow.Instance.CurrentAssemblyList.RefreshSave(); return allSaved; }
public bool Save(IEnumerable<object> docs) { var objsAry = Distinct(docs).ToArray(); if (objsAry.Length == 0) return true; if (objsAry.Length == 1) { SaveOptionsVM options; var document = objsAry[0] as IDsDocument; if (document != null) { var optsData = new SaveModuleOptionsVM(document); var optsWin = new SaveModuleOptionsDlg(); optsWin.Owner = appWindow.MainWindow; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) return false; options = optsData; } else { var buffer = objsAry[0] as HexBuffer; Debug.Assert(buffer != null); var optsData = new SaveHexOptionsVM(buffer); var optsWin = new SaveHexOptionsDlg(); optsWin.Owner = appWindow.MainWindow; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) return false; options = optsData; } var data = new SaveMultiModuleVM(mmapDisabler.Value, Dispatcher.CurrentDispatcher, options); var win = new SaveSingleModuleDlg(); win.Owner = appWindow.MainWindow; win.DataContext = data; data.Save(); win.ShowDialog(); return MarkAsSaved(data, objsAry); } else { var data = new SaveMultiModuleVM(mmapDisabler.Value, Dispatcher.CurrentDispatcher, objsAry); var win = new SaveMultiModuleDlg(); win.Owner = appWindow.MainWindow; win.DataContext = data; win.ShowDialog(); return MarkAsSaved(data, objsAry); } }
bool MarkAsSaved(SaveMultiModuleVM vm, object[] docs) { bool allSaved = true; foreach (var doc in docs) { if (!vm.WasSaved(doc)) allSaved = false; else { undoCommandService.Value.MarkAsSaved(undoCommandService.Value.GetUndoObject(doc)); var document = doc as IDsDocument; if (document != null && string.IsNullOrEmpty(document.Filename)) { var filename = vm.GetSavedFileName(doc); if (!string.IsNullOrWhiteSpace(filename) && document.ModuleDef != null) { document.ModuleDef.Location = filename; document.Filename = filename; var modNode = documentTabService.DocumentTreeView.FindNode(document.ModuleDef) as ModuleDocumentNode; Debug.Assert(modNode != null); if (modNode != null) { modNode.TreeNode.RefreshUI(); documentTabService.RefreshModifiedDocument(modNode.Document); } } } } } return allSaved; }
/// <summary> /// Saves all asms/hex docs and returns true if all of them were saved to disk /// </summary> /// <param name="objs">All objects to save</param> /// <returns></returns> public static bool SaveAssemblies(IEnumerable<IUndoObject> objs) { var objsAry = objs.ToArray(); if (objsAry.Length == 0) return true; if (objsAry.Length == 1) { SaveOptionsVM options; var file = UndoCommandManager.Instance.TryGetDnSpyFile(objsAry[0]); if (file != null) { var optsData = new SaveModuleOptionsVM(file); var optsWin = new SaveModuleOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) return false; options = optsData; } else { var doc = UndoCommandManager.Instance.TryGetAsmEdHexDocument(objsAry[0]); Debug.Assert(doc != null); var optsData = new SaveHexOptionsVM(doc); var optsWin = new SaveHexOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) return false; options = optsData; } var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, options); var win = new SaveSingleModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; data.Save(); win.ShowDialog(); return MarkAsSaved(data, objsAry); } else { var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, objsAry); var win = new SaveMultiModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; win.ShowDialog(); return MarkAsSaved(data, objsAry); } }
static bool MarkAsSaved(SaveMultiModuleVM vm, IUndoObject[] objs) { bool setNewFileName = false; bool allSaved = true; foreach (var obj in objs) { if (!vm.WasSaved(obj)) allSaved = false; else { UndoCommandManager.Instance.MarkAsSaved(obj); var file = UndoCommandManager.Instance.TryGetDnSpyFile(obj); if (file != null && string.IsNullOrEmpty(file.Filename)) { var filename = vm.GetSavedFileName(obj); if (!string.IsNullOrWhiteSpace(filename) && file.ModuleDef != null) { file.ModuleDef.Location = filename; file.Filename = filename; setNewFileName = true; var asmNode = MainWindow.Instance.FindTreeNode(file.ModuleDef) as AssemblyTreeNode; Debug.Assert(asmNode != null); if (asmNode != null) { asmNode.OnFileNameChanged(); Utils.NotifyModifiedAssembly(file); } } } } } if (setNewFileName) MainWindow.Instance.DnSpyFileListManager.RefreshSave(MainWindow.Instance.DnSpyFileList); return allSaved; }
/// <summary> /// Saves all asms/hex docs and returns true if all of them were saved to disk /// </summary> /// <param name="objs">All objects to save</param> /// <returns></returns> public static bool SaveAssemblies(IEnumerable <IUndoObject> objs) { var objsAry = objs.ToArray(); if (objsAry.Length == 0) { return(true); } if (objsAry.Length == 1) { SaveOptionsVM options; var file = UndoCommandManager.Instance.TryGetDnSpyFile(objsAry[0]); if (file != null) { var optsData = new SaveModuleOptionsVM(file); var optsWin = new SaveModuleOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) { return(false); } options = optsData; } else { var doc = UndoCommandManager.Instance.TryGetAsmEdHexDocument(objsAry[0]); Debug.Assert(doc != null); var optsData = new SaveHexOptionsVM(doc); var optsWin = new SaveHexOptionsDlg(); optsWin.Owner = MainWindow.Instance; optsWin.DataContext = optsData; var res = optsWin.ShowDialog(); if (res != true) { return(false); } options = optsData; } var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, options); var win = new SaveSingleModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; data.Save(); win.ShowDialog(); return(MarkAsSaved(data, objsAry)); } else { var data = new SaveMultiModuleVM(MainWindow.Instance.Dispatcher, objsAry); var win = new SaveMultiModuleDlg(); win.Owner = MainWindow.Instance; win.DataContext = data; win.ShowDialog(); return(MarkAsSaved(data, objsAry)); } }
bool MarkAsSaved(SaveMultiModuleVM vm, object[] docs) { bool allSaved = true; foreach (var doc in docs) { if (!vm.WasSaved(doc)) allSaved = false; else { undoCommandManager.Value.MarkAsSaved(undoCommandManager.Value.GetUndoObject(doc)); var file = doc as IDnSpyFile; if (file != null && string.IsNullOrEmpty(file.Filename)) { var filename = vm.GetSavedFileName(doc); if (!string.IsNullOrWhiteSpace(filename) && file.ModuleDef != null) { file.ModuleDef.Location = filename; file.Filename = filename; var modNode = fileTabManager.FileTreeView.FindNode(file.ModuleDef) as IModuleFileNode; Debug.Assert(modNode != null); if (modNode != null) { modNode.TreeNode.RefreshUI(); fileTabManager.RefreshModifiedFile(modNode.DnSpyFile); } } } } } return allSaved; }