mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Added support for a %STARTDIR% es_systems.xml variable.
This commit is contained in:
parent
de48b69760
commit
6caf4d193b
|
|
@ -994,10 +994,9 @@ void FileData::launchGame()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
LOG(LogDebug) << "FileData::launchGame(): Found emulator binary \""
|
LOG(LogDebug) << "FileData::launchGame(): Found emulator binary "
|
||||||
<< Utils::String::replace(
|
<< Utils::String::replace(
|
||||||
Utils::String::replace(binaryPath, "%ESPATH%", esPath), "/", "\\")
|
Utils::String::replace(binaryPath, "%ESPATH%", esPath), "/", "\\");
|
||||||
<< "\"";
|
|
||||||
#else
|
#else
|
||||||
LOG(LogDebug) << "FileData::launchGame(): Found emulator binary \""
|
LOG(LogDebug) << "FileData::launchGame(): Found emulator binary \""
|
||||||
<< Utils::String::replace(binaryPath, "%ESPATH%", esPath) << "\"";
|
<< Utils::String::replace(binaryPath, "%ESPATH%", esPath) << "\"";
|
||||||
|
|
@ -1165,15 +1164,116 @@ void FileData::launchGame()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string startDirectory;
|
||||||
|
size_t startDirPos {command.find("%STARTDIR%")};
|
||||||
|
|
||||||
|
if (startDirPos != std::string::npos) {
|
||||||
|
bool invalidEntry {false};
|
||||||
|
|
||||||
|
if (startDirPos + 12 >= command.size())
|
||||||
|
invalidEntry = true;
|
||||||
|
else if (command[startDirPos + 10] != '=')
|
||||||
|
invalidEntry = true;
|
||||||
|
|
||||||
|
if (!invalidEntry && command[startDirPos + 11] == '\"') {
|
||||||
|
size_t closingQuotation {command.find("\"", startDirPos + 12)};
|
||||||
|
|
||||||
|
if (closingQuotation != std::string::npos) {
|
||||||
|
startDirectory =
|
||||||
|
command.substr(startDirPos + 12, closingQuotation - startDirPos - 12);
|
||||||
|
command = command.replace(startDirPos, closingQuotation - startDirPos + 2, "");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
invalidEntry = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!invalidEntry) {
|
||||||
|
size_t spacePos {command.find(" ", startDirPos)};
|
||||||
|
if (spacePos != std::string::npos) {
|
||||||
|
startDirectory = command.substr(startDirPos + 11, spacePos - startDirPos - 11);
|
||||||
|
command = command.replace(startDirPos, spacePos - startDirPos + 1, "");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
startDirectory = command.substr(startDirPos + 11, command.size() - startDirPos);
|
||||||
|
command = command.replace(startDirPos, command.size() - startDirPos, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invalidEntry) {
|
||||||
|
LOG(LogError) << "Couldn't launch game, invalid %STARTDIR% entry";
|
||||||
|
LOG(LogError) << "Raw emulator launch command:";
|
||||||
|
LOG(LogError) << commandRaw;
|
||||||
|
|
||||||
|
window->queueInfoPopup("ERROR: INVALID %STARTDIR% VARIABLE ENTRY", 6000);
|
||||||
|
window->setAllowTextScrolling(true);
|
||||||
|
window->setAllowFileAnimation(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDirectory != "") {
|
||||||
|
startDirectory = Utils::FileSystem::expandHomePath(startDirectory);
|
||||||
|
#if defined(_WIN64)
|
||||||
|
startDirectory = Utils::String::replace(
|
||||||
|
startDirectory, "%EMUDIR%",
|
||||||
|
Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\"", "")));
|
||||||
|
#else
|
||||||
|
startDirectory = Utils::String::replace(
|
||||||
|
startDirectory, "%EMUDIR%",
|
||||||
|
Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\\", "")));
|
||||||
|
#endif
|
||||||
|
if (!Utils::FileSystem::isDirectory(startDirectory)) {
|
||||||
|
Utils::FileSystem::createDirectory(startDirectory);
|
||||||
|
|
||||||
|
if (!Utils::FileSystem::isDirectory(startDirectory)) {
|
||||||
|
LOG(LogError)
|
||||||
|
<< "Couldn't launch game, directory defined by %STARTDIR% could not be "
|
||||||
|
"created, permission problems?";
|
||||||
|
LOG(LogError) << "Raw emulator launch command:";
|
||||||
|
LOG(LogError) << commandRaw;
|
||||||
|
|
||||||
|
window->queueInfoPopup("ERROR: DIRECTORY DEFINED BY %STARTDIR% COULD NOT BE "
|
||||||
|
"CREATED, PERMISSION PROBLEMS?",
|
||||||
|
6000);
|
||||||
|
window->setAllowTextScrolling(true);
|
||||||
|
window->setAllowFileAnimation(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if defined(_WIN64)
|
||||||
|
startDirectory = Utils::String::replace(startDirectory, "/", "\\");
|
||||||
|
#else
|
||||||
|
startDirectory = Utils::FileSystem::getEscapedPath(startDirectory);
|
||||||
|
#endif
|
||||||
|
LOG(LogDebug) << "FileData::launchGame(): Setting start directory to \""
|
||||||
|
<< startDirectory << "\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Replace the remaining variables with their actual values.
|
// Replace the remaining variables with their actual values.
|
||||||
command = Utils::String::replace(command, "%ROM%", romPath);
|
command = Utils::String::replace(command, "%ROM%", romPath);
|
||||||
command = Utils::String::replace(command, "%BASENAME%", baseName);
|
command = Utils::String::replace(command, "%BASENAME%", baseName);
|
||||||
command = Utils::String::replace(command, "%ROMRAW%", romRaw);
|
command = Utils::String::replace(command, "%ROMRAW%", romRaw);
|
||||||
command = Utils::String::replace(command, "%ROMPATH%", getROMDirectory());
|
command = Utils::String::replace(command, "%ROMPATH%",
|
||||||
|
Utils::FileSystem::getEscapedPath(getROMDirectory()));
|
||||||
|
#if defined(_WIN64)
|
||||||
|
command = Utils::String::replace(command, "%EMUDIR%",
|
||||||
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
|
||||||
|
Utils::String::replace(binaryPath, "\"", ""))));
|
||||||
|
#else
|
||||||
|
command = Utils::String::replace(command, "%EMUDIR%",
|
||||||
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
|
||||||
|
Utils::String::replace(binaryPath, "\\", ""))));
|
||||||
|
#endif
|
||||||
|
|
||||||
// Trim any leading and trailing whitespace characters as they could cause launch issues.
|
// Trim any leading and trailing whitespace characters as they could cause launch issues.
|
||||||
command = Utils::String::trim(command);
|
command = Utils::String::trim(command);
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
// Hack to be able to surround paths with quotation marks when using the %ROMPATH% and
|
||||||
|
// %EMUDIR% variables.
|
||||||
|
command = Utils::String::replace(command, "\"\"", "");
|
||||||
|
#endif
|
||||||
|
|
||||||
// swapBuffers() is called here to turn the screen black to eliminate some potential
|
// swapBuffers() is called here to turn the screen black to eliminate some potential
|
||||||
// flickering and to avoid showing the game launch message briefly when returning
|
// flickering and to avoid showing the game launch message briefly when returning
|
||||||
// from the game.
|
// from the game.
|
||||||
|
|
@ -1198,10 +1298,11 @@ void FileData::launchGame()
|
||||||
// Possibly keep ES-DE running in the background while the game is launched.
|
// Possibly keep ES-DE running in the background while the game is launched.
|
||||||
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
returnValue = Utils::Platform::launchGameWindows(Utils::String::stringToWideString(command),
|
returnValue = Utils::Platform::launchGameWindows(
|
||||||
runInBackground, hideWindow);
|
Utils::String::stringToWideString(command),
|
||||||
|
Utils::String::stringToWideString(startDirectory), runInBackground, hideWindow);
|
||||||
#else
|
#else
|
||||||
returnValue = Utils::Platform::launchGameUnix(command, runInBackground);
|
returnValue = Utils::Platform::launchGameUnix(command, startDirectory, runInBackground);
|
||||||
#endif
|
#endif
|
||||||
// Notify the user in case of a failed game launch using a popup window.
|
// Notify the user in case of a failed game launch using a popup window.
|
||||||
if (returnValue != 0) {
|
if (returnValue != 0) {
|
||||||
|
|
@ -1495,6 +1596,7 @@ const std::string FileData::findEmulatorPath(std::string& command)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils::FileSystem::isRegularFile(path) || Utils::FileSystem::isSymlink(path)) {
|
if (Utils::FileSystem::isRegularFile(path) || Utils::FileSystem::isSymlink(path)) {
|
||||||
|
path = Utils::FileSystem::getEscapedPath(path);
|
||||||
command.replace(startPos, endPos - startPos + 1, path);
|
command.replace(startPos, endPos - startPos + 1, path);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
@ -1540,10 +1642,11 @@ const std::string FileData::findEmulatorPath(std::string& command)
|
||||||
#else
|
#else
|
||||||
if (Utils::FileSystem::isRegularFile(emuExecutable) ||
|
if (Utils::FileSystem::isRegularFile(emuExecutable) ||
|
||||||
Utils::FileSystem::isSymlink(emuExecutable)) {
|
Utils::FileSystem::isSymlink(emuExecutable)) {
|
||||||
exePath = emuExecutable;
|
exePath = Utils::FileSystem::getEscapedPath(emuExecutable);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
exePath = Utils::FileSystem::getPathToBinary(emuExecutable);
|
exePath =
|
||||||
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getPathToBinary(emuExecutable));
|
||||||
if (exePath != "")
|
if (exePath != "")
|
||||||
exePath += "/" + emuExecutable;
|
exePath += "/" + emuExecutable;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,9 @@ namespace Utils
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int launchGameUnix(const std::string& cmd_utf8, bool runInBackground)
|
int launchGameUnix(const std::string& cmd_utf8,
|
||||||
|
const std::string& startDirectory,
|
||||||
|
bool runInBackground)
|
||||||
{
|
{
|
||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
std::string command = std::string(cmd_utf8) + " 2>&1 &";
|
std::string command = std::string(cmd_utf8) + " 2>&1 &";
|
||||||
|
|
@ -94,6 +96,9 @@ namespace Utils
|
||||||
std::string commandOutput;
|
std::string commandOutput;
|
||||||
int returnValue;
|
int returnValue;
|
||||||
|
|
||||||
|
if (startDirectory != "")
|
||||||
|
command = "cd " + startDirectory + " && " + command;
|
||||||
|
|
||||||
if (!(commandPipe = reinterpret_cast<FILE*>(popen(command.c_str(), "r")))) {
|
if (!(commandPipe = reinterpret_cast<FILE*>(popen(command.c_str(), "r")))) {
|
||||||
LOG(LogError) << "Couldn't open pipe to command.";
|
LOG(LogError) << "Couldn't open pipe to command.";
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -141,7 +146,10 @@ namespace Utils
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int launchGameWindows(const std::wstring& cmd_utf16, bool runInBackground, bool hideWindow)
|
int launchGameWindows(const std::wstring& cmd_utf16,
|
||||||
|
std::wstring& startDirectory,
|
||||||
|
bool runInBackground,
|
||||||
|
bool hideWindow)
|
||||||
{
|
{
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
STARTUPINFOW si {};
|
STARTUPINFOW si {};
|
||||||
|
|
@ -157,6 +165,8 @@ namespace Utils
|
||||||
bool processReturnValue = true;
|
bool processReturnValue = true;
|
||||||
DWORD errorCode = 0;
|
DWORD errorCode = 0;
|
||||||
|
|
||||||
|
wchar_t* startDir {startDirectory == L"" ? nullptr : &startDirectory[0]};
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
processReturnValue = CreateProcessW(
|
processReturnValue = CreateProcessW(
|
||||||
nullptr, // No application name (use command line).
|
nullptr, // No application name (use command line).
|
||||||
|
|
@ -166,7 +176,7 @@ namespace Utils
|
||||||
FALSE, // Handles inheritance.
|
FALSE, // Handles inheritance.
|
||||||
0, // Creation flags.
|
0, // Creation flags.
|
||||||
nullptr, // Use parent's environment block.
|
nullptr, // Use parent's environment block.
|
||||||
nullptr, // Use parent's starting directory.
|
startDir, // Starting directory, possibly the same as parent.
|
||||||
&si, // Pointer to the STARTUPINFOW structure.
|
&si, // Pointer to the STARTUPINFOW structure.
|
||||||
&pi); // Pointer to the PROCESS_INFORMATION structure.
|
&pi); // Pointer to the PROCESS_INFORMATION structure.
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,13 @@ namespace Utils
|
||||||
// Windows specific UTF-16/wstring function. (FOR FUTURE USE)
|
// Windows specific UTF-16/wstring function. (FOR FUTURE USE)
|
||||||
int runSystemCommand(const std::wstring& cmd_utf16);
|
int runSystemCommand(const std::wstring& cmd_utf16);
|
||||||
|
|
||||||
int launchGameUnix(const std::string& cmd_utf8, bool runInBackground);
|
int launchGameUnix(const std::string& cmd_utf8,
|
||||||
int launchGameWindows(const std::wstring& cmd_utf16, bool runInBackground, bool hideWindow);
|
const std::string& startDirectory,
|
||||||
|
bool runInBackground);
|
||||||
|
int launchGameWindows(const std::wstring& cmd_utf16,
|
||||||
|
std::wstring& startDirectory,
|
||||||
|
bool runInBackground,
|
||||||
|
bool hideWindow);
|
||||||
|
|
||||||
unsigned int getTaskbarState();
|
unsigned int getTaskbarState();
|
||||||
void hideTaskbar();
|
void hideTaskbar();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue