//[Test] //public void FindSmallestBinaryWithResources() //{ // FindSmallestBinaryWithResources( // Environment.SystemDirectory, // "*.exe", // Kernel32.ResourceTypes.RT_MENU); //} private void FindSmallestBinaryWithResources( string path, string ext, Kernel32.ResourceTypes rt) { long smallest = 0; string[] files = Directory.GetFiles(path, ext); foreach (string filename in files) { try { using (ResourceInfo ri = new ResourceInfo()) { ri.Load(filename); if (!ri.Resources.ContainsKey(new ResourceId(rt))) { continue; } FileInfo fi = new FileInfo(filename); //if (fi.Length < smallest || smallest == 0) //{ Console.WriteLine("{0} {1}", filename, new FileInfo(filename).Length); smallest = fi.Length; // } break; } } catch { } } }
/// <summary> /// A collection of resources. /// </summary> /// <param name="type">Resource type.</param> /// <returns>A collection of resources of a given type.</returns> internal List <Resource> this[Kernel32.ResourceTypes type] { get { return(_resources[new ResourceId(type)]); } set { _resources[new ResourceId(type)] = value; } }
/// <summary> /// A new hardware-independent icon resource. /// </summary> public DirectoryResource(Kernel32.ResourceTypes resourceType) : base(IntPtr.Zero, IntPtr.Zero, new ResourceId(resourceType), new ResourceId(1), ResourceUtil.NEUTRALLANGID, Marshal.SizeOf(typeof(Kernel32.GRPICONDIR))) { switch (resourceType) { //case Kernel32.ResourceTypes.RT_GROUP_CURSOR: // _header.wType = 2; // break; case Kernel32.ResourceTypes.RT_GROUP_ICON: _header.wType = 1; break; default: throw new NotSupportedException(); } }
public override void CopyResources(string src, string dest) { ResourceInfo srcInfo = new ResourceInfo(); ResourceInfo dstInfo = new ResourceInfo(); srcInfo.Load(src); dstInfo.Load(dest); Kernel32.ResourceTypes resType = 0; switch (ResourceType) { case ResourceType.Icon: resType = Kernel32.ResourceTypes.RT_GROUP_ICON; break; case ResourceType.Bitmap: resType = Kernel32.ResourceTypes.RT_BITMAP; break; default: Debug.Fail("Unknown resource type"); break; } List <Resource> resourcesToReplace = new List <Resource>(); foreach (Resource res in srcInfo[resType]) { if (Ids == null || Ids.Contains(res.Name.Name)) { // Find matching resource in destination file Resource dstRes = dstInfo[resType].Single(dr => dr.Name.Equals(res.Name)); res.LoadFrom(src); dstRes.LoadFrom(dest); res.Language = dstRes.Language; // Do some checks if (ResourceType == VSIconSwitcher.ResourceType.Icon) { IconDirectoryResource srcIconDirectory = res as IconDirectoryResource; IconDirectoryResource dstIconDirectory = dstRes as IconDirectoryResource; //Debug.Assert(srcIconDirectory.Icons.Count == dstIconDirectory.Icons.Count, "Source/destination icon directory count should match."); } else if (ResourceType == VSIconSwitcher.ResourceType.Bitmap) { BitmapResource srcBitmap = res as BitmapResource; BitmapResource dstBitmap = dstRes as BitmapResource; Debug.Assert(srcBitmap.Bitmap.Header.biHeight == dstBitmap.Bitmap.Header.biHeight, "Source/destination bitmap height dimension should match."); Debug.Assert(srcBitmap.Bitmap.Header.biWidth == dstBitmap.Bitmap.Header.biWidth, "Source/destination bitmap height dimension should match."); } resourcesToReplace.Add(res); } } dstInfo.Unload(); foreach (Resource res in resourcesToReplace) { res.SaveTo(dest); } srcInfo.Unload(); }
/// <summary> /// A well-known resource-type identifier. /// </summary> /// <param name="value">A well known resource type.</param> internal ResourceId(Kernel32.ResourceTypes value) { Id = (IntPtr)value; }
/// <summary> /// A well-known resource-type identifier. /// </summary> /// <param name="value">A well known resource type.</param> public ResourceId(Kernel32.ResourceTypes value) { Id = (IntPtr)value; }