public override VirtualDisk OpenDisk(FileLocator locator, string path, FileAccess access) { OpticalFormat format = path.EndsWith(".bin", StringComparison.OrdinalIgnoreCase) ? OpticalFormat.Mode2 : OpticalFormat.Mode1; FileShare share = access == FileAccess.Read ? FileShare.Read : FileShare.None; return(new Disc(locator.Open(path, FileMode.Open, access, share), Ownership.Dispose, format)); }
/// <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); } }
/// <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); } }
/// <summary> /// Initializes a new instance of the Disc class. /// </summary> /// <param name="stream">The stream to read</param> /// <param name="ownsStream">Indicates if the new instance should control the lifetime of the stream.</param> /// <param name="format">The disk image format</param> public Disc(Stream stream, Ownership ownsStream, OpticalFormat format) { _file = new DiscImageFile(stream, ownsStream, format); }
/// <summary> /// Initializes a new instance of the Disc class. /// </summary> /// <param name="stream">The stream to read</param> /// <param name="ownsStream">Indicates if the new instance should control the lifetime of the stream.</param> /// <param name="format">The disk image format</param> public Disc(Stream stream, Ownership ownsStream, OpticalFormat format) { _file = new DiscImageFile(stream, ownsStream, format); }