/// <summary> /// Reads a HFE disk image from a given stream. /// </summary> /// <param name="image">Stream containing the HFE disk image.</param> /// <param name="isWriteable">Allow write operations to this disk.</param> /// <returns>A disk object.</returns> public static HfeDisk Open(Stream image, bool isWriteable) { if (image == null) { throw new ArgumentNullException("image"); } if (!image.CanRead) { throw new NotSupportedException("Disk image stream does not support reading"); } if (!image.CanSeek) { throw new NotSupportedException("Disk image stream does not support seeking"); } if (isWriteable && !image.CanWrite) { throw new NotSupportedException("Disk image stream does not support writing"); } var diskHeader = new HfeDiskHeader(image); if (diskHeader.FloppyInterface != HfeDiskHeader.FloppyInterfaceMode.GENERIC_SHUGART_DD) { throw new DiskImageFormatException(String.Format("Unsupported floppy interface mode {0}", diskHeader.FloppyInterface)); } if (diskHeader.TrackEncoding != HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM) { throw new DiskImageFormatException(String.Format("Unsupported track encoding mode {0}", diskHeader.TrackEncoding)); } if (diskHeader.TrackEncoding0 != HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM) { throw new DiskImageFormatException( String.Format("Unsupported track encoding mode {0} for track 0 head 0", diskHeader.TrackEncoding0)); } if (diskHeader.Sides > 1 && diskHeader.TrackEncoding1 != HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM) { throw new DiskImageFormatException( String.Format("Unsupported track encoding mode {0} for track 0 head 1", diskHeader.TrackEncoding1)); } var disk = new HfeDisk { DiskHeader = diskHeader, IsWriteable = isWriteable, diskImageStream = image }; disk.ReadTrackList(); return(disk); }
/// <summary> /// Reads a HFE disk image from a given stream. /// </summary> /// <param name="image">Stream containing the HFE disk image.</param> /// <param name="isWriteable">Allow write operations to this disk.</param> /// <returns>A disk object.</returns> public static HfeDisk Open(Stream image, bool isWriteable) { if (image == null) throw new ArgumentNullException("image"); if (!image.CanRead) throw new NotSupportedException("Disk image stream does not support reading"); if (!image.CanSeek) throw new NotSupportedException("Disk image stream does not support seeking"); if (isWriteable && !image.CanWrite) throw new NotSupportedException("Disk image stream does not support writing"); var diskHeader = new HfeDiskHeader(image); if (diskHeader.FloppyInterface != HfeDiskHeader.FloppyInterfaceMode.GENERIC_SHUGART_DD) throw new DiskImageFormatException(String.Format("Unsupported floppy interface mode {0}", diskHeader.FloppyInterface)); if (diskHeader.TrackEncoding != HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM) throw new DiskImageFormatException(String.Format("Unsupported track encoding mode {0}", diskHeader.TrackEncoding)); if (diskHeader.TrackEncoding0 != HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM) throw new DiskImageFormatException( String.Format("Unsupported track encoding mode {0} for track 0 head 0", diskHeader.TrackEncoding0)); if (diskHeader.Sides > 1 && diskHeader.TrackEncoding1 != HfeDiskHeader.TrackEncodingMode.ISOIBM_MFM) throw new DiskImageFormatException( String.Format("Unsupported track encoding mode {0} for track 0 head 1", diskHeader.TrackEncoding1)); var disk = new HfeDisk {DiskHeader = diskHeader, IsWriteable = isWriteable, diskImageStream = image}; disk.ReadTrackList(); return disk; }