From dfe9a19b0d223ad8e7c8a5049bacf122ae94f81a Mon Sep 17 00:00:00 2001 From: x1nixmzeng Date: Fri, 1 Jan 2021 15:52:49 +0000 Subject: [PATCH 1/2] Fixed path registration on write protected drives --- src/core/kernel/support/EmuFile.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/kernel/support/EmuFile.cpp b/src/core/kernel/support/EmuFile.cpp index d98f98e9d..c972bbe82 100644 --- a/src/core/kernel/support/EmuFile.cpp +++ b/src/core/kernel/support/EmuFile.cpp @@ -554,29 +554,39 @@ XboxDevice *CxbxDeviceByDevicePath(const std::string XboxDevicePath) int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevicePath, bool IsFile) { int result = -1; - NTSTATUS status = (NTSTATUS)-1; XboxDevice newDevice; newDevice.XboxDevicePath = XboxDevicePath; newDevice.HostDevicePath = HostDevicePath; + bool succeeded{ false }; + // 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) { - std::string partitionHeaderPath = (HostDevicePath + ".bin").c_str(); - if (!PathFileExists(partitionHeaderPath.c_str())) { + std::string partitionHeaderPath = HostDevicePath + ".bin"; + if (!std::filesystem::exists(partitionHeaderPath)) { 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 (!IsFile) { - status = SHCreateDirectoryEx(NULL, HostDevicePath.c_str(), NULL); + + if (std::filesystem::exists(HostDevicePath)) + { + succeeded = true; + } + else + { + succeeded = std::filesystem::create_directory(HostDevicePath); + } } - if (status == xbox::status_success || status == ERROR_ALREADY_EXISTS) { - Devices.push_back(newDevice); + if (succeeded) + { + Devices.emplace_back(newDevice); result = Devices.size() - 1; } From 9e05b3342de1e1e534ae0af75c9cbd8f27f7d737 Mon Sep 17 00:00:00 2001 From: x1nixmzeng Date: Sat, 2 Jan 2021 00:20:32 +0000 Subject: [PATCH 2/2] Log a fatal message if registering a host device fails --- src/core/kernel/support/EmuFile.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/core/kernel/support/EmuFile.cpp b/src/core/kernel/support/EmuFile.cpp index c972bbe82..0b242b663 100644 --- a/src/core/kernel/support/EmuFile.cpp +++ b/src/core/kernel/support/EmuFile.cpp @@ -553,8 +553,6 @@ XboxDevice *CxbxDeviceByDevicePath(const std::string XboxDevicePath) int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevicePath, bool IsFile) { - int result = -1; - XboxDevice newDevice; newDevice.XboxDevicePath = XboxDevicePath; newDevice.HostDevicePath = HostDevicePath; @@ -573,24 +571,17 @@ int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevic // If this path is not a raw file partition, create the directory for it if (!IsFile) { - - if (std::filesystem::exists(HostDevicePath)) - { - succeeded = true; - } - else - { - succeeded = std::filesystem::create_directory(HostDevicePath); - } + succeeded = std::filesystem::exists(HostDevicePath) || std::filesystem::create_directory(HostDevicePath); } - if (succeeded) - { - Devices.emplace_back(newDevice); - result = Devices.size() - 1; + if (succeeded) { + Devices.push_back(newDevice); + return static_cast(Devices.size()) - 1; } - return result; + EmuLog(LOG_LEVEL::FATAL, "Failed to register host device (%s)\n", HostDevicePath.c_str()); + + return -1; }