コード例 #1
0
        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));
            }
        }
コード例 #2
0
 public SaveModuleOptionsVM CopyTo(SaveModuleOptionsVM other)
 {
     other.FileName     = FileName;
     other.UseMixedMode = UseMixedMode;
     other.InitializeFrom(CreateWriterOptions());
     return(other);
 }
コード例 #3
0
        /// <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));
            }
        }
コード例 #4
0
ファイル: Saver.cs プロジェクト: gsong2014/dnSpy
        /// <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(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(objsAry);
                var win = new SaveMultiModuleDlg();
                win.Owner = MainWindow.Instance;
                win.DataContext = data;
                win.ShowDialog();
                return MarkAsSaved(data, objsAry);
            }
        }
コード例 #5
0
ファイル: DocumentSaver.cs プロジェクト: manojdjoshi/dnSpy
		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);
			}
		}
コード例 #6
0
ファイル: Saver.cs プロジェクト: arkanoid1/dnSpy
		/// <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);
			}
		}
コード例 #7
0
ファイル: SaveModuleWindow.cs プロジェクト: se7ensoft/dnSpy
        internal void ShowOptions(SaveModuleOptionsVM data)
        {
            if (data == null)
                return;

            var win = new SaveModuleOptions();
            win.Owner = this;
            var clone = data.Clone();
            win.DataContext = clone;
            var res = win.ShowDialog();
            if (res == true) {
                clone.CopyTo(data);
                ((SaveMultiModuleVM)DataContext).OnModuleSettingsSaved();
            }
        }
コード例 #8
0
        void Save(SaveModuleOptionsVM vm)
        {
            fileProgress = new ModuleFileProgress();
            var opts = vm.CreateWriterOptions();

            opts.Listener = this;
            opts.Logger   = this;
            var filename = vm.FileName;

            if (opts is NativeModuleWriterOptions)
            {
                ((ModuleDefMD)vm.Module).NativeWrite(filename, (NativeModuleWriterOptions)opts);
            }
            else
            {
                vm.Module.Write(filename, (ModuleWriterOptions)opts);
            }
        }
コード例 #9
0
ファイル: ModuleSaver.cs プロジェクト: unixfreaxjp/dnSpy
        void Save(SaveModuleOptionsVM vm)
        {
            fileProgress = new ModuleFileProgress();
            var opts = vm.CreateWriterOptions();

            opts.ProgressUpdated += ModuleWriter_ProgressUpdated;
            opts.Logger           = this;
            // Make sure the order of the interfaces don't change, see https://github.com/dotnet/roslyn/issues/3905
            opts.MetadataOptions.Flags |= MetadataFlags.RoslynSortInterfaceImpl;
            var filename = vm.FileName;

            if (opts is NativeModuleWriterOptions)
            {
                ((ModuleDefMD)vm.Module).NativeWrite(filename, (NativeModuleWriterOptions)opts);
            }
            else
            {
                vm.Module.Write(filename, (ModuleWriterOptions)opts);
            }
        }
コード例 #10
0
ファイル: SaveMultiModuleVM.cs プロジェクト: se7ensoft/dnSpy
 public SaveMultiModuleVM(SaveModuleOptionsVM options)
 {
     this.modules.Add(options);
 }
コード例 #11
0
ファイル: SaveMultiModuleVM.cs プロジェクト: se7ensoft/dnSpy
        void SaveAsync(SaveModuleOptionsVM[] mods)
        {
            try {
                moduleSaver = new ModuleSaver(mods);
                moduleSaver.OnProgressUpdated += moduleSaver_OnProgressUpdated;
                moduleSaver.OnLogMessage += moduleSaver_OnLogMessage;
                moduleSaver.OnWritingFile += moduleSaver_OnWritingFile;
                moduleSaver.SaveAll();
                AsyncAddMessage("All files written to disk.", false, false);
            }
            catch (TaskCanceledException) {
                AsyncAddMessage("Save was canceled by user.", true, false);
            }
            catch (UnauthorizedAccessException ex) {
                AsyncAddMessage(string.Format("Access error: {0}", ex.Message), true, false);
            }
            catch (IOException ex) {
                AsyncAddMessage(string.Format("File error: {0}", ex.Message), true, false);
            }
            catch (Exception ex) {
                AsyncAddMessage(string.Format("An exception occurred\n\n{0}", ex), true, false);
            }
            moduleSaver = null;

            ExecInOldThread(() => {
                CurrentFileName = string.Empty;
                State = SaveState.Saved;
            });
        }
コード例 #12
0
ファイル: ModuleSaver.cs プロジェクト: lovebanyi/dnSpy
		void Save(SaveModuleOptionsVM vm) {
			fileProgress = new ModuleFileProgress();
			var opts = vm.CreateWriterOptions();
			opts.Listener = this;
			opts.Logger = this;
			var filename = vm.FileName;
			if (opts is NativeModuleWriterOptions)
				((ModuleDefMD)vm.Module).NativeWrite(filename, (NativeModuleWriterOptions)opts);
			else
				vm.Module.Write(filename, (ModuleWriterOptions)opts);
		}
コード例 #13
0
ファイル: ModuleSaver.cs プロジェクト: se7ensoft/dnSpy
 public ModuleSaverWriteEventArgs(SaveModuleOptionsVM vm, bool starting)
 {
     this.File = vm;
     this.Starting = starting;
 }
コード例 #14
0
ファイル: ModuleSaver.cs プロジェクト: se7ensoft/dnSpy
 public SaveState(SaveModuleOptionsVM vm)
 {
     this.File = vm;
 }
コード例 #15
0
ファイル: SaveModuleOptionsVM.cs プロジェクト: nakijun/dnSpy
		public SaveModuleOptionsVM CopyTo(SaveModuleOptionsVM other) {
			other.FileName = FileName;
			other.UseMixedMode = UseMixedMode;
			other.InitializeFrom(CreateWriterOptions());
			return other;
		}
コード例 #16
0
ファイル: Saver.cs プロジェクト: xornand/dnSpy
        /// <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));
            }
        }