Skip to content

Commit

Permalink
BACKENDS: Add support for opening a CD on Windows by drive
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops authored and Johannes Schickel committed Mar 13, 2016
1 parent 442f91c commit 4a6c7b5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions backends/audiocd/win32/win32-audiocd.cpp
Expand Up @@ -267,6 +267,9 @@ class Win32AudioCDManager : public DefaultAudioCDManager {
void closeCD();
void playCD(int track, int numLoops, int startFrame, int duration);

protected:
bool openCD(const Common::String &drive);

private:
bool loadTOC();

Expand Down Expand Up @@ -314,6 +317,37 @@ bool Win32AudioCDManager::openCD(int drive) {
return false;
}

bool Win32AudioCDManager::openCD(const Common::String &drive) {
// Just some bounds checking
if (drive.empty() || drive.size() > 3)
return false;

if (!Common::isAlpha(drive[0]) || drive[1] != ':')
return false;

if (drive[2] != 0 && drive[2] != '\\')
return false;

DriveList drives;
if (!tryAddDrive(toupper(drive[0]), drives))
return false;

// Construct the drive path and try to open it
Common::String drivePath = Common::String::format("\\\\.\\%c:", drives[0]);
_driveHandle = CreateFileA(drivePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (_driveHandle == INVALID_HANDLE_VALUE) {
warning("Failed to open drive %c:\\, error %d", drives[0], (int)GetLastError());
return false;
}

if (!loadTOC()) {
closeCD();
return false;
}

return true;
}

void Win32AudioCDManager::closeCD() {
// Stop any previous track
stop();
Expand Down

0 comments on commit 4a6c7b5

Please sign in to comment.