Fixed multiple game launching issues.

This commit is contained in:
Leon Styhre 2022-05-02 17:25:10 +02:00
parent c197dde21e
commit f4c9586eeb

View file

@ -933,7 +933,11 @@ void FileData::launchGame()
// If there's a quotation mark before the %CORE_ variable, then remove it.
// The closing quotation mark will be removed later below.
bool hasCoreQuotation {false};
if (command.find("\"%CORE_") != std::string::npos) {
command = Utils::String::replace(command, "\"%CORE_", "%CORE_");
hasCoreQuotation = true;
}
coreEntryPos = command.find("%CORE_");
if (coreEntryPos != std::string::npos) {
@ -1019,8 +1023,14 @@ void FileData::launchGame()
std::string coreFile;
if (spacePos != std::string::npos) {
coreRaw = command.substr(emuPathPos, spacePos - emuPathPos);
#if defined(_WIN64)
coreFile = Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\"", "")) +
command.substr(emuPathPos + 9, spacePos - emuPathPos - 9);
coreFile = Utils::String::replace(coreFile, "/", "\\");
#else
coreFile = Utils::FileSystem::getParent(binaryPath) +
command.substr(emuPathPos + 9, spacePos - emuPathPos - 9);
#endif
if (hasQuotationMark) {
coreRaw.pop_back();
coreFile.pop_back();
@ -1103,9 +1113,10 @@ void FileData::launchGame()
size_t stringPos = coreFile.find("%EMUPATH%");
if (stringPos != std::string::npos) {
#if defined(_WIN64)
coreFile = Utils::String::replace(
coreFile.replace(stringPos, 9, Utils::FileSystem::getParent(binaryPath)), "/",
"\\");
coreFile = coreFile.replace(
stringPos, 9,
Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\"", "")));
coreFile = Utils::String::replace(coreFile, "/", "\\");
#else
coreFile = coreFile.replace(stringPos, 9, Utils::FileSystem::getParent(binaryPath));
#endif
@ -1126,7 +1137,8 @@ void FileData::launchGame()
// Escape any blankspaces.
if (coreFile.find(" ") != std::string::npos)
coreFile = Utils::FileSystem::getEscapedPath(coreFile);
command.replace(coreEntryPos, separatorPos - coreEntryPos, coreFile);
command.replace(coreEntryPos,
separatorPos - coreEntryPos + (hasCoreQuotation ? 1 : 0), coreFile);
#if !defined(_WIN64)
// Remove any quotation marks as it would make the launch function fail.
if (command.find("\"") != std::string::npos)
@ -1256,10 +1268,13 @@ void FileData::launchGame()
command = Utils::String::replace(command, "%ROMPATH%",
Utils::FileSystem::getEscapedPath(getROMDirectory()));
#if defined(_WIN64)
command = Utils::String::replace(
command, "%ESPATH%", Utils::String::replace(Utils::FileSystem::getExePath(), "/", "\\"));
command = Utils::String::replace(command, "%EMUDIR%",
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
Utils::String::replace(binaryPath, "\"", ""))));
#else
command = Utils::String::replace(command, "%ESPATH%", Utils::FileSystem::getExePath());
command = Utils::String::replace(command, "%EMUDIR%",
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
Utils::String::replace(binaryPath, "\\", ""))));