private void ReadPsd()
            {
                this.HasCapability = 0;
                try
                {
                    using (Stream stream = this._FileInfo.OpenRead())
                    {
                        PSD_HEADER psd_header = ByteArrayHelper.ReadStructureFromStream<PSD_HEADER>(stream);
                        if (Encoding.ASCII.GetString(psd_header.Signature) != "8BPS")
                        {
                            throw new InvalidDataException();
                        }
                        this.ImageSize = new Size(Swap(psd_header.Columns), Swap(psd_header.Rows));
                        this.BPP = Swap(psd_header.Depth) * Swap(psd_header.Channels);
                        switch (Swap(psd_header.Mode))
                        {
                            case 0:
                            case 2:
                                this.Space = ColorSpace.Indexed;
                                break;

                            case 1:
                                this.Space = ColorSpace.Grayscale;
                                break;

                            case 3:
                                this.Space = ColorSpace.RGB;
                                break;

                            case 4:
                                this.Space = ColorSpace.CMYK;
                                break;
                        }
                        this.HasCapability |= PsdCapability.BPP | PsdCapability.ColorSpace | PsdCapability.Size;
                        using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII))
                        {
                            int num4;
                            int num = Swap(reader.ReadInt32());
                            stream.Seek((long) num, SeekOrigin.Current);
                            for (num = Swap(reader.ReadInt32()); num > 0; num -= num4 + Math.Sign((int) (num4 % 2)))
                            {
                                string str = new string(reader.ReadChars(4));
                                num -= 4;
                                if (str != "8BIM")
                                {
                                    goto Label_02E9;
                                }
                                ushort num2 = Swap(reader.ReadUInt16());
                                num -= 2;
                                byte count = reader.ReadByte();
                                if (count > 0)
                                {
                                    reader.ReadChars(count);
                                }
                                else
                                {
                                    reader.ReadByte();
                                }
                                num -= Math.Max(2, 1 + count);
                                num4 = Swap(reader.ReadInt32());
                                int num5 = 0;
                                switch (num2)
                                {
                                    case 0x3ed:
                                    {
                                        RESOURCE_RESOLUTION structure = ByteArrayHelper.ReadStructureFromStream<RESOURCE_RESOLUTION>(stream);
                                        this.DPI = new Size(Swap(structure.hRes), Swap(structure.vRes));
                                        this.HasCapability |= PsdCapability.DPI;
                                        num5 = Marshal.SizeOf(structure);
                                        break;
                                    }
                                    case 0x40c:
                                    {
                                        RESOURCE_THUMBNAIL resource_thumbnail = ByteArrayHelper.ReadStructureFromStream<RESOURCE_THUMBNAIL>(stream);
                                        if (Swap(resource_thumbnail.nFormat) == 1)
                                        {
                                            this.ThumbnailStreamStart = stream.Position;
                                            this.ThumbnailStreamSize = Swap(resource_thumbnail.nCompressedSize);
                                            this.HasCapability |= PsdCapability.Thumbnail;
                                        }
                                        num5 = Marshal.SizeOf(resource_thumbnail);
                                        break;
                                    }
                                }
                                Debug.Assert(num5 <= num4);
                                stream.Seek((long) ((num4 + Math.Sign((int) (num4 % 2))) - num5), SeekOrigin.Current);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    PropertyProviderManager.ProviderTrace.TraceException(TraceEventType.Error, exception);
                }
            Label_02E9:
                if (!this.CheckCapability(PsdCapability.Thumbnail))
                {
                    this._FileInfo = null;
                }
            }
 public PsdPropertyBag(FileInfo fileInfo)
 {
     this._FileInfo = fileInfo;
     this.HasCapability = PsdCapability.Dirty | PsdCapability.Thumbnail | PsdCapability.DPI | PsdCapability.BPP | PsdCapability.ColorSpace | PsdCapability.Size;
 }
 private bool CheckCapability(PsdCapability capability)
 {
     return ((this.HasCapability & capability) == capability);
 }
 private Image ReadThumbnail()
 {
     try
     {
         using (Stream stream = this._FileInfo.OpenRead())
         {
             stream.Position = this.ThumbnailStreamStart;
             using (Stream stream2 = new SubStream(stream, (long) this.ThumbnailStreamSize))
             {
                 using (Image image = Image.FromStream(stream2))
                 {
                     return new Bitmap(image);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         PropertyProviderManager.ProviderTrace.TraceException(TraceEventType.Error, exception);
         this.HasCapability &= ~PsdCapability.Thumbnail;
         this._FileInfo = null;
         base.ResetAvailableSet();
     }
     return null;
 }