diff --git a/pcsx2/CDVD/CDVDdiscReader.cpp b/pcsx2/CDVD/CDVDdiscReader.cpp index 0a34301ae4..0d57018855 100644 --- a/pcsx2/CDVD/CDVDdiscReader.cpp +++ b/pcsx2/CDVD/CDVDdiscReader.cpp @@ -189,6 +189,8 @@ s32 CALLBACK DISCopen(const char* pTitle) std::string drive = g_Conf->Folders.RunDisc.GetPath().ToStdString(); #endif GetValidDrive(drive); + if (drive.empty()) + return -1; // open device file try diff --git a/pcsx2/CDVD/Windows/DriveUtility.cpp b/pcsx2/CDVD/Windows/DriveUtility.cpp index a856324e49..c75c2a3245 100644 --- a/pcsx2/CDVD/Windows/DriveUtility.cpp +++ b/pcsx2/CDVD/Windows/DriveUtility.cpp @@ -41,23 +41,19 @@ void GetValidDrive(std::wstring& drive) auto drives = GetOpticalDriveList(); if (drives.empty()) { - drive = {}; - } - else - { - drive = drives.front(); + drive.clear(); + return; } + drive = drives.front(); } - else - { - int size = WideCharToMultiByte(CP_UTF8, 0, drive.c_str(), -1, nullptr, 0, nullptr, nullptr); - std::vector converted_string(size); - WideCharToMultiByte(CP_UTF8, 0, drive.c_str(), -1, converted_string.data(), converted_string.size(), nullptr, nullptr); - printf(" * CDVD: Opening drive '%s'...\n", converted_string.data()); - // The drive string has the form "X:\", but to open the drive, the string - // has to be in the form "\\.\X:" - drive.pop_back(); - drive.insert(0, L"\\\\.\\"); - } -} \ No newline at end of file + int size = WideCharToMultiByte(CP_UTF8, 0, drive.c_str(), -1, nullptr, 0, nullptr, nullptr); + std::vector converted_string(size); + WideCharToMultiByte(CP_UTF8, 0, drive.c_str(), -1, converted_string.data(), converted_string.size(), nullptr, nullptr); + printf(" * CDVD: Opening drive '%s'...\n", converted_string.data()); + + // The drive string has the form "X:\", but to open the drive, the string + // has to be in the form "\\.\X:" + drive.pop_back(); + drive.insert(0, L"\\\\.\\"); +}