Esempio n. 1
0
 private MenuResourceData(ResourceLang lang, byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 2
0
 public abstract ResourceData FromFileToUpdate(Stream stream, string extension, ResourceLang currentLang);
Esempio n. 3
0
 private TiffImageResourceData(Image image, ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
     _image = image;
 }
Esempio n. 4
0
        public static Boolean TryCreateFromRes(ResourceLang lang, Byte[] rawData, out IconDirectoryResourceData typed)
        {
            Int32 sizeOfIconDir = Marshal.SizeOf(typeof(IconDirectory));
            Int32 sizeOfDirEntr = Marshal.SizeOf(typeof(ResIconDirectoryEntry));

            // the data in here is an ICONDIR structure

            IntPtr p = Marshal.AllocHGlobal(rawData.Length);

            Marshal.Copy(rawData, 0, p, rawData.Length);

            // this could be vastly simplified by correctly marshaling the member array of IconDirectory
            // but that's a can of worms, I'd rather not
            IconDirectory dir = (IconDirectory)Marshal.PtrToStructure(p, typeof(IconDirectory));

            Marshal.FreeHGlobal(p);

            if (dir.wType != 1)
            {
                throw new InvalidOperationException("Provided rawData was not that of an icon's");
            }

            ResIconDirectoryEntry[] subImages = new ResIconDirectoryEntry[dir.wCount];

            for (int i = 0; i < dir.wCount; i++)
            {
                Int32 byteOffset = sizeOfIconDir + sizeOfDirEntr * i;

                p = Marshal.AllocHGlobal(sizeOfDirEntr);
                Marshal.Copy(rawData, byteOffset, p, sizeOfDirEntr);

                ResIconDirectoryEntry img = (ResIconDirectoryEntry)Marshal.PtrToStructure(p, typeof(ResIconDirectoryEntry));

                subImages[i] = img;
            }

            IconDirectoryResourceData retval = new IconDirectoryResourceData(lang, rawData);

            // then we might be able to get the resourcedata for the subimages to include in the directory

            // find the Icon Image resource type
            ResourceType iconType = null;

            foreach (ResourceType type in lang.Name.Type.Source.Types)
            {
                if (type.Identifier.KnownType == Win32ResourceType.IconImage)
                {
                    iconType = type;
                    break;
                }
            }

            if (iconType != null)
            {
                foreach (ResIconDirectoryEntry img in subImages)
                {
                    IconCursorImageResourceData rd = GetDataFromWid(iconType, lang, img.wId);

                    String description = String.Format(
                        Cult.InvariantCulture,
                        "{0}x{1} {2}-bit",
                        img.bWidth == 0 ? 256 : img.bWidth,
                        img.bHeight == 0 ? 256 : img.bHeight,
                        img.wBitCount
                        );

                    retval.UnderlyingMembers.Add(new IconDirectoryMember(description, rd));
                }
            }

            typed = retval;
            return(true);
        }
Esempio n. 5
0
        public static ResIconDir FromResource(ResourceLang lang, Byte[] rawBytes)
        {
            Int32 sizeOfIconDir = Marshal.SizeOf(typeof(IconDirectory));
            Int32 sizeOfDirEntr = Marshal.SizeOf(typeof(ResIconDirectoryEntry));

            // the data in here is an ICONDIR structure

            IntPtr p = Marshal.AllocHGlobal(rawBytes.Length);

            Marshal.Copy(rawBytes, 0, p, rawBytes.Length);

            // this could be vastly simplified by correctly marshaling the member array of IconDirectory
            // but that's a can of worms, I'd rather not
            IconDirectory dir = (IconDirectory)Marshal.PtrToStructure(p, typeof(IconDirectory));

            Marshal.FreeHGlobal(p);

            if (dir.wType != 1 && dir.wType != 2)
            {
                throw new InvalidOperationException("Provided rawData is not an icon or cursor");
            }

            ResIconDirectoryEntry[] subImages = new ResIconDirectoryEntry[dir.wCount];

            for (int i = 0; i < dir.wCount; i++)
            {
                Int32 byteOffset = sizeOfIconDir + sizeOfDirEntr * i;

                p = Marshal.AllocHGlobal(sizeOfDirEntr);
                Marshal.Copy(rawBytes, byteOffset, p, sizeOfDirEntr);

                ResIconDirectoryEntry img = (ResIconDirectoryEntry)Marshal.PtrToStructure(p, typeof(ResIconDirectoryEntry));

                subImages[i] = img;
            }

            ResIconDir retval = new ResIconDir(dir.wType == 1, lang.LanguageId, lang.Name.Type.Source);

            // then we might be able to get the resourcedata for the subimages to include in the directory

            // find the Icon Image resource type
            ResourceType      imageType = null;
            Win32ResourceType desired   = dir.wType == 1 ? Win32ResourceType.IconImage : Win32ResourceType.CursorImage;

            foreach (ResourceType type in lang.Name.Type.Source.AllTypes)
            {
                if (type.Identifier.KnownType == desired)
                {
                    imageType = type;
                    break;
                }
            }

            if (imageType != null)
            {
                foreach (ResIconDirectoryEntry img in subImages)
                {
                    IconCursorImageResourceData rd = GetDataFromWid(imageType, lang, img.wId);

                    Size dimensions = new Size(img.bWidth == 0 ? 256 : img.bWidth, img.bHeight == 0 ? 256 : img.bHeight);
                    // cursors might have Height == 0, so it should copy the width rather than being set to 256

                    retval.Members.Add(new IconDirectoryMember(rd, dimensions, img.bColorCount, img.bReserved, img.wPlanes, img.wBitCount, img.dwBytesInRes));
                }
            }

            return(retval);
        }
Esempio n. 6
0
        public override ResourceData FromResource(ResourceLang lang, Byte[] data)
        {
            IconGroup group = new IconGroup(lang, data);

            return(new IconDirectoryResourceData(group, lang));
        }
Esempio n. 7
0
 internal IconDirectoryResourceData(IconGroup icon, ResourceLang lang) : base(lang, icon.GetResDirectoryData())
 {
     IconGroup = icon;
 }
Esempio n. 8
0
 public UnknownResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 9
0
 public override ResourceData FromResource(ResourceLang lang, byte[] data)
 {
     return(DialogResourceData.TryCreate(lang, data));
 }
Esempio n. 10
0
 protected DirectoryResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 11
0
 public override ResourceData FromResource(ResourceLang lang, byte[] data)
 {
     return(new UnknownResourceData(lang, data));
 }
Esempio n. 12
0
 internal RiffMediaResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 13
0
 public override ResourceData FromResource(ResourceLang lang, byte[] data)
 {
     return(new RiffMediaResourceData(lang, data));
 }
Esempio n. 14
0
 protected MediaResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 15
0
 private IconCursorImageResourceData(ResourceLang lang, byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 16
0
 public override ResourceData FromFileToUpdate(Stream stream, string extension, ResourceLang currentLang)
 {
     throw new NotSupportedException();
 }
Esempio n. 17
0
 private IconCursorImageResourceData(System.Drawing.Image image, ResourceLang lang, byte[] rawData) : base(lang, rawData)
 {
     _image = image;
 }
Esempio n. 18
0
 private DialogResourceData(ResourceLang lang, byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 19
0
        public override ResourceData FromFileToUpdate(Stream stream, String extension, ResourceLang currentLang)
        {
            if (!IsExtension(extension, "ICO"))
            {
                throw new ArgumentException("ico is the only supported extension");
            }

            IconDirectoryResourceData originalData = currentLang.Data as IconDirectoryResourceData;

            if (originalData == null)
            {
                throw new ResourceDataException("Unexpected original data subclass");
            }

            IconGroup newGroup = new IconGroup(stream);

            IconGroup canonicalGroup = originalData.IconGroup;

            canonicalGroup.Merge(newGroup, GetMergeOptions());

            return(new IconDirectoryResourceData(canonicalGroup, null));
        }
Esempio n. 20
0
 public override ResourceData FromResource(ResourceLang lang, Byte[] data)
 {
     return(new DummyResourceData(ResourceDataAction.None, data));
 }
Esempio n. 21
0
 private IconDirectoryResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 22
0
 private DummyResourceData(ResourceDataAction action, ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
     base.Action = action;
 }
Esempio n. 23
0
 protected ImageResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData)
 {
 }
Esempio n. 24
0
        protected override Boolean PatchFile(String fileName)
        {
            List <PatchResource> patchResources = new List <PatchResource>();

            foreach (PatchResourceSet set in _resourceSets)
            {
                if (EvaluatePatchResourceSet(set, fileName))
                {
                    // HACK: This just adds them together into a massive list. If the same name is mentioned it'll be overwritten several times
                    // fortunately it isnt' very expensive as only the last "final" one counts, but could do with filtering at this stage maybe?

                    patchResources.AddRange(set.Resources);
                }
                else
                {
                    Package.Log.Add(LogSeverity.Info, "Expression evaluation non-one: " + set.Condition.ExpressionString + ", did not process " + set.Resources.Count + " resources");
                }
            }

            if (patchResources.Count == 0)
            {
                Package.Log.Add(LogSeverity.Warning, "No resources to patch: " + fileName);
                return(false);
            }

            try {
                // for now, use lazy-load under all circumstances. In future analyse the Resources list to see if it's necessary or not
                // but the performance impact is minimal and it's the safest option, so keep it as it is
                using (ResourceSource source = ResourceSource.Open(fileName, false, ResourceSourceLoadMode.LazyLoadData)) {
                    List <String> tempFiles = new List <String>();

                    foreach (PatchResource res in patchResources)
                    {
                        if (res.Source.StartsWith("comp:", StringComparison.OrdinalIgnoreCase))
                        {
                            CompositedImage comp = new CompositedImage(res.Source, Package.RootDirectory);

                            DirectoryInfo packageTempDirectory = new DirectoryInfo(P.Combine(Package.RootDirectory.FullName, "Temp"));
                            if (!packageTempDirectory.Exists)
                            {
                                packageTempDirectory.Create();
                            }

                            // I think not using the *.bmp extension messes up Bitmap import
                            String tempFileName = PackageUtility.GetUnusedFileName(P.Combine(packageTempDirectory.FullName, P.GetFileName(Path) + res.Name) + ".bmp");

                            comp.Save(tempFileName, System.Drawing.Imaging.ImageFormat.Bmp);

                            res.File = tempFileName;
                            tempFiles.Add(tempFileName);
                        }
                        else
                        {
                            res.File = res.Source;
                        }

                        if (!File.Exists(res.File))
                        {
                            Package.Log.Add(LogSeverity.Error, "Data File not found: " + res.File);
                            continue;
                        }

                        ResourceTypeIdentifier typeId = ResourceTypeIdentifier.CreateFromString(res.Type, true);
                        ResourceIdentifier     nameId = ResourceIdentifier.CreateFromString(res.Name);
                        UInt16 langId = String.IsNullOrEmpty(res.Lang) ? UInt16.MaxValue : UInt16.Parse(res.Lang, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture);


                        if (langId == UInt16.MaxValue)                                // if the lang="" attribute was not specified

                        {
                            ResourceName name = source.GetName(typeId, nameId);

                            if (name == null)                              // if the specified name does not exist

                            {
                                if (res.Add)
                                {
                                    UInt16 sysLang = (UInt16)CultureInfo.InvariantCulture.LCID;

                                    ResourceData data = ResourceData.FromFileToAdd(res.File, sysLang, source);
                                    source.Add(typeId, nameId, sysLang, data);
                                }
                                else
                                {
                                    // Error

                                    String sourcePath = source.Name;

                                    Anolis.Core.Source.FileResourceSource frs = source as Anolis.Core.Source.FileResourceSource;
                                    if (frs != null)
                                    {
                                        sourcePath = frs.FileInfo.FullName;
                                    }

                                    Package.Log.Add(LogSeverity.Warning, "Resource name not found: " + sourcePath + '\\' + typeId.ToString() + '\\' + nameId.FriendlyName);
                                }
                            }
                            else
                            {
                                foreach (ResourceLang lang in name.Langs)
                                {
                                    ResourceData data = ResourceData.FromFileToUpdate(res.File, lang);
                                    lang.SwapData(data);
                                }
                            }
                        }
                        else                             // if the lang="" attribute was specified

                        {
                            ResourceLang lang = source.GetLang(typeId, nameId, langId);
                            if (lang == null)
                            {
                                ResourceData data = ResourceData.FromFileToAdd(res.File, langId, source);
                                source.Add(typeId, nameId, langId, data);
                            }
                            else
                            {
                                ResourceData data = ResourceData.FromFileToUpdate(res.File, lang);
                                lang.SwapData(data);
                            }
                        }
                    }                    //foreach

                    // note that Win32ResourceSource now recomptues the PE checksum by itself
                    source.CommitChanges();

                    foreach (String tempFile in tempFiles)
                    {
                        File.Delete(tempFile);
                    }

                    return(true);
                }                //using source
            } catch (AnolisException aex) {
                Package.Log.Add(LogSeverity.Error, "Patch Exception: " + aex.Message);

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                throw;
            }
        }
Esempio n. 25
0
 /// <summary>Returns null if unsuccessful. Wrap all exceptions in ResourceDataException.</summary>
 public abstract ResourceData FromResource(ResourceLang lang, byte[] data);
Esempio n. 26
0
 public IconCursorImageResourceData FromFileData(ResourceLang lang, byte[] data, bool isIcon)
 {
     return(IconCursorImageResourceData.TryCreate(isIcon, lang, data, out var rd) ? rd : null);
 }
Esempio n. 27
0
 public override ResourceData FromFileToUpdate(Stream stream, String extension, ResourceLang currentLang)
 {
     return(FromFile(stream));
 }
Esempio n. 28
0
 public override ResourceData FromFileToUpdate(Stream stream, string extension, ResourceLang currentLang)
 {
     LastErrorMessage = "Not supported";
     return(null);
 }
Esempio n. 29
0
 public override ResourceData FromResource(ResourceLang lang, byte[] data)
 {
     return(JpegImageResourceData.TryCreate(lang, data, out var rd) ? rd : null);
 }
Esempio n. 30
0
        // There is no need to override the SaveAs method since the bytes are the same

        private GifImageResourceData(Image image, ResourceLang lang, Byte[] rawData) : base(image, lang, rawData)
        {
        }