Пример #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
        /// <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
		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
		/// <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
        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
        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
 public SaveMultiModuleVM(SaveModuleOptionsVM options)
 {
     this.modules.Add(options);
 }
Пример #11
0
        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
		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
 public ModuleSaverWriteEventArgs(SaveModuleOptionsVM vm, bool starting)
 {
     this.File = vm;
     this.Starting = starting;
 }
Пример #14
0
 public SaveState(SaveModuleOptionsVM vm)
 {
     this.File = vm;
 }
Пример #15
0
		public SaveModuleOptionsVM CopyTo(SaveModuleOptionsVM other) {
			other.FileName = FileName;
			other.UseMixedMode = UseMixedMode;
			other.InitializeFrom(CreateWriterOptions());
			return other;
		}
Пример #16
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 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));
            }
        }