Repair EmuXLaunchNewImage

Symbolic links cannot be relied upon, but devices are always present, so
use those.
This commit is contained in:
PatrickvL 2016-12-31 20:00:42 +01:00
parent 74b13b7d65
commit bebcff71e8
3 changed files with 38 additions and 24 deletions

View File

@ -96,12 +96,6 @@ const char CxbxDefaultXbeDriveLetter = 'D';
int CxbxDefaultXbeDriveIndex = -1; int CxbxDefaultXbeDriveIndex = -1;
EmuNtSymbolicLinkObject* NtSymbolicLinkObjects[26]; EmuNtSymbolicLinkObject* NtSymbolicLinkObjects[26];
struct XboxDevice {
std::string XboxDevicePath;
std::string HostDevicePath;
HANDLE HostRootHandle;
};
std::vector<XboxDevice> Devices; std::vector<XboxDevice> Devices;
EmuHandle::EmuHandle(EmuNtObject* ntObject) EmuHandle::EmuHandle(EmuNtObject* ntObject)
@ -353,6 +347,24 @@ NTSTATUS CxbxObjectAttributesToNT(
return result; return result;
} }
int CxbxDeviceIndexByDevicePath(const char *XboxDevicePath)
{
for (size_t i = 0; i < Devices.size(); i++)
if (_strnicmp(XboxDevicePath, Devices[i].XboxDevicePath.c_str(), Devices[i].XboxDevicePath.length()) == 0)
return(i);
return -1;
}
XboxDevice *CxbxDeviceByDevicePath(const std::string XboxDevicePath)
{
int DeviceIndex = CxbxDeviceIndexByDevicePath(XboxDevicePath.c_str());
if (DeviceIndex >= 0)
return &Devices[DeviceIndex];
return nullptr;
}
int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevicePath, bool IsFile) int CxbxRegisterDeviceHostPath(std::string XboxDevicePath, std::string HostDevicePath, bool IsFile)
{ {
int result = -1; int result = -1;
@ -426,16 +438,7 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin
if (IsHostBasedPath) if (IsHostBasedPath)
DeviceIndex = CxbxDefaultXbeDriveIndex; DeviceIndex = CxbxDefaultXbeDriveIndex;
else else
{ DeviceIndex = CxbxDeviceIndexByDevicePath(aFullPath.c_str());
DeviceIndex = -1;
for (size_t i = 0; i < Devices.size(); i++) {
if (_strnicmp(aFullPath.c_str(), Devices[i].XboxDevicePath.c_str(), Devices[i].XboxDevicePath.length()) == 0)
{
DeviceIndex = i;
break;
}
}
}
if (DeviceIndex >= 0) if (DeviceIndex >= 0)
{ {

View File

@ -41,6 +41,7 @@ namespace xboxkrnl
#include <xboxkrnl/xboxkrnl.h> #include <xboxkrnl/xboxkrnl.h>
}; };
#include <vector>
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <memory> #include <memory>
@ -210,6 +211,12 @@ public:
~EmuNtSymbolicLinkObject(); ~EmuNtSymbolicLinkObject();
}; };
struct XboxDevice {
std::string XboxDevicePath;
std::string HostDevicePath;
HANDLE HostRootHandle;
};
// ****************************************************************** // ******************************************************************
// * is Handle a 'special' emulated handle? // * is Handle a 'special' emulated handle?
// ****************************************************************** // ******************************************************************
@ -219,13 +226,17 @@ HANDLE EmuHandleToHandle(EmuHandle* emuHandle);
CHAR* NtStatusToString(IN NTSTATUS Status); CHAR* NtStatusToString(IN NTSTATUS Status);
int CxbxRegisterDeviceHostPath(std::string XboxFullPath, std::string HostDevicePath, bool IsFile = false);
int CxbxDeviceIndexByDevicePath(const char *XboxDevicePath);
XboxDevice *CxbxDeviceByDevicePath(const std::string XboxDevicePath);
char SymbolicLinkToDriveLetter(std::string aSymbolicLinkName); char SymbolicLinkToDriveLetter(std::string aSymbolicLinkName);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDriveLetter(const char DriveLetter); EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDriveLetter(const char DriveLetter);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByName(std::string SymbolicLinkName); EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByName(std::string SymbolicLinkName);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDevice(std::string DeviceName); EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDevice(std::string DeviceName);
EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(HANDLE Handle); EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(HANDLE Handle);
void CleanupSymbolicLinks(); void CleanupSymbolicLinks();
int CxbxRegisterDeviceHostPath(std::string XboxFullPath, std::string HostDevicePath, bool IsFile = false);
HANDLE CxbxGetDeviceNativeRootHandle(std::string XboxFullPath); HANDLE CxbxGetDeviceNativeRootHandle(std::string XboxFullPath);
NTSTATUS CxbxCreateSymbolicLink(std::string SymbolicLinkName, std::string FullPath); NTSTATUS CxbxCreateSymbolicLink(std::string SymbolicLinkName, std::string FullPath);
bool CxbxMountUtilityDrive(bool formatClean); bool CxbxMountUtilityDrive(bool formatClean);

View File

@ -968,15 +968,15 @@ DWORD WINAPI XTL::EmuXLaunchNewImage
// If no path is specified, then the xbe is rebooting to dashboard // If no path is specified, then the xbe is rebooting to dashboard
if (!lpTitlePath) { if (!lpTitlePath) {
char szDashboardPath[MAX_PATH]; char szDashboardPath[MAX_PATH] = { 0 };
EmuNtSymbolicLinkObject* symbolicLinkObject = FindNtSymbolicLinkObjectByDevice(DeviceHarddisk0Partition2); XboxDevice* rootDevice = CxbxDeviceByDevicePath(DeviceHarddisk0Partition2);
sprintf(szDashboardPath, "%s\\xboxdash.xbe", symbolicLinkObject->HostSymbolicLinkPath.c_str()); if(rootDevice != nullptr)
sprintf(szDashboardPath, "%s\\xboxdash.xbe", rootDevice->HostDevicePath.c_str());
if (PathFileExists(szDashboardPath)) { if (PathFileExists(szDashboardPath))
{
MessageBox(CxbxKrnl_hEmuParent, "The title is rebooting to dashboard", "Cxbx-Reloaded", 0); MessageBox(CxbxKrnl_hEmuParent, "The title is rebooting to dashboard", "Cxbx-Reloaded", 0);
char szXboxDashboardPath[MAX_PATH]; EmuXLaunchNewImage("C:\xboxdash.xbe", pLaunchData);
sprintf(szXboxDashboardPath, "%c:\\xboxdash.xbe", symbolicLinkObject->DriveLetter);
EmuXLaunchNewImage(szXboxDashboardPath, pLaunchData);
} }
CxbxKrnlCleanup("The xbe rebooted to Dashboard and xboxdash.xbe could not be found"); CxbxKrnlCleanup("The xbe rebooted to Dashboard and xboxdash.xbe could not be found");