protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features) { using (var fd = NativeApi.OpenDevice(device)) { if (fd.IsInvalid) { throw new IOException($"Failed to open '{device}'.", new UnixException()); } // Read the TOC itself NativeApi.ReadTOC(fd, out var first, out var last, out var rawtracks, this.AddressesAreNative); var tracks = new Track[rawtracks.Length]; var i = 0; if (first > 0) { for (var trackno = first; trackno <= last; ++trackno, ++i) // Add the regular tracks. { if (rawtracks[i].TrackNumber != trackno) { throw new InvalidDataException($"Internal logic error; first track is {first}, but entry at index {i} claims to be track {rawtracks[i].TrackNumber} instead of {trackno}."); } var isrc = ((features & DiscReadFeature.TrackIsrc) != 0) ? NativeApi.GetTrackIsrc(fd, trackno) : null; tracks[trackno] = new Track(rawtracks[i].Address, rawtracks[i].ControlAndADR.Control, isrc); } } // Next entry should be the lead-out (track number 0xAA) if (rawtracks[i].TrackNumber != 0xAA) { throw new InvalidDataException($"Internal logic error; track data ends with a record that reports track number {rawtracks[i].TrackNumber} instead of 0xAA (lead-out)."); } tracks[0] = new Track(rawtracks[i].Address, rawtracks[i].ControlAndADR.Control, null); var mcn = ((features & DiscReadFeature.MediaCatalogNumber) != 0) ? NativeApi.GetMediaCatalogNumber(fd) : null; // TODO: Find out how to get CD-TEXT data. return(new TableOfContents(device, first, last, tracks, mcn, null)); } }
TableOfContents IPlatform.ReadTableOfContents(string device, DiscReadFeature features) { if (string.IsNullOrWhiteSpace(device)) // Map null/blanks to the default device { device = this.DefaultDevice; } if (device == null) // But we do need a device at this point { throw new NotSupportedException("No cd-rom device found."); } // Mask off unsupported features features &= this._features; return(this.ReadTableOfContents(device, features)); }
protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features) { using (var fd = NativeApi.OpenDevice(device)) { if (fd.IsInvalid) { throw new IOException($"Failed to open '{device}'.", new UnixException()); } byte first = 0; byte last = 0; Track[] tracks = null; { // Read the TOC itself NativeApi.GetTableOfContents(fd, out MMC.TOCDescriptor rawtoc); first = rawtoc.FirstTrack; last = rawtoc.LastTrack; tracks = new Track[last + 1]; var i = 0; for (var trackno = rawtoc.FirstTrack; trackno <= rawtoc.LastTrack; ++trackno, ++i) // Add the regular tracks. { if (rawtoc.Tracks[i].TrackNumber != trackno) { throw new InvalidDataException($"Internal logic error; first track is {rawtoc.FirstTrack}, but entry at index {i} claims to be track {rawtoc.Tracks[i].TrackNumber} instead of {trackno}."); } var isrc = ((features & DiscReadFeature.TrackIsrc) != 0) ? NativeApi.GetTrackIsrc(fd, trackno) : null; tracks[trackno] = new Track(rawtoc.Tracks[i].Address, rawtoc.Tracks[i].ControlAndADR.Control, isrc); } // Next entry should be the lead-out (track number 0xAA) if (rawtoc.Tracks[i].TrackNumber != 0xAA) { throw new InvalidDataException($"Internal logic error; track data ends with a record that reports track number {rawtoc.Tracks[i].TrackNumber} instead of 0xAA (lead-out)."); } tracks[0] = new Track(rawtoc.Tracks[i].Address, rawtoc.Tracks[i].ControlAndADR.Control, null); } var mcn = ((features & DiscReadFeature.MediaCatalogNumber) != 0) ? NativeApi.GetMediaCatalogNumber(fd) : null; RedBook.CDTextGroup?cdtg = null; if ((features & DiscReadFeature.CdText) != 0) { NativeApi.GetCdTextInfo(fd, out MMC.CDTextDescriptor cdtext); if (cdtext.Data.Packs != null) { cdtg = cdtext.Data; } } return(new TableOfContents(device, first, last, tracks, mcn, cdtg)); } }
protected Unix(DiscReadFeature features = DiscReadFeature.TableOfContents) : base(features) { }
protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features) { throw new NotImplementedException($"CD device access has not been implemented for this platform ({this.GetType().Name} {Environment.OSVersion})."); }
/// <summary>Reads the table of contents for the current disc in the specified device, getting the requested information.</summary> /// <param name="device">The name of the device to read from; null to read from <see cref="DefaultDevice"/>.</param> /// <param name="features">The features to use (if supported). Note that the table of contents will always be read.</param> public static TableOfContents ReadDisc(string device, DiscReadFeature features = DiscReadFeature.All) { return(TableOfContents.Platform.ReadTableOfContents(device, features)); }
/// <summary>Determines whether or not the specified feature is supported for use with <see cref="ReadDisc"/>.</summary> /// <param name="feature">The (single) feature to test.</param> /// <returns>true if the feature is supported; false otherwise.</returns> public static bool HasReadFeature(DiscReadFeature feature) => TableOfContents.Platform.HasFeature(feature);
protected override TableOfContents ReadTableOfContents(string device, DiscReadFeature features) { throw new PlatformNotSupportedException($"CD device access is not supported on this platform ({Environment.OSVersion})."); }
protected abstract TableOfContents ReadTableOfContents(string device, DiscReadFeature features);
public bool HasFeature(DiscReadFeature feature) => (feature & this._features) != 0;
protected Platform(DiscReadFeature features) { this._features = features; }