private static Image ExtractIcon(object iconHandler, ClassIconLocation iconLocation, bool addToCache, ref Size size)
 {
     Image image;
     if (!GetIconFromCache(iconLocation, ref size, out image))
     {
         IntPtr ptr;
         IntPtr ptr2;
         uint num;
         int num2;
         IntPtr ptr3;
         IntPtr ptr4;
         if (size.Height >= 0x20)
         {
             num = (uint) (size.Height | 0x100000);
         }
         else
         {
             num = (uint) (0x20 | (size.Height << 0x10));
         }
         IExtractIconW nw = iconHandler as IExtractIconW;
         if (nw != null)
         {
             num2 = nw.Extract(iconLocation.IconFileName, iconLocation.IconIndex, out ptr, out ptr2, num);
         }
         else
         {
             num2 = ((IExtractIconA) iconHandler).Extract(iconLocation.IconFileName, iconLocation.IconIndex, out ptr, out ptr2, num);
         }
         if (num2 != 0)
         {
             return null;
         }
         if (size.Height >= 0x20)
         {
             ptr3 = ptr;
             ptr4 = ptr2;
         }
         else
         {
             ptr3 = ptr2;
             ptr4 = ptr;
         }
         if (ptr3 != IntPtr.Zero)
         {
             image = ImageHelper.IconToBitmap(ptr3);
             if (addToCache)
             {
                 AddIconToCache(iconLocation, ref size, image);
             }
             Windows.DestroyIcon(ptr3);
         }
         if (!(ptr4 != IntPtr.Zero))
         {
             return image;
         }
         if (addToCache)
         {
             Image icon = ImageHelper.IconToBitmap(ptr4);
             if ((icon != null) && IsIconSizeInCache(iconLocation, icon.Size))
             {
                 icon.Dispose();
                 icon = null;
             }
             if (icon != null)
             {
                 Size size2 = icon.Size;
                 AddIconToCache(iconLocation, ref size2, icon);
             }
         }
         Windows.DestroyIcon(ptr4);
     }
     return image;
 }
        public static void LoadIconCache(Stream cacheStream)
        {
            BinaryReader reader = new BinaryReader(cacheStream, Encoding.UTF8);
            if (new string(reader.ReadChars(4)) != "IMCH")
            {
                throw new InvalidDataException();
            }
            if (reader.ReadInt32() != 1)
            {
                throw new InvalidDataException("Unknown icon cache format version.");
            }
            lock (LocationIconCache)
            {
                LocationIconCache.Clear();
                int num = reader.ReadInt32();
                for (int i = 0; i < num; i++)
                {
                    IconLocation location;
                    switch (reader.ReadByte())
                    {
                        case 0:
                            location = new IconLocation(reader.ReadString(), reader.ReadInt32());
                            break;

                        case 1:
                        {
                            Guid classId = new Guid(reader.ReadBytes(0x10));
                            location = new ClassIconLocation(ref classId, reader.ReadString(), reader.ReadInt32());
                            break;
                        }
                        default:
                            throw new InvalidDataException("Unknown icon location format.");
                    }
                    IDictionary<Size, Image> dictionary = IconCollection.Create();
                    int num4 = reader.ReadInt32();
                    for (int j = 0; j < num4; j++)
                    {
                        Size key = new Size(reader.ReadInt32(), reader.ReadInt32());
                        int num6 = reader.ReadInt32();
                        long position = cacheStream.Position;
                        using (Image image = Image.FromStream(new SubStream(cacheStream, FileAccess.Read, (long) num6)))
                        {
                            dictionary.Add(key, new Bitmap(image));
                        }
                        cacheStream.Position = position + num6;
                    }
                    LocationIconCache.Add(location, (dictionary.Count == 0) ? null : dictionary);
                }
            }
        }