From f79f85480b2141f6ea444054dbd63a340f2c0cc1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 19 Aug 2021 19:05:04 +1000 Subject: [PATCH] CDVD: Use ANSI variants on Windows for disc access The drive path is not going to contain unicode characters. --- pcsx2/CDVD/CDVDdiscReader.cpp | 7 +------ pcsx2/CDVD/CDVDdiscReader.h | 11 +++-------- pcsx2/CDVD/Windows/DriveUtility.cpp | 23 ++++++++++------------- pcsx2/CDVD/Windows/IOCtlSrc.cpp | 6 +++--- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/pcsx2/CDVD/CDVDdiscReader.cpp b/pcsx2/CDVD/CDVDdiscReader.cpp index d3a54e6c0b..5c7493968d 100644 --- a/pcsx2/CDVD/CDVDdiscReader.cpp +++ b/pcsx2/CDVD/CDVDdiscReader.cpp @@ -15,7 +15,6 @@ #include "PrecompiledHeader.h" #include "CDVDdiscReader.h" -#include "Config.h" #include @@ -182,11 +181,7 @@ void StopKeepAliveThread() s32 CALLBACK DISCopen(const char* pTitle) { -#if defined(_WIN32) - std::wstring drive = EmuConfig.CurrentDiscDrive.ToStdWstring(); -#else - std::string drive = EmuConfig.CurrentDiscDrive.ToStdString(); -#endif + std::string drive(pTitle); GetValidDrive(drive); if (drive.empty()) return -1; diff --git a/pcsx2/CDVD/CDVDdiscReader.h b/pcsx2/CDVD/CDVDdiscReader.h index 2bb3d9f9c5..c53771e336 100644 --- a/pcsx2/CDVD/CDVDdiscReader.h +++ b/pcsx2/CDVD/CDVDdiscReader.h @@ -52,13 +52,13 @@ class IOCtlSrc IOCtlSrc(const IOCtlSrc&) = delete; IOCtlSrc& operator=(const IOCtlSrc&) = delete; + std::string m_filename; + #if defined(_WIN32) HANDLE m_device = INVALID_HANDLE_VALUE; - std::wstring m_filename; mutable std::mutex m_lock; #else int m_device = -1; - std::string m_filename; #endif s32 m_media_type = 0; @@ -71,7 +71,7 @@ class IOCtlSrc bool Reopen(); public: - IOCtlSrc(decltype(m_filename) filename); + IOCtlSrc(std::string filename); ~IOCtlSrc(); u32 GetSectorCount() const; @@ -86,13 +86,8 @@ public: extern std::unique_ptr src; -#if defined(_WIN32) -std::vector GetOpticalDriveList(); -void GetValidDrive(std::wstring& drive); -#else std::vector GetOpticalDriveList(); void GetValidDrive(std::string& drive); -#endif extern bool disc_has_changed; extern bool weAreInNewDiskCB; diff --git a/pcsx2/CDVD/Windows/DriveUtility.cpp b/pcsx2/CDVD/Windows/DriveUtility.cpp index 5143f1c646..23833fdb53 100644 --- a/pcsx2/CDVD/Windows/DriveUtility.cpp +++ b/pcsx2/CDVD/Windows/DriveUtility.cpp @@ -16,17 +16,17 @@ #include "PrecompiledHeader.h" #include "CDVD/CDVDdiscReader.h" -std::vector GetOpticalDriveList() +std::vector GetOpticalDriveList() { - DWORD size = GetLogicalDriveStrings(0, nullptr); - std::vector drive_strings(size); - if (GetLogicalDriveStrings(size, drive_strings.data()) != size - 1) + DWORD size = GetLogicalDriveStringsA(0, nullptr); + std::vector drive_strings(size); + if (GetLogicalDriveStringsA(size, drive_strings.data()) != size - 1) return {}; - std::vector drives; + std::vector drives; for (auto p = drive_strings.data(); *p; ++p) { - if (GetDriveType(p) == DRIVE_CDROM) + if (GetDriveTypeA(p) == DRIVE_CDROM) drives.push_back(p); while (*p) ++p; @@ -34,9 +34,9 @@ std::vector GetOpticalDriveList() return drives; } -void GetValidDrive(std::wstring& drive) +void GetValidDrive(std::string& drive) { - if (drive.empty() || GetDriveType(drive.c_str()) != DRIVE_CDROM) + if (drive.empty() || GetDriveTypeA(drive.c_str()) != DRIVE_CDROM) { auto drives = GetOpticalDriveList(); if (drives.empty()) @@ -47,13 +47,10 @@ void GetValidDrive(std::wstring& drive) drive = drives.front(); } - 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()); + printf(" * CDVD: Opening drive '%s'...\n", drive.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"\\\\.\\"); + drive.insert(0, "\\\\.\\"); } diff --git a/pcsx2/CDVD/Windows/IOCtlSrc.cpp b/pcsx2/CDVD/Windows/IOCtlSrc.cpp index fe774ba94b..bfeb956260 100644 --- a/pcsx2/CDVD/Windows/IOCtlSrc.cpp +++ b/pcsx2/CDVD/Windows/IOCtlSrc.cpp @@ -29,8 +29,8 @@ #include #include -IOCtlSrc::IOCtlSrc(decltype(m_filename) filename) - : m_filename(filename) +IOCtlSrc::IOCtlSrc(std::string filename) + : m_filename(std::move(filename)) { if (!Reopen()) throw std::runtime_error(" * CDVD: Error opening source.\n"); @@ -53,7 +53,7 @@ bool IOCtlSrc::Reopen() CloseHandle(m_device); // SPTI only works if the device is opened with GENERIC_WRITE access. - m_device = CreateFile(m_filename.c_str(), GENERIC_READ | GENERIC_WRITE, + m_device = CreateFileA(m_filename.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr); if (m_device == INVALID_HANDLE_VALUE)