Exemplo n.º 1
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();
            }
        }
Exemplo 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();
        }
Exemplo n.º 3
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, Options.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));
        }
Exemplo n.º 4
0
 ResourceElementOptions CopyTo(ResourceElementOptions options)
 {
     options.Name = this.Name;
     options.ResourceData = CreateResourceData();
     return options;
 }
Exemplo n.º 5
0
 SerializedImageResourceElementSettingsCommand(ResourceElementTreeNode rsrcElNode, ResourceElementOptions options)
     : base(rsrcElNode, options)
 {
 }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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, Options.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));
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
        public ImageResourceElementVM(ResourceElementOptions options)
        {
            this.origOptions = options;

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

            this.resourceTypeCode = options.ResourceData.Code;
            this.Name = options.Name;
            this.Data = (byte[])builtin.Data;
        }
Exemplo n.º 11
0
 ResourceElementOptions CopyTo(ResourceElementOptions options)
 {
     options.Name = this.Name;
     options.ResourceData = new BuiltInResourceData(resourceTypeCode, Data);
     return options;
 }