private MenuResourceData(ResourceLang lang, byte[] rawData) : base(lang, rawData) { }
public abstract ResourceData FromFileToUpdate(Stream stream, string extension, ResourceLang currentLang);
private TiffImageResourceData(Image image, ResourceLang lang, Byte[] rawData) : base(lang, rawData) { _image = image; }
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); }
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); }
public override ResourceData FromResource(ResourceLang lang, Byte[] data) { IconGroup group = new IconGroup(lang, data); return(new IconDirectoryResourceData(group, lang)); }
internal IconDirectoryResourceData(IconGroup icon, ResourceLang lang) : base(lang, icon.GetResDirectoryData()) { IconGroup = icon; }
public UnknownResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData) { }
public override ResourceData FromResource(ResourceLang lang, byte[] data) { return(DialogResourceData.TryCreate(lang, data)); }
protected DirectoryResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData) { }
public override ResourceData FromResource(ResourceLang lang, byte[] data) { return(new UnknownResourceData(lang, data)); }
internal RiffMediaResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData) { }
public override ResourceData FromResource(ResourceLang lang, byte[] data) { return(new RiffMediaResourceData(lang, data)); }
protected MediaResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData) { }
private IconCursorImageResourceData(ResourceLang lang, byte[] rawData) : base(lang, rawData) { }
public override ResourceData FromFileToUpdate(Stream stream, string extension, ResourceLang currentLang) { throw new NotSupportedException(); }
private IconCursorImageResourceData(System.Drawing.Image image, ResourceLang lang, byte[] rawData) : base(lang, rawData) { _image = image; }
private DialogResourceData(ResourceLang lang, byte[] rawData) : base(lang, rawData) { }
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)); }
public override ResourceData FromResource(ResourceLang lang, Byte[] data) { return(new DummyResourceData(ResourceDataAction.None, data)); }
private IconDirectoryResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData) { }
private DummyResourceData(ResourceDataAction action, ResourceLang lang, Byte[] rawData) : base(lang, rawData) { base.Action = action; }
protected ImageResourceData(ResourceLang lang, Byte[] rawData) : base(lang, rawData) { }
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; } }
/// <summary>Returns null if unsuccessful. Wrap all exceptions in ResourceDataException.</summary> public abstract ResourceData FromResource(ResourceLang lang, byte[] data);
public IconCursorImageResourceData FromFileData(ResourceLang lang, byte[] data, bool isIcon) { return(IconCursorImageResourceData.TryCreate(isIcon, lang, data, out var rd) ? rd : null); }
public override ResourceData FromFileToUpdate(Stream stream, String extension, ResourceLang currentLang) { return(FromFile(stream)); }
public override ResourceData FromFileToUpdate(Stream stream, string extension, ResourceLang currentLang) { LastErrorMessage = "Not supported"; return(null); }
public override ResourceData FromResource(ResourceLang lang, byte[] data) { return(JpegImageResourceData.TryCreate(lang, data, out var rd) ? rd : null); }
// 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) { }