Detecting available CDROM drives

Detecting CDROM drive device information
This commit is contained in:
chudov
2008-11-30 01:43:17 +00:00
parent 524097b059
commit 2db66848bf
5 changed files with 46 additions and 6 deletions

View File

@@ -155,6 +155,16 @@ namespace Bwg.Scsi
m_devices.Add(newdev);
return newdev;
}
/// <summary>
/// This method returns or creates a unique device info structure based on the
/// drive letter for a given drive.
/// </summary>
/// <param name="letter">the drive letter for the drive</param>
/// <returns>the single DeviceInfo object that represents this drive</returns>
public static DeviceInfo CreateDevice(string letter)
{
return CreateDevice(DeviceManager.GetNtDeviceNameForDrive(letter),letter);
}
#endregion
}
}

View File

@@ -168,7 +168,12 @@ namespace Bwg.Scsi
#region private methods
private static string GetNtDeviceNameForDrive(string name)
/// <summary>
/// Return the NT name for a drive given its drive letter
/// </summary>
/// <param name="name">the drive letter</param>
/// <returns>the NT name</returns>
public static string GetNtDeviceNameForDrive(string name)
{
string result;
const int buflen = 512;

View File

@@ -25,6 +25,7 @@ using System.Text;
using System.Collections.Generic;
using CUETools.Ripper.SCSI;
using CUETools.Codecs;
using CUETools.CDImage;
using CUETools.AccurateRip;
namespace CUERipper
@@ -50,12 +51,19 @@ namespace CUERipper
return;
}
string destFile = args[0];
char[] drives = CDDriveReader.DrivesAvailable();
if (drives.Length < 1)
{
Console.WriteLine("No CD drives found.");
return;
}
char driveLetter = drives[0];
#if !DEBUG
try
#endif
{
CDDriveReader audioSource = new CDDriveReader();
audioSource.Open('D');
audioSource.Open(driveLetter);
audioSource.DriveOffset = 48;
bool toStdout = false;
@@ -67,7 +75,8 @@ namespace CUERipper
arVerify.ContactAccurateRip(ArId);
Console.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.SampleRate, audioSource.ChannelCount, audioSource.BitsPerSample, TimeSpan.FromSeconds(audioSource.Length * 1.0 / audioSource.SampleRate));
Console.WriteLine("Drive : {0}", audioSource.Path);
Console.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.SampleRate, audioSource.ChannelCount, audioSource.BitsPerSample, CDImageLayout.TimeToString((uint)(audioSource.Length / 588)));
Console.WriteLine("Filename : {0}", destFile);
Console.WriteLine("AR status : {0}", arVerify.ARStatus == null ? "ok" : arVerify.ARStatus);

View File

@@ -24,6 +24,7 @@ using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.IO;
using Bwg.Scsi;
using Bwg.Logging;
using CUETools.CDImage;
@@ -46,8 +47,9 @@ namespace CUETools.Ripper.SCSI
const int CB_AUDIO = 588 * 4 + 16;
const int NSECTORS = 32;
int _currentTrack = -1, _currentIndex = -1, _currentTrackActualStart = -1;
Logger m_logger = null;
Logger m_logger;
CDImageLayout _toc;
DeviceInfo m_info;
public CDImageLayout TOC
{
@@ -59,17 +61,23 @@ namespace CUETools.Ripper.SCSI
public CDDriveReader()
{
m_logger = new Logger();
}
public bool Open(char Drive)
{
Device.CommandStatus st;
m_info = DeviceInfo.CreateDevice(Drive + ":");
// Open the base device
m_device = new Device(m_logger);
if (!m_device.Open(Drive))
throw new Exception("SCSI error");
if (!m_info.ExtractInfo(m_device))
throw new Exception("SCSI error");
//// Open/Initialize the driver
//Drive m_drive = new Drive(dev);
//DiskOperationError status = m_drive.Initialize();
@@ -370,7 +378,7 @@ namespace CUETools.Ripper.SCSI
{
get
{
return m_device.Name;
return m_info.LongDesc;
}
}
@@ -413,5 +421,14 @@ namespace CUETools.Ripper.SCSI
{
return (hex >> 4) * 10 + (hex & 15);
}
public static char[] DrivesAvailable()
{
List<char> result = new List<char>();
foreach (DriveInfo info in DriveInfo.GetDrives())
if (info.DriveType == DriveType.CDRom)
result.Add(info.Name[0]);
return result.ToArray();
}
}
}

View File

@@ -816,7 +816,6 @@ namespace CUETools.Processor
if (_accurateRipId == null && _dataTrackLength == null && _eacLog != null)
{
sr = new StringReader(_eacLog);
uint lastAudioSector = 0;
bool isEACLog = false;
CDImageLayout tocFromLog = new CDImageLayout();
while ((lineStr = sr.ReadLine()) != null)