示例#1
0
        /// <summary>
        /// Initializes a new instance of the DiscImageFile class.
        /// </summary>
        /// <param name="stream">The stream to interpret</param>
        /// <param name="ownsStream">Indicates if the new instance should control the lifetime of the stream.</param>
        /// <param name="format">The disc image format</param>
        public DiscImageFile(Stream stream, Ownership ownsStream, OpticalFormat format)
        {
            if (ownsStream == Ownership.Dispose)
            {
                _toDispose = stream;
            }

            if (format == OpticalFormat.None)
            {
                if ((stream.Length % Mode1SectorSize) == 0 && (stream.Length % Mode2SectorSize) != 0)
                {
                    _format = OpticalFormat.Mode1;
                }
                else if ((stream.Length % Mode1SectorSize) != 0 && (stream.Length % Mode2SectorSize) == 0)
                {
                    _format = OpticalFormat.Mode2;
                }
                else
                {
                    throw new IOException("Unable to detect optical disk format");
                }
            }
            else
            {
                _format = format;
            }

            _content = stream as SparseStream;
            if (_content == null)
            {
                _content = SparseStream.FromStream(stream, Ownership.None);
            }

            if (_format == OpticalFormat.Mode2)
            {
                Mode2Buffer converter = new Mode2Buffer(new StreamBuffer(_content, Ownership.None));
                _content = new BufferStream(converter, FileAccess.Read);
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the DiscImageFile class.
        /// </summary>
        /// <param name="stream">The stream to interpret</param>
        /// <param name="ownsStream">Indicates if the new instance should control the lifetime of the stream.</param>
        /// <param name="format">The disc image format</param>
        public DiscImageFile(Stream stream, Ownership ownsStream, OpticalFormat format)
        {
            if (ownsStream == Ownership.Dispose)
            {
                _toDispose = stream;
            }

            if (format == OpticalFormat.None)
            {
                if ((stream.Length % Mode1SectorSize) == 0 && (stream.Length % Mode2SectorSize) != 0)
                {
                    _format = OpticalFormat.Mode1;
                }
                else if ((stream.Length % Mode1SectorSize) != 0 && (stream.Length % Mode2SectorSize) == 0)
                {
                    _format = OpticalFormat.Mode2;
                }
                else
                {
                    throw new IOException("Unable to detect optical disk format");
                }
            }
            else
            {
                _format = format;
            }

            _content = stream as SparseStream;
            if (_content == null)
            {
                _content = SparseStream.FromStream(stream, Ownership.None);
            }

            if (_format == OpticalFormat.Mode2)
            {
                Mode2Buffer converter = new Mode2Buffer(new StreamBuffer(_content, Ownership.None));
                _content = new BufferStream(converter, FileAccess.Read);
            }
        }