Ejemplo n.º 1
0
        public ResourceElementVM(ResourceElementOptions options, ModuleDef ownerModule, bool canDeserialize)
        {
            origOptions         = options;
            this.canDeserialize = canDeserialize;

            BooleanVM             = new BooleanVM(a => HasErrorUpdated());
            CharVM                = new CharVM(a => HasErrorUpdated());
            ByteVM                = new ByteVM(a => HasErrorUpdated());
            SByteVM               = new SByteVM(a => HasErrorUpdated());
            Int16VM               = new Int16VM(a => HasErrorUpdated());
            UInt16VM              = new UInt16VM(a => HasErrorUpdated());
            Int32VM               = new Int32VM(a => HasErrorUpdated());
            UInt32VM              = new UInt32VM(a => HasErrorUpdated());
            Int64VM               = new Int64VM(a => HasErrorUpdated());
            UInt64VM              = new UInt64VM(a => HasErrorUpdated());
            SingleVM              = new SingleVM(a => HasErrorUpdated());
            DoubleVM              = new DoubleVM(a => HasErrorUpdated());
            DecimalVM             = new DecimalVM(a => HasErrorUpdated());
            DateTimeVM            = new DateTimeVM(a => HasErrorUpdated());
            TimeSpanVM            = new TimeSpanVM(a => HasErrorUpdated());
            UserTypeVM            = new UserTypeVM(ownerModule, canDeserialize);
            ResourceElementTypeVM = new EnumListVM(resourceElementTypeList, (a, b) => OnResourceElementTypeChanged());

            UserTypeVM.PropertyChanged += (s, e) => {
                if (e.PropertyName == nameof(UserTypeVM.HasError))
                {
                    HasErrorUpdated();
                }
            };

            Reinitialize();
        }
Ejemplo n.º 2
0
        public ResourceElementVM(ResourceElementOptions options, ModuleDef ownerModule, bool canDeserialize)
        {
            this.origOptions    = options;
            this.canDeserialize = canDeserialize;

            this.booleanVM             = new BooleanVM(a => HasErrorUpdated());
            this.charVM                = new CharVM(a => HasErrorUpdated());
            this.byteVM                = new ByteVM(a => HasErrorUpdated());
            this.sbyteVM               = new SByteVM(a => HasErrorUpdated());
            this.int16VM               = new Int16VM(a => HasErrorUpdated());
            this.uint16VM              = new UInt16VM(a => HasErrorUpdated());
            this.int32VM               = new Int32VM(a => HasErrorUpdated());
            this.uint32VM              = new UInt32VM(a => HasErrorUpdated());
            this.int64VM               = new Int64VM(a => HasErrorUpdated());
            this.uint64VM              = new UInt64VM(a => HasErrorUpdated());
            this.singleVM              = new SingleVM(a => HasErrorUpdated());
            this.doubleVM              = new DoubleVM(a => HasErrorUpdated());
            this.decimalVM             = new DecimalVM(a => HasErrorUpdated());
            this.dateTimeVM            = new DateTimeVM(a => HasErrorUpdated());
            this.timeSpanVM            = new TimeSpanVM(a => HasErrorUpdated());
            this.userTypeVM            = new UserTypeVM(ownerModule, canDeserialize);
            this.resourceElementTypeVM = new EnumListVM(resourceElementTypeList, (a, b) => OnResourceElementTypeChanged());

            this.UserTypeVM.PropertyChanged += (s, e) => {
                if (e.PropertyName == "HasError")
                {
                    HasErrorUpdated();
                }
            };

            Reinitialize();
        }
Ejemplo n.º 3
0
		void InitializeFrom(ResourceElementOptions options) {
			if (options.ResourceData.Code != ResourceTypeCode.ByteArray && options.ResourceData.Code != ResourceTypeCode.Stream)
				throw new InvalidOperationException();
			var builtin = (BuiltInResourceData)options.ResourceData;

			resourceTypeCode = options.ResourceData.Code;
			Name = options.Name;
			Data = (byte[])builtin.Data;
		}
Ejemplo n.º 4
0
        void InitializeFrom(ResourceElementOptions options)
        {
            this.Name = options.Name;
            var code    = Convert(options.ResourceData.Code);
            var builtin = options.ResourceData as BuiltInResourceData;

            this.ResourceElementTypeVM.SelectedItem = code;
            switch (code)
            {
            case ResourceElementType.Null:          break;

            case ResourceElementType.String:        String = (string)builtin.Data; break;

            case ResourceElementType.Boolean:       BooleanVM.Value = (bool)builtin.Data; break;

            case ResourceElementType.Char:          CharVM.Value = (char)builtin.Data; break;

            case ResourceElementType.Byte:          ByteVM.Value = (byte)builtin.Data; break;

            case ResourceElementType.SByte:         SByteVM.Value = (sbyte)builtin.Data; break;

            case ResourceElementType.Int16:         Int16VM.Value = (short)builtin.Data; break;

            case ResourceElementType.UInt16:        UInt16VM.Value = (ushort)builtin.Data; break;

            case ResourceElementType.Int32:         Int32VM.Value = (int)builtin.Data; break;

            case ResourceElementType.UInt32:        UInt32VM.Value = (uint)builtin.Data; break;

            case ResourceElementType.Int64:         Int64VM.Value = (long)builtin.Data; break;

            case ResourceElementType.UInt64:        UInt64VM.Value = (ulong)builtin.Data; break;

            case ResourceElementType.Single:        SingleVM.Value = (float)builtin.Data; break;

            case ResourceElementType.Double:        DoubleVM.Value = (double)builtin.Data; break;

            case ResourceElementType.Decimal:       DecimalVM.Value = (decimal)builtin.Data; break;

            case ResourceElementType.DateTime:      DateTimeVM.Value = (DateTime)builtin.Data; break;

            case ResourceElementType.TimeSpan:      TimeSpanVM.Value = (TimeSpan)builtin.Data; break;

            case ResourceElementType.ByteArray:     Data = (byte[])builtin.Data; break;

            case ResourceElementType.Stream:        Data = (byte[])builtin.Data; break;

            case ResourceElementType.SerializedType:
                var binRes = (BinaryResourceData)options.ResourceData;
                UserTypeVM.TypeFullName = binRes.TypeName;
                UserTypeVM.SetData(binRes.Data);
                break;

            default: throw new InvalidOperationException();
            }
        }
Ejemplo n.º 5
0
        void InitializeFrom(ResourceElementOptions options)
        {
            if (options.ResourceData.Code != ResourceTypeCode.ByteArray && options.ResourceData.Code != ResourceTypeCode.Stream)
            {
                throw new InvalidOperationException();
            }
            var builtin = (BuiltInResourceData)options.ResourceData;

            resourceTypeCode = options.ResourceData.Code;
            Name             = options.Name;
            Data             = (byte[])builtin.Data;
        }
Ejemplo n.º 6
0
        public ResourceElementVM(ResourceElementOptions options, ModuleDef ownerModule, bool canDeserialize)
        {
            this.origOptions = options;
            this.canDeserialize = canDeserialize;

            this.booleanVM = new BooleanVM(a => HasErrorUpdated());
            this.charVM = new CharVM(a => HasErrorUpdated());
            this.byteVM = new ByteVM(a => HasErrorUpdated());
            this.sbyteVM = new SByteVM(a => HasErrorUpdated());
            this.int16VM = new Int16VM(a => HasErrorUpdated());
            this.uint16VM = new UInt16VM(a => HasErrorUpdated());
            this.int32VM = new Int32VM(a => HasErrorUpdated());
            this.uint32VM = new UInt32VM(a => HasErrorUpdated());
            this.int64VM = new Int64VM(a => HasErrorUpdated());
            this.uint64VM = new UInt64VM(a => HasErrorUpdated());
            this.singleVM = new SingleVM(a => HasErrorUpdated());
            this.doubleVM = new DoubleVM(a => HasErrorUpdated());
            this.decimalVM = new DecimalVM(a => HasErrorUpdated());
            this.dateTimeVM = new DateTimeVM(a => HasErrorUpdated());
            this.timeSpanVM = new TimeSpanVM(a => HasErrorUpdated());
            this.userTypeVM = new UserTypeVM(ownerModule, canDeserialize);
            this.resourceElementTypeVM = new EnumListVM(resourceElementTypeList, (a, b) => OnResourceElementTypeChanged());

            this.UserTypeVM.PropertyChanged += (s, e) => {
                if (e.PropertyName == "HasError")
                    HasErrorUpdated();
            };

            Reinitialize();
        }
Ejemplo n.º 7
0
        void InitializeFrom(ResourceElementOptions options)
        {
            this.Name = options.Name;
            var code = Convert(options.ResourceData.Code);
            var builtin = options.ResourceData as BuiltInResourceData;
            this.ResourceElementTypeVM.SelectedItem = code;
            switch (code) {
            case ResourceElementType.Null:		break;
            case ResourceElementType.String:	String = (string)builtin.Data; break;
            case ResourceElementType.Boolean:	BooleanVM.Value = (bool)builtin.Data; break;
            case ResourceElementType.Char:		CharVM.Value = (char)builtin.Data; break;
            case ResourceElementType.Byte:		ByteVM.Value = (byte)builtin.Data; break;
            case ResourceElementType.SByte:		SByteVM.Value = (sbyte)builtin.Data; break;
            case ResourceElementType.Int16:		Int16VM.Value = (short)builtin.Data; break;
            case ResourceElementType.UInt16:	UInt16VM.Value = (ushort)builtin.Data; break;
            case ResourceElementType.Int32:		Int32VM.Value = (int)builtin.Data; break;
            case ResourceElementType.UInt32:	UInt32VM.Value = (uint)builtin.Data; break;
            case ResourceElementType.Int64:		Int64VM.Value = (long)builtin.Data; break;
            case ResourceElementType.UInt64:	UInt64VM.Value = (ulong)builtin.Data; break;
            case ResourceElementType.Single:	SingleVM.Value = (float)builtin.Data; break;
            case ResourceElementType.Double:	DoubleVM.Value = (double)builtin.Data; break;
            case ResourceElementType.Decimal:	DecimalVM.Value = (decimal)builtin.Data; break;
            case ResourceElementType.DateTime:	DateTimeVM.Value = (DateTime)builtin.Data; break;
            case ResourceElementType.TimeSpan:	TimeSpanVM.Value = (TimeSpan)builtin.Data; break;
            case ResourceElementType.ByteArray:	Data = (byte[])builtin.Data; break;
            case ResourceElementType.Stream:	Data = (byte[])builtin.Data; break;

            case ResourceElementType.SerializedType:
                var binRes = (BinaryResourceData)options.ResourceData;
                UserTypeVM.TypeFullName = binRes.TypeName;
                UserTypeVM.SetData(binRes.Data);
                break;

            default: throw new InvalidOperationException();
            }
        }
Ejemplo n.º 8
0
 ResourceElementOptions CopyTo(ResourceElementOptions options)
 {
     options.Name = this.Name;
     options.ResourceData = CreateResourceData();
     return options;
 }
Ejemplo n.º 9
0
		ResourceElementOptions CopyTo(ResourceElementOptions options) {
			options.Name = this.Name;
			options.ResourceData = new BuiltInResourceData(resourceTypeCode, Data);
			return options;
		}
Ejemplo n.º 10
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var imgNode = (SerializedImageListStreamerResourceElementTreeNode)nodes[0];
            var options = new ImageListOptions(imgNode.ImageListOptions);
            var data = new ImageListVM(options);
            var win = new ImageListDlg();
            win.Title = CMD_NAME;
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            var listOpts = data.CreateImageListOptions();

            if (listOpts.ImageSources.Count == 0) {
                MainWindow.Instance.ShowMessageBox("It's not possible to create an empty image list");
                return;
            }

            ResourceElementOptions opts = null;
            string error;
            try {
                opts = new ResourceElementOptions(SerializedImageListStreamerResourceElementTreeNode.Serialize(listOpts));
                error = imgNode.CheckCanUpdateData(opts.Create());
            }
            catch (Exception ex) {
                error = string.Format("Couldn't serialize the images. Error: {0}", ex.Message);
            }
            if (!string.IsNullOrEmpty(error)) {
                MainWindow.Instance.ShowMessageBox(error);
                return;
            }

            UndoCommandManager.Instance.Add(new SerializedImageListStreamerResourceElementSettingsCommand(imgNode, opts));
        }
Ejemplo n.º 11
0
        protected ResourceElementSettingsBaseCommand(ResourceElementTreeNode rsrcElNode, ResourceElementOptions options)
        {
            this.rsrcSetNode = (ResourceElementSetTreeNode)rsrcElNode.Parent;
            this.rsrcElNode = rsrcElNode;
            this.newOptions = options.Create();
            this.origOptions = rsrcElNode.ResourceElement;

            this.module = ILSpyTreeNode.GetModule(rsrcSetNode);
            Debug.Assert(this.module != null);
            this.resource = rsrcSetNode.Resource;
            this.resourceIndex = module.Resources.IndexOf(this.resource);
            Debug.Assert(this.resourceIndex >= 0);
            if (this.resourceIndex < 0)
                throw new InvalidOperationException();

            this.origParentChildIndex = this.rsrcSetNode.Children.IndexOf(rsrcElNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
        }
Ejemplo n.º 12
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var imgNode = (ISerializedImageListStreamerResourceElementNode)nodes[0];
			var options = new ImageListOptions(imgNode.ImageListOptions);
			var data = new ImageListVM(options);
			var win = new ImageListDlg();
			win.Title = dnSpy_AsmEditor_Resources.EditResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var listOpts = data.CreateImageListOptions();

			if (listOpts.ImageSources.Count == 0) {
				Shared.App.MsgBox.Instance.Show(dnSpy_AsmEditor_Resources.Error_EmptyImageList);
				return;
			}

			ResourceElementOptions opts = null;
			string error;
			try {
				opts = new ResourceElementOptions(SerializedImageListStreamerUtils.Serialize(listOpts));
				error = imgNode.CheckCanUpdateData(opts.Create());
			}
			catch (Exception ex) {
				error = string.Format(dnSpy_AsmEditor_Resources.Error_CouldNotSerializeImages, ex.Message);
			}
			if (!string.IsNullOrEmpty(error)) {
				Shared.App.MsgBox.Instance.Show(error);
				return;
			}

			undoCommandManager.Value.Add(new SerializedImageListStreamerResourceElementSettingsCommand(imgNode, opts));
		}
Ejemplo n.º 13
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var imgRsrcElNode = (IImageResourceElementNode)nodes[0];

			var options = new ResourceElementOptions(imgRsrcElNode.ResourceElement);
			var data = new ImageResourceElementVM(options);
			var win = new ImageResourceElementDlg();
			win.Title = dnSpy_AsmEditor_Resources.EditResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var opts = data.CreateResourceElementOptions();
			string error;
			try {
				error = imgRsrcElNode.CheckCanUpdateData(opts.Create());
			}
			catch (Exception ex) {
				error = string.Format(dnSpy_AsmEditor_Resources.Error_NewResourceDataMustBeImage, ex.Message);
			}
			if (!string.IsNullOrEmpty(error)) {
				Shared.App.MsgBox.Instance.Show(error);
				return;
			}

			undoCommandManager.Value.Add(new ImageResourceElementSettingsCommand(imgRsrcElNode, opts));
		}
Ejemplo n.º 14
0
		ImageResourceElementSettingsCommand(IResourceElementNode rsrcElNode, ResourceElementOptions options)
			: base(rsrcElNode, options) {
		}
Ejemplo n.º 15
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeViewSettings fileTreeViewSettings, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var rsrcElNode = (IResourceElementNode)nodes[0];
			var module = nodes[0].GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			var options = new ResourceElementOptions(rsrcElNode.ResourceElement);
			var data = new ResourceElementVM(options, module, fileTreeViewSettings.DeserializeResources);
			data.CanChangeType = false;
			var win = new ResourceElementDlg();
			win.Title = dnSpy_AsmEditor_Resources.EditResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var opts = data.CreateResourceElementOptions();
			string error;
			try {
				error = rsrcElNode.CheckCanUpdateData(opts.Create());
			}
			catch (Exception ex) {
				error = string.Format(dnSpy_AsmEditor_Resources.Error_InvalidResourceData, ex.Message);
			}
			if (!string.IsNullOrEmpty(error)) {
				Shared.App.MsgBox.Instance.Show(error);
				return;
			}

			undoCommandManager.Value.Add(new ResourceElementSettingsCommand(rsrcElNode, opts));
		}
Ejemplo n.º 16
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IResourceNodeFactory resourceNodeFactory, IFileTreeViewSettings fileTreeViewSettings, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var rsrcSetNode = nodes[0] as IResourceElementSetNode;
			if (rsrcSetNode == null)
				rsrcSetNode = nodes[0].TreeNode.Parent.Data as IResourceElementSetNode;
			Debug.Assert(rsrcSetNode != null);

			var module = nodes[0].GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			var options = new ResourceElementOptions(new ResourceElement {
				Name = string.Empty,
				ResourceData = new BuiltInResourceData(ResourceTypeCode.String, string.Empty),
			});
			var data = new ResourceElementVM(options, module, fileTreeViewSettings.DeserializeResources);
			var win = new ResourceElementDlg();
			win.Title = dnSpy_AsmEditor_Resources.CreateResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var opts = data.CreateResourceElementOptions();
			var treeView = appWindow.FileTreeView.TreeView;
			var treeNodeGroup = appWindow.FileTreeView.FileTreeNodeGroups.GetGroup(FileTreeNodeGroupType.ResourceElementTreeNodeGroup);
			var node = (IResourceElementNode)treeView.Create(resourceNodeFactory.Create(module, opts.Create(), treeNodeGroup)).Data;
			undoCommandManager.Value.Add(new CreateResourceElementCommand(rsrcSetNode, node));
			appWindow.FileTabManager.FollowReference(node);
		}
Ejemplo n.º 17
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IResourceNodeFactory resourceNodeFactory, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var rsrcSetNode = nodes[0] as IResourceElementSetNode;
			if (rsrcSetNode == null)
				rsrcSetNode = nodes[0].TreeNode.Parent.Data as IResourceElementSetNode;
			Debug.Assert(rsrcSetNode != null);

			var module = nodes[0].GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			var data = new ImageListVM(new ImageListOptions() { Name = "my.ImageStream" });
			var win = new ImageListDlg();
			win.Title = dnSpy_AsmEditor_Resources.CreateImageListStreamerResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			if (data.ImageListStreamerVM.Collection.Count == 0) {
				Shared.App.MsgBox.Instance.Show(dnSpy_AsmEditor_Resources.Error_EmptyImageList);
				return;
			}

			var listOpts = data.CreateImageListOptions();
			ResourceElementOptions opts = null;
			string error;
			try {
				opts = new ResourceElementOptions(SerializedImageListStreamerUtils.Serialize(listOpts));
				error = SerializedImageListStreamerUtils.CheckCanUpdateData(module, opts.Create());
			}
			catch (Exception ex) {
				error = string.Format(dnSpy_AsmEditor_Resources.Error_CouldNotSerializeImages, ex.Message);
			}
			if (!string.IsNullOrEmpty(error)) {
				Shared.App.MsgBox.Instance.Show(error);
				return;
			}

			var treeView = appWindow.FileTreeView.TreeView;
			var treeNodeGroup = appWindow.FileTreeView.FileTreeNodeGroups.GetGroup(FileTreeNodeGroupType.ResourceElementTreeNodeGroup);
			var newNode = (ISerializedImageListStreamerResourceElementNode)treeView.Create(resourceNodeFactory.Create(module, opts.Create(), treeNodeGroup)).Data;
			undoCommandManager.Value.Add(new CreateImageListResourceElementCommand(rsrcSetNode, newNode));
			appWindow.FileTabManager.FollowReference(newNode);
		}
Ejemplo n.º 18
0
 ResourceElementOptions CopyTo(ResourceElementOptions options)
 {
     options.Name         = Name;
     options.ResourceData = new BuiltInResourceData(resourceTypeCode, Data);
     return(options);
 }
Ejemplo n.º 19
0
		SerializedImageListStreamerResourceElementSettingsCommand(IResourceElementNode rsrcElNode, ResourceElementOptions options)
			: base(rsrcElNode, options) {
		}
Ejemplo n.º 20
0
        public ImageResourceElementVM(ResourceElementOptions options)
        {
            origOptions = options;

            Reinitialize();
        }
Ejemplo n.º 21
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var imgRsrcElNode = (SerializedImageResourceElementTreeNode)nodes[0];
            var options = new ResourceElementOptions(imgRsrcElNode.GetAsRawImage());
            var data = new ImageResourceElementVM(options);
            var win = new ImageResourceElementDlg();
            win.Title = CMD_NAME;
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            var opts = data.CreateResourceElementOptions();
            string error;
            try {
                opts = new ResourceElementOptions(imgRsrcElNode.Serialize(opts.Create()));
                error = imgRsrcElNode.CheckCanUpdateData(opts.Create());
            }
            catch (Exception ex) {
                error = string.Format("New data must be an image. Error: {0}", ex.Message);
            }
            if (!string.IsNullOrEmpty(error)) {
                MainWindow.Instance.ShowMessageBox(error);
                return;
            }

            UndoCommandManager.Instance.Add(new SerializedImageResourceElementSettingsCommand(imgRsrcElNode, opts));
        }
Ejemplo n.º 22
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var rsrcSetNode = nodes[0] as ResourceElementSetTreeNode;
            if (rsrcSetNode == null)
                rsrcSetNode = nodes[0].Parent as ResourceElementSetTreeNode;
            Debug.Assert(rsrcSetNode != null);

            var module = ILSpyTreeNode.GetModule(nodes[0]);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            var options = new ResourceElementOptions(new ResourceElement {
                Name = string.Empty,
                ResourceData = new BuiltInResourceData(ResourceTypeCode.String, string.Empty),
            });
            var data = new ResourceElementVM(options, module, OtherSettings.Instance.DeserializeResources);
            var win = new ResourceElementDlg();
            win.Title = CMD_NAME;
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            var opts = data.CreateResourceElementOptions();
            var node = ResourceFactory.Create(module, opts.Create());
            UndoCommandManager.Instance.Add(new CreateResourceElementCommand(rsrcSetNode, node));
        }
Ejemplo n.º 23
0
		public ResourceElementVM(ResourceElementOptions options, ModuleDef ownerModule, bool canDeserialize) {
			origOptions = options;
			this.canDeserialize = canDeserialize;

			BooleanVM = new BooleanVM(a => HasErrorUpdated());
			CharVM = new CharVM(a => HasErrorUpdated());
			ByteVM = new ByteVM(a => HasErrorUpdated());
			SByteVM = new SByteVM(a => HasErrorUpdated());
			Int16VM = new Int16VM(a => HasErrorUpdated());
			UInt16VM = new UInt16VM(a => HasErrorUpdated());
			Int32VM = new Int32VM(a => HasErrorUpdated());
			UInt32VM = new UInt32VM(a => HasErrorUpdated());
			Int64VM = new Int64VM(a => HasErrorUpdated());
			UInt64VM = new UInt64VM(a => HasErrorUpdated());
			SingleVM = new SingleVM(a => HasErrorUpdated());
			DoubleVM = new DoubleVM(a => HasErrorUpdated());
			DecimalVM = new DecimalVM(a => HasErrorUpdated());
			DateTimeVM = new DateTimeVM(a => HasErrorUpdated());
			TimeSpanVM = new TimeSpanVM(a => HasErrorUpdated());
			UserTypeVM = new UserTypeVM(ownerModule, canDeserialize);
			ResourceElementTypeVM = new EnumListVM(resourceElementTypeList, (a, b) => OnResourceElementTypeChanged());

			UserTypeVM.PropertyChanged += (s, e) => {
				if (e.PropertyName == nameof(UserTypeVM.HasError))
					HasErrorUpdated();
			};

			Reinitialize();
		}
Ejemplo n.º 24
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var rsrcElNode = (ResourceElementTreeNode)nodes[0];
            var module = ILSpyTreeNode.GetModule(nodes[0]);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            var options = new ResourceElementOptions(rsrcElNode.ResourceElement);
            var data = new ResourceElementVM(options, module, OtherSettings.Instance.DeserializeResources);
            data.CanChangeType = false;
            var win = new ResourceElementDlg();
            win.Title = CMD_NAME;
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            var opts = data.CreateResourceElementOptions();
            string error;
            try {
                error = rsrcElNode.CheckCanUpdateData(opts.Create());
            }
            catch (Exception ex) {
                error = string.Format("Can't use this data: {0}", ex.Message);
            }
            if (!string.IsNullOrEmpty(error)) {
                MainWindow.Instance.ShowMessageBox(error);
                return;
            }

            UndoCommandManager.Instance.Add(new ResourceElementSettingsCommand(rsrcElNode, opts));
        }
Ejemplo n.º 25
0
 ResourceElementOptions CopyTo(ResourceElementOptions options)
 {
     options.Name         = this.Name;
     options.ResourceData = CreateResourceData();
     return(options);
 }
Ejemplo n.º 26
0
 SerializedImageResourceElementSettingsCommand(ResourceElementTreeNode rsrcElNode, ResourceElementOptions options)
     : base(rsrcElNode, options)
 {
 }
Ejemplo n.º 27
0
		public ImageResourceElementVM(ResourceElementOptions options) {
			this.origOptions = options;

			Reinitialize();
		}
Ejemplo n.º 28
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var rsrcSetNode = nodes[0] as ResourceElementSetTreeNode;
            if (rsrcSetNode == null)
                rsrcSetNode = nodes[0].Parent as ResourceElementSetTreeNode;
            Debug.Assert(rsrcSetNode != null);

            var module = ILSpyTreeNode.GetModule(nodes[0]);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            var data = new ImageListVM(new ImageListOptions() { Name = "my.ImageStream" });
            var win = new ImageListDlg();
            win.Title = CMD_NAME;
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            if (data.ImageListStreamerVM.Collection.Count == 0) {
                MainWindow.Instance.ShowMessageBox("It's not possible to create an empty image list");
                return;
            }

            var listOpts = data.CreateImageListOptions();
            ResourceElementOptions opts = null;
            string error;
            try {
                opts = new ResourceElementOptions(SerializedImageListStreamerResourceElementTreeNode.Serialize(listOpts));
                error = SerializedImageListStreamerResourceElementTreeNode.CheckCanUpdateData(module, opts.Create());
            }
            catch (Exception ex) {
                error = string.Format("Couldn't serialize the images. Error: {0}", ex.Message);
            }
            if (!string.IsNullOrEmpty(error)) {
                MainWindow.Instance.ShowMessageBox(error);
                return;
            }

            var newNode = (SerializedImageListStreamerResourceElementTreeNode)ResourceFactory.Create(module, opts.Create());
            UndoCommandManager.Instance.Add(new CreateImageListResourceElementCommand(rsrcSetNode, newNode));
        }
Ejemplo n.º 29
0
		static void Execute(Lazy<IUndoCommandService> undoCommandService, IAppService appService, DocumentTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var imgRsrcElNode = (SerializedImageResourceElementNode)nodes[0];
			var options = new ResourceElementOptions(imgRsrcElNode.GetAsRawImage());
			var data = new ImageResourceElementVM(options);
			var win = new ImageResourceElementDlg();
			win.Title = dnSpy_AsmEditor_Resources.EditResourceCommand2;
			win.DataContext = data;
			win.Owner = appService.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var opts = data.CreateResourceElementOptions();
			string error;
			try {
				opts = new ResourceElementOptions(SerializedImageUtilities.Serialize(opts.Create()));
				error = imgRsrcElNode.CheckCanUpdateData(opts.Create());
			}
			catch (Exception ex) {
				error = string.Format(dnSpy_AsmEditor_Resources.Error_NewResourceDataMustBeImage, ex.Message);
			}
			if (!string.IsNullOrEmpty(error)) {
				MsgBox.Instance.Show(error);
				return;
			}

			undoCommandService.Value.Add(new SerializedImageResourceElementSettingsCommand(imgRsrcElNode, opts));
		}