mirror of https://github.com/PCSX2/pcsx2.git
CDVD: Use ANSI variants on Windows for disc access
The drive path is not going to contain unicode characters.
This commit is contained in:
parent
17c049d7e3
commit
f79f85480b
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
#include "CDVDdiscReader.h"
|
#include "CDVDdiscReader.h"
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
|
@ -182,11 +181,7 @@ void StopKeepAliveThread()
|
||||||
|
|
||||||
s32 CALLBACK DISCopen(const char* pTitle)
|
s32 CALLBACK DISCopen(const char* pTitle)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
std::string drive(pTitle);
|
||||||
std::wstring drive = EmuConfig.CurrentDiscDrive.ToStdWstring();
|
|
||||||
#else
|
|
||||||
std::string drive = EmuConfig.CurrentDiscDrive.ToStdString();
|
|
||||||
#endif
|
|
||||||
GetValidDrive(drive);
|
GetValidDrive(drive);
|
||||||
if (drive.empty())
|
if (drive.empty())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -52,13 +52,13 @@ class IOCtlSrc
|
||||||
IOCtlSrc(const IOCtlSrc&) = delete;
|
IOCtlSrc(const IOCtlSrc&) = delete;
|
||||||
IOCtlSrc& operator=(const IOCtlSrc&) = delete;
|
IOCtlSrc& operator=(const IOCtlSrc&) = delete;
|
||||||
|
|
||||||
|
std::string m_filename;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
HANDLE m_device = INVALID_HANDLE_VALUE;
|
HANDLE m_device = INVALID_HANDLE_VALUE;
|
||||||
std::wstring m_filename;
|
|
||||||
mutable std::mutex m_lock;
|
mutable std::mutex m_lock;
|
||||||
#else
|
#else
|
||||||
int m_device = -1;
|
int m_device = -1;
|
||||||
std::string m_filename;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
s32 m_media_type = 0;
|
s32 m_media_type = 0;
|
||||||
|
@ -71,7 +71,7 @@ class IOCtlSrc
|
||||||
bool Reopen();
|
bool Reopen();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IOCtlSrc(decltype(m_filename) filename);
|
IOCtlSrc(std::string filename);
|
||||||
~IOCtlSrc();
|
~IOCtlSrc();
|
||||||
|
|
||||||
u32 GetSectorCount() const;
|
u32 GetSectorCount() const;
|
||||||
|
@ -86,13 +86,8 @@ public:
|
||||||
|
|
||||||
extern std::unique_ptr<IOCtlSrc> src;
|
extern std::unique_ptr<IOCtlSrc> src;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
std::vector<std::wstring> GetOpticalDriveList();
|
|
||||||
void GetValidDrive(std::wstring& drive);
|
|
||||||
#else
|
|
||||||
std::vector<std::string> GetOpticalDriveList();
|
std::vector<std::string> GetOpticalDriveList();
|
||||||
void GetValidDrive(std::string& drive);
|
void GetValidDrive(std::string& drive);
|
||||||
#endif
|
|
||||||
|
|
||||||
extern bool disc_has_changed;
|
extern bool disc_has_changed;
|
||||||
extern bool weAreInNewDiskCB;
|
extern bool weAreInNewDiskCB;
|
||||||
|
|
|
@ -16,17 +16,17 @@
|
||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
#include "CDVD/CDVDdiscReader.h"
|
#include "CDVD/CDVDdiscReader.h"
|
||||||
|
|
||||||
std::vector<std::wstring> GetOpticalDriveList()
|
std::vector<std::string> GetOpticalDriveList()
|
||||||
{
|
{
|
||||||
DWORD size = GetLogicalDriveStrings(0, nullptr);
|
DWORD size = GetLogicalDriveStringsA(0, nullptr);
|
||||||
std::vector<wchar_t> drive_strings(size);
|
std::vector<char> drive_strings(size);
|
||||||
if (GetLogicalDriveStrings(size, drive_strings.data()) != size - 1)
|
if (GetLogicalDriveStringsA(size, drive_strings.data()) != size - 1)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::vector<std::wstring> drives;
|
std::vector<std::string> drives;
|
||||||
for (auto p = drive_strings.data(); *p; ++p)
|
for (auto p = drive_strings.data(); *p; ++p)
|
||||||
{
|
{
|
||||||
if (GetDriveType(p) == DRIVE_CDROM)
|
if (GetDriveTypeA(p) == DRIVE_CDROM)
|
||||||
drives.push_back(p);
|
drives.push_back(p);
|
||||||
while (*p)
|
while (*p)
|
||||||
++p;
|
++p;
|
||||||
|
@ -34,9 +34,9 @@ std::vector<std::wstring> GetOpticalDriveList()
|
||||||
return drives;
|
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();
|
auto drives = GetOpticalDriveList();
|
||||||
if (drives.empty())
|
if (drives.empty())
|
||||||
|
@ -47,13 +47,10 @@ void GetValidDrive(std::wstring& drive)
|
||||||
drive = drives.front();
|
drive = drives.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = WideCharToMultiByte(CP_UTF8, 0, drive.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
printf(" * CDVD: Opening drive '%s'...\n", drive.data());
|
||||||
std::vector<char> 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
|
// The drive string has the form "X:\", but to open the drive, the string
|
||||||
// has to be in the form "\\.\X:"
|
// has to be in the form "\\.\X:"
|
||||||
drive.pop_back();
|
drive.pop_back();
|
||||||
drive.insert(0, L"\\\\.\\");
|
drive.insert(0, "\\\\.\\");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
IOCtlSrc::IOCtlSrc(decltype(m_filename) filename)
|
IOCtlSrc::IOCtlSrc(std::string filename)
|
||||||
: m_filename(filename)
|
: m_filename(std::move(filename))
|
||||||
{
|
{
|
||||||
if (!Reopen())
|
if (!Reopen())
|
||||||
throw std::runtime_error(" * CDVD: Error opening source.\n");
|
throw std::runtime_error(" * CDVD: Error opening source.\n");
|
||||||
|
@ -53,7 +53,7 @@ bool IOCtlSrc::Reopen()
|
||||||
CloseHandle(m_device);
|
CloseHandle(m_device);
|
||||||
|
|
||||||
// SPTI only works if the device is opened with GENERIC_WRITE access.
|
// 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_SHARE_READ, nullptr, OPEN_EXISTING,
|
||||||
FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
|
FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
|
||||||
if (m_device == INVALID_HANDLE_VALUE)
|
if (m_device == INVALID_HANDLE_VALUE)
|
||||||
|
|
Loading…
Reference in New Issue