예제 #1
0
 public AudioCD()
 {
     drive = new CDDrive();
     char[] Drives = CDDrive.GetCDDriveLetters();
     foreach (char drive in Drives)
     {
         DriveList.Add(drive.ToString());
     }
 }
        protected override void Initialize()
        {
            base.Initialize();

            if (this.ConversionPreset == null)
            {
                throw new Exception("The conversion preset must be valid.");
            }

            // Retrieve and check drive letter.
            string pathDriveLetter = PathHelpers.GetPathDriveLetter(this.InputFilePath);

            if (pathDriveLetter.Length == 0)
            {
                this.ConversionFailed(Properties.Resources.ErrorFailToRetrieveInputPathDriveLetter);
                return;
            }

            char driveLetter = pathDriveLetter[0];

            this.diskDrive            = new Ripper.CDDrive();
            this.diskDrive.CDRemoved += new EventHandler(this.CdDriveCdRemoved);

            bool driveLetterFound = false;

            char[] driveLetters = Ripper.CDDrive.GetCDDriveLetters();
            for (int index = 0; index < driveLetters.Length; index++)
            {
                driveLetterFound |= driveLetters[index] == driveLetter;
            }

            if (!driveLetterFound)
            {
                Debug.Log($"Invalid drive letter {driveLetter}.");
                this.ConversionFailed(Properties.Resources.ErrorFailToRetrieveInputPathDriveLetter);
                return;
            }

            // Retrieve and track number.
            try
            {
                this.cdaTrackNumber = PathHelpers.GetCDATrackNumber(this.InputFilePath);
            }
            catch (Exception)
            {
                Debug.Log($"Input path: '{this.InputFilePath}'.");
                this.ConversionFailed(Properties.Resources.ErrorFailToRetrieveTrackNumber);
                return;
            }

            if (this.diskDrive.IsOpened)
            {
                this.ConversionFailed(Properties.Resources.ErrorFailToUseCDDriveOpen);
                return;
            }

            if (!this.diskDrive.Open(driveLetter))
            {
                this.ConversionFailed(string.Format(Properties.Resources.ErrorFailToReadCDDrive, driveLetter));
                return;
            }

            // Generate intermediate file path.
            string fileName = Path.GetFileName(this.OutputFilePath);
            string tempPath = Path.GetTempPath();

            this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".wav");

            // Sub conversion job (for compression).
            this.compressionConversionJob = ConversionJobFactory.Create(this.ConversionPreset, this.intermediateFilePath);
            this.compressionConversionJob.PrepareConversion(this.OutputFilePath);
            this.compressionThread = Helpers.InstantiateThread("CDACompressionThread", this.CompressAsync);
        }