mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Added emulator filename wildcard support for es_systems.xml and es_find_rules.xml
This commit is contained in:
parent
fabc18a680
commit
da802aec61
|
@ -1453,6 +1453,13 @@ const std::string FileData::findEmulatorPath(std::string& command)
|
|||
// Likewise for the %ROMPATH% variable which expands to the configured ROM directory.
|
||||
path = Utils::String::replace(path, "%ROMPATH%", getROMDirectory());
|
||||
|
||||
// Find the first matching file if a wildcard was used for the emulator entry.
|
||||
if (path.find('*') != std::string::npos) {
|
||||
Utils::FileSystem::StringList files {Utils::FileSystem::getMatchingFiles(path)};
|
||||
if (files.size() > 0)
|
||||
path = files.front();
|
||||
}
|
||||
|
||||
if (Utils::FileSystem::isRegularFile(path) || Utils::FileSystem::isSymlink(path)) {
|
||||
command.replace(startPos, endPos - startPos + 1, path);
|
||||
return path;
|
||||
|
@ -1474,6 +1481,14 @@ const std::string FileData::findEmulatorPath(std::string& command)
|
|||
emuExecutable = command.substr(0, command.find(' '));
|
||||
}
|
||||
|
||||
if (emuExecutable.find('*') != std::string::npos) {
|
||||
Utils::FileSystem::StringList files {Utils::FileSystem::getMatchingFiles(emuExecutable)};
|
||||
if (files.size() > 0) {
|
||||
command = Utils::String::replace(command, emuExecutable, files.front());
|
||||
emuExecutable = files.front();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_WIN64)
|
||||
std::wstring emuExecutableWide = Utils::String::stringToWideString(emuExecutable);
|
||||
// Search for the emulator using the PATH environment variable.
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "utils/StringUtil.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
@ -122,6 +123,44 @@ namespace Utils
|
|||
return contentList;
|
||||
}
|
||||
|
||||
StringList getMatchingFiles(const std::string& pattern)
|
||||
{
|
||||
StringList files;
|
||||
size_t entry {pattern.find('*')};
|
||||
|
||||
if (entry == std::string::npos)
|
||||
return files;
|
||||
|
||||
std::string parent {getParent(pattern)};
|
||||
|
||||
// Don't allow wildcard matching for the parent directory.
|
||||
if (entry <= parent.size())
|
||||
return files;
|
||||
|
||||
StringList dirContent {getDirContent(parent)};
|
||||
|
||||
if (dirContent.size() == 0)
|
||||
return files;
|
||||
|
||||
std::regex expression;
|
||||
|
||||
try {
|
||||
expression = Utils::String::replace(pattern, "*", ".*");
|
||||
}
|
||||
catch (...) {
|
||||
LOG(LogError) << "FileSystemUtil::getMatchingFiles(): Invalid regular expression "
|
||||
<< "\"" << pattern << "\"";
|
||||
return files;
|
||||
}
|
||||
|
||||
for (auto& dir : dirContent) {
|
||||
if (std::regex_match(dir, expression))
|
||||
files.emplace_back(dir);
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
StringList getPathList(const std::string& path)
|
||||
{
|
||||
StringList pathList;
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace Utils
|
|||
using StringList = std::list<std::string>;
|
||||
|
||||
StringList getDirContent(const std::string& path, const bool recursive = false);
|
||||
StringList getMatchingFiles(const std::string& pattern);
|
||||
StringList getPathList(const std::string& path);
|
||||
void setHomePath(const std::string& path);
|
||||
std::string getHomePath();
|
||||
|
|
Loading…
Reference in a new issue