Made it possible to directly launch files inside directories that are interpreted as files.

This commit is contained in:
Leon Styhre 2022-04-22 21:01:58 +02:00
parent c2a1d2e914
commit da4462c5a6

View file

@ -819,8 +819,8 @@ void FileData::launchGame()
LOG(LogInfo) << "Launching game \"" << this->metadata.get("name") << "\"..."; LOG(LogInfo) << "Launching game \"" << this->metadata.get("name") << "\"...";
SystemData* gameSystem = nullptr; SystemData* gameSystem {nullptr};
std::string command = ""; std::string command;
std::string alternativeEmulator; std::string alternativeEmulator;
if (mSystem->isCollection()) if (mSystem->isCollection())
@ -868,17 +868,30 @@ void FileData::launchGame()
if (command.empty()) if (command.empty())
command = mEnvData->mLaunchCommands.front().first; command = mEnvData->mLaunchCommands.front().first;
std::string commandRaw = command; std::string commandRaw {command};
std::string romPath {Utils::FileSystem::getEscapedPath(mPath)};
const std::string romPath = Utils::FileSystem::getEscapedPath(getPath()); // For the special case where a directory has a supported file extension and is therefore
const std::string baseName = Utils::FileSystem::getStem(getPath()); // interpreted as a file, check if there is a matching filename inside the directory.
const std::string romRaw = Utils::FileSystem::getPreferredPath(getPath()); // This is used as a shortcut to be able to launch games directly inside folders.
const std::string esPath = Utils::FileSystem::getExePath(); if (mType == GAME && Utils::FileSystem::isDirectory(mPath)) {
bool runInBackground = false; for (std::string& file : Utils::FileSystem::getDirContent(mPath)) {
if (Utils::FileSystem::getFileName(file) == Utils::FileSystem::getFileName(mPath) &&
(Utils::FileSystem::isRegularFile(file) || Utils::FileSystem::isSymlink(file))) {
romPath = Utils::FileSystem::getEscapedPath(file);
break;
}
}
}
const std::string baseName {Utils::FileSystem::getStem(mPath)};
const std::string romRaw {Utils::FileSystem::getPreferredPath(mPath)};
const std::string esPath {Utils::FileSystem::getExePath()};
bool runInBackground {false};
// In addition to the global RunInBackground setting it's possible to define this flag // In addition to the global RunInBackground setting it's possible to define this flag
// per launch command in es_systems.xml. // per launch command in es_systems.xml.
size_t inBackgroundPos = command.find("%RUNINBACKGROUND%"); size_t inBackgroundPos {command.find("%RUNINBACKGROUND%")};
if (inBackgroundPos != std::string::npos) { if (inBackgroundPos != std::string::npos) {
runInBackground = true; runInBackground = true;