コード例 #1
0
        private static Byte[] ReconstructRawData(IconDirectory dir, FileIconDirectoryEntry[] ents, IconCursorImageResourceData[] images, ResourceSource source)
        {
            Int32 sizeOfIconDirectory = Marshal.SizeOf(typeof(IconDirectory));
            Int32 sizeOfResIconDirEnt = Marshal.SizeOf(typeof(ResIconDirectoryEntry));

            Int32 sizeOfData =
                sizeOfIconDirectory +
                sizeOfResIconDirEnt * dir.wCount;

            IntPtr p = Marshal.AllocHGlobal(sizeOfData);

            Marshal.StructureToPtr(dir, p, true);

            IntPtr q = Inc(p, Marshal.SizeOf(typeof(IconDirectory)));

            for (int i = 0; i < ents.Length; i++)
            {
                FileIconDirectoryEntry e = ents[i];

                ResourceTypeIdentifier iconImageTypeId = new ResourceTypeIdentifier(new IntPtr((int)Win32ResourceType.IconImage));
                ResourceIdentifier     nameId          = source.GetUnusedName(iconImageTypeId);
                source.Add(iconImageTypeId, nameId, 1033, images[i]);

                ResIconDirectoryEntry d = new ResIconDirectoryEntry()
                {
                    bWidth       = e.bWidth,
                    bHeight      = e.bHeight,
                    bColorCount  = e.bColorCount,
                    bReserved    = e.bReserved,
                    wPlanes      = e.wPlanes,
                    wBitCount    = e.wPlanes,
                    dwBytesInRes = e.dwBytesInRes,
                    wId          = (ushort)images[i].Lang.Name.Identifier.NativeId
                };

                Marshal.StructureToPtr(d, q, true);
                q = Inc(q, sizeOfResIconDirEnt);
            }

            Byte[] data = new Byte[sizeOfData];
            Marshal.Copy(p, data, 0, sizeOfData);

            Marshal.FreeHGlobal(p);

            return(data);

            // Major problem:
            // RawData of a directory contains the ResourceNames of the entries in the ResourceSource
            // seeming as this source does not exist, what should go in their place?

            // idea:
            // when a ResourceData is created from a file it is passed the current ResourceSource which it can 'preliminarily add' the datas to
            //	a UI will need to be presented to prompt the user for details if not in Simple Mode. A UI is presented anyway, so this works.

            // this way the IconCursorImageResourceData has been added to the ResourceSource (with the Action.Add property) and this method can
            //	just query ResourceName. Simple (sort-of)
        }
コード例 #2
0
        /// <summary>Associates all of the IconImages in this directory with the ResourceSource by creating IconCursorResourceData instances for each IconImage (with the specified Lang)</summary>
        public void BindToSource(ResourceSource source, UInt16 langId)
        {
            IconCursorImageResourceDataFactory factory = GetImageFactory();

            ResourceTypeIdentifier typeId = Type == IconType.Icon ? _iiTypeId : _ciTypeId;

            foreach (IconImage image in _images)
            {
                IconCursorImageResourceData rd = (IconCursorImageResourceData)factory.FromFileData(null, image.ImageData, Type == IconType.Icon);

                image.ResourceDataTyped = rd;

                source.Add(typeId, source.GetUnusedName(typeId), langId, rd);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Associates all of the IconImages in this directory with the ResourceSource by creating IconCursorResourceData
        ///     instances for each IconImage (with the specified Lang)
        /// </summary>
        public void BindToSource(ResourceSource source, ushort langId)
        {
            var factory = GetImageFactory();

            var typeId = Type == IconType.Icon ? _iiTypeId : _ciTypeId;

            foreach (var directoryMember in _images)
            {
                var image = (IconImage)directoryMember;
                var rd    = factory.FromFileData(null, image.ImageData, Type == IconType.Icon);

                image.ResourceDataTyped = rd;

                source.Add(typeId, source.GetUnusedName(typeId), langId, rd);
            }
        }