Merge pull request #2112 from x1nixmzeng/fix-ro-launch

Fixed booting games from write-protected drives
This commit is contained in:
PatrickvL 2021-01-03 17:57:12 +01:00 committed by GitHub
commit 875f97b5dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -553,34 +553,35 @@ XboxDevice *CxbxDeviceByDevicePath(const std::string XboxDevicePath)
int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevicePath, bool IsFile) int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevicePath, bool IsFile)
{ {
int result = -1;
NTSTATUS status = (NTSTATUS)-1;
XboxDevice newDevice; XboxDevice newDevice;
newDevice.XboxDevicePath = XboxDevicePath; newDevice.XboxDevicePath = XboxDevicePath;
newDevice.HostDevicePath = HostDevicePath; newDevice.HostDevicePath = HostDevicePath;
bool succeeded{ false };
// All HDD partitions have a .bin file to allow direct file io on the partition info // All HDD partitions have a .bin file to allow direct file io on the partition info
if (_strnicmp(XboxDevicePath.c_str(), DeviceHarddisk0PartitionPrefix.c_str(), DeviceHarddisk0PartitionPrefix.length()) == 0) { if (_strnicmp(XboxDevicePath.c_str(), DeviceHarddisk0PartitionPrefix.c_str(), DeviceHarddisk0PartitionPrefix.length()) == 0) {
std::string partitionHeaderPath = (HostDevicePath + ".bin").c_str(); std::string partitionHeaderPath = HostDevicePath + ".bin";
if (!PathFileExists(partitionHeaderPath.c_str())) { if (!std::filesystem::exists(partitionHeaderPath)) {
CxbxCreatePartitionHeaderFile(partitionHeaderPath, XboxDevicePath == DeviceHarddisk0Partition0); CxbxCreatePartitionHeaderFile(partitionHeaderPath, XboxDevicePath == DeviceHarddisk0Partition0);
} }
status = xbox::status_success; succeeded = true;
} }
// If this path is not a raw file partition, create the directory for it // If this path is not a raw file partition, create the directory for it
if (!IsFile) { if (!IsFile) {
status = SHCreateDirectoryEx(NULL, HostDevicePath.c_str(), NULL); succeeded = std::filesystem::exists(HostDevicePath) || std::filesystem::create_directory(HostDevicePath);
} }
if (status == xbox::status_success || status == ERROR_ALREADY_EXISTS) { if (succeeded) {
Devices.push_back(newDevice); Devices.push_back(newDevice);
result = Devices.size() - 1; return static_cast<int>(Devices.size()) - 1;
} }
return result; EmuLog(LOG_LEVEL::FATAL, "Failed to register host device (%s)\n", HostDevicePath.c_str());
return -1;
} }