From a8741693f538b1ad2544cbb2d0ec67ff51482703 Mon Sep 17 00:00:00 2001 From: Tichau Date: Thu, 14 Apr 2016 19:19:48 +0200 Subject: [PATCH] Fixed: Avoid simultaneous read on cd drive --- .../ConversionJobs/ConversionFlags.cs | 2 +- .../ConversionJobs/ConversionJob.cs | 12 ++++++++-- .../ConversionJob_ExtractCDA.cs | 9 +------- Application/FileConverter/PathHelpers.cs | 22 +++++++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionFlags.cs b/Application/FileConverter/ConversionJobs/ConversionFlags.cs index a78abcd..7e81df3 100644 --- a/Application/FileConverter/ConversionJobs/ConversionFlags.cs +++ b/Application/FileConverter/ConversionJobs/ConversionFlags.cs @@ -9,6 +9,6 @@ namespace FileConverter.ConversionJobs { None = 0x00, - CdaExtraction = 0x01, + CdDriveExtraction = 0x01, } } \ No newline at end of file diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 6f24b55..0ec5193 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -141,7 +141,7 @@ namespace FileConverter.ConversionJobs public virtual bool CanStartConversion(ConversionFlags conversionFlags) { - return true; + return (conversionFlags & ConversionFlags.CdDriveExtraction) == 0; } public void PrepareConversion(string inputFilePath, string outputFilePath = null) @@ -225,6 +225,12 @@ namespace FileConverter.ConversionJobs return; } + // Check if the input file is located on a cd drive. + if (PathHelpers.IsOnCDDrive(this.InputFilePath)) + { + this.StateFlags = ConversionFlags.CdDriveExtraction; + } + this.Initialize(); if (this.State == ConversionState.Unknown) @@ -252,7 +258,7 @@ namespace FileConverter.ConversionJobs Debug.Log("Convert file {0} to {1}.", this.InputFilePath, this.OutputFilePath); this.State = ConversionState.InProgress; - + try { this.Convert(); @@ -262,6 +268,8 @@ namespace FileConverter.ConversionJobs this.ConversionFailed(exception.Message); } + this.StateFlags = ConversionFlags.None; + if (this.State == ConversionState.Failed) { this.OnConversionFailed(); diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs b/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs index be223b9..344ae35 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs @@ -35,12 +35,7 @@ namespace FileConverter.ConversionJobs return InputPostConversionAction.None; } } - - public override bool CanStartConversion(ConversionFlags conversionFlags) - { - return (conversionFlags & ConversionFlags.CdaExtraction) == 0; - } - + protected override void Initialize() { base.Initialize(); @@ -108,8 +103,6 @@ namespace FileConverter.ConversionJobs this.compressionConversionJob = ConversionJobFactory.Create(this.ConversionPreset, this.intermediateFilePath); this.compressionConversionJob.PrepareConversion(this.intermediateFilePath, this.OutputFilePath); this.compressionThread = new Thread(this.CompressAsync); - - this.StateFlags = ConversionFlags.CdaExtraction; } protected override void Convert() diff --git a/Application/FileConverter/PathHelpers.cs b/Application/FileConverter/PathHelpers.cs index 846806d..3376e36 100644 --- a/Application/FileConverter/PathHelpers.cs +++ b/Application/FileConverter/PathHelpers.cs @@ -23,6 +23,28 @@ namespace FileConverter return PathHelpers.driveLetterRegex.Match(path).Groups[0].Value; } + public static bool IsOnCDDrive(string path) + { + string pathDriveLetter = GetPathDriveLetter(path); + if (string.IsNullOrEmpty(pathDriveLetter)) + { + return false; + } + + char driveLetter = pathDriveLetter[0]; + + char[] driveLetters = Ripper.CDDrive.GetCDDriveLetters(); + for (int index = 0; index < driveLetters.Length; index++) + { + if (driveLetters[index] == driveLetter) + { + return true; + } + } + + return false; + } + public static int GetCDATrackNumber(string path) { Match match = PathHelpers.cdaTrackNumberRegex.Match(path);