Added proper support for interpreting directories as files.

This commit is contained in:
Leon Styhre 2021-12-17 20:18:47 +01:00
parent 3e28bacdcf
commit daf66c4b60
6 changed files with 78 additions and 17 deletions

View file

@ -298,15 +298,22 @@ bool SystemData::populateFolder(FileData* folder)
// We first get the extension of the file itself: // We first get the extension of the file itself:
extension = Utils::FileSystem::getExtension(filePath); extension = Utils::FileSystem::getExtension(filePath);
// FYI, folders *can* also match the extension and be added as games.
// This is mostly just to support higan.
// See issue #75: https://github.com/Aloshi/EmulationStation/issues/75
isGame = false; isGame = false;
if (std::find(mEnvData->mSearchExtensions.cbegin(), mEnvData->mSearchExtensions.cend(), if (std::find(mEnvData->mSearchExtensions.cbegin(), mEnvData->mSearchExtensions.cend(),
extension) != mEnvData->mSearchExtensions.cend()) { extension) != mEnvData->mSearchExtensions.cend()) {
FileData* newGame = new FileData(GAME, filePath, mEnvData, this); FileData* newGame = new FileData(GAME, filePath, mEnvData, this);
// If adding a configured file extension to a directory it will get interpreted as
// a regular file. This is useful for some emulators that can get directories passed
// to them as command line parameters instead of regular files. In these instances
// we remove the extension from the metadata name so it does not show up in the
// gamelists and similar.
if (Utils::FileSystem::isDirectory(filePath)) {
const std::string folderName = newGame->metadata.get("name");
newGame->metadata.set(
"name", folderName.substr(0, folderName.length() - extension.length()));
}
// Prevent new arcade assets from being added. // Prevent new arcade assets from being added.
if (!newGame->isArcadeAsset()) { if (!newGame->isArcadeAsset()) {
folder->addChild(newGame); folder->addChild(newGame);

View file

@ -385,6 +385,11 @@ void GuiGamelistOptions::openMetaDataEd()
LOG(LogInfo) << "Deleting the media files and gamelist.xml entry for the folder \"" LOG(LogInfo) << "Deleting the media files and gamelist.xml entry for the folder \""
<< file->getFullPath() << "\""; << file->getFullPath() << "\"";
} }
else if (file->getType() == GAME && Utils::FileSystem::isDirectory(file->getFullPath())) {
LOG(LogInfo) << "Deleting the media files and gamelist.xml entry for the "
"file-interpreted folder \""
<< file->getFullPath() << "\"";
}
else { else {
LOG(LogInfo) << "Deleting the media files and gamelist.xml entry for the file \"" LOG(LogInfo) << "Deleting the media files and gamelist.xml entry for the file \""
<< file->getFullPath() << "\""; << file->getFullPath() << "\"";
@ -408,6 +413,11 @@ void GuiGamelistOptions::openMetaDataEd()
file->metadata.set(it->key, it->defaultValue); file->metadata.set(it->key, it->defaultValue);
} }
// For the special case where a directory has a supported file extension and is therefore
// interpreted as a file, don't include the extension in the metadata name.
if (file->getType() == GAME && Utils::FileSystem::isDirectory(file->getFullPath()))
file->metadata.set("name", Utils::FileSystem::getStem(file->metadata.get("name")));
// Update all collections where the game is present. // Update all collections where the game is present.
if (file->getType() == GAME) if (file->getType() == GAME)
CollectionSystemsManager::get()->refreshCollectionSystems(file, true); CollectionSystemsManager::get()->refreshCollectionSystems(file, true);

View file

@ -429,11 +429,19 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
// If the user has entered a blank game name, then set the name to the ROM // If the user has entered a blank game name, then set the name to the ROM
// filename (minus the extension). // filename (minus the extension).
if (currentKey == "name" && newVal == "") { if (currentKey == "name" && newVal == "") {
if (scraperParams.game->isArcadeGame()) if (scraperParams.game->isArcadeGame()) {
ed->setValue(MameNames::getInstance().getCleanName( ed->setValue(MameNames::getInstance().getCleanName(
scraperParams.game->getCleanName())); scraperParams.game->getCleanName()));
else }
ed->setValue(gamePath); else {
// For the special case where a directory has a supported file extension
// and is therefore interpreted as a file, exclude the extension.
if (scraperParams.game->getType() == GAME &&
Utils::FileSystem::isDirectory(scraperParams.game->getFullPath()))
ed->setValue(Utils::FileSystem::getStem(gamePath));
else
ed->setValue(gamePath);
}
if (gamePath == originalValue) if (gamePath == originalValue)
ed->setColor(DEFAULT_TEXTCOLOR); ed->setColor(DEFAULT_TEXTCOLOR);
else else
@ -546,7 +554,9 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
clearSelfBtnFunc)); clearSelfBtnFunc));
} }
if (mDeleteGameFunc) { // For the special case where a directory has a supported file extension and is therefore
// interpreted as a file, don't add the delete button.
if (mDeleteGameFunc && !Utils::FileSystem::isDirectory(scraperParams.game->getPath())) {
auto deleteFilesAndSelf = [&] { auto deleteFilesAndSelf = [&] {
mDeleteGameFunc(); mDeleteGameFunc();
delete this; delete this;

View file

@ -823,10 +823,20 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params)
// in case the scraper is set to TheGamesDB and it's an arcade game. This is // in case the scraper is set to TheGamesDB and it's an arcade game. This is
// required as TheGamesDB does not support searches using the short MAME names. // required as TheGamesDB does not support searches using the short MAME names.
if (params.game->isArcadeGame() && if (params.game->isArcadeGame() &&
Settings::getInstance()->getString("Scraper") == "thegamesdb") Settings::getInstance()->getString("Scraper") == "thegamesdb") {
searchString = MameNames::getInstance().getCleanName(params.game->getCleanName()); searchString = MameNames::getInstance().getCleanName(params.game->getCleanName());
else }
searchString = params.game->getCleanName(); else {
if (params.game->getType() == GAME &&
Utils::FileSystem::isDirectory(params.game->getFullPath())) {
// For the special case where a directory has a supported file extension and is
// therefore interpreted as a file, exclude the extension from the search.
searchString = Utils::FileSystem::getStem(params.game->getCleanName());
}
else {
searchString = params.game->getCleanName();
}
}
} }
} }
else { else {

View file

@ -156,10 +156,21 @@ void thegamesdb_generate_json_scraper_requests(
// If not searching based on the metadata name, then check whether it's an // If not searching based on the metadata name, then check whether it's an
// arcade game and if so expand to the full game name. This is required as // arcade game and if so expand to the full game name. This is required as
// TheGamesDB has issues with searching using the short MAME names. // TheGamesDB has issues with searching using the short MAME names.
if (params.game->isArcadeGame()) if (params.game->isArcadeGame()) {
cleanName = MameNames::getInstance().getCleanName(params.game->getCleanName()); cleanName = MameNames::getInstance().getCleanName(params.game->getCleanName());
else }
cleanName = params.game->getCleanName(); else {
if (params.game->getType() == GAME &&
Utils::FileSystem::isDirectory(params.game->getFullPath())) {
// For the special case where a directory has a supported file extension
// and is therefore interpreted as a file, exclude the extension from the
// search.
cleanName = Utils::FileSystem::getStem(params.game->getCleanName());
}
else {
cleanName = params.game->getCleanName();
}
}
} }
} }

View file

@ -181,11 +181,24 @@ void screenscraper_generate_scraper_requests(const ScraperSearchParams& params,
ssConfig.isArcadeSystem = false; ssConfig.isArcadeSystem = false;
if (params.nameOverride == "") { if (params.nameOverride == "") {
if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) {
path = ssConfig.getGameSearchUrl( path = ssConfig.getGameSearchUrl(
Utils::String::removeParenthesis(params.game->metadata.get("name"))); Utils::String::removeParenthesis(params.game->metadata.get("name")));
else }
path = ssConfig.getGameSearchUrl(params.game->getCleanName()); else {
std::string cleanName;
if (params.game->getType() == GAME &&
Utils::FileSystem::isDirectory(params.game->getFullPath())) {
// For the special case where a directory has a supported file extension and is
// therefore interpreted as a file, exclude the extension from the search.
cleanName = Utils::FileSystem::getStem(params.game->getCleanName());
}
else {
cleanName = params.game->getCleanName();
}
path = ssConfig.getGameSearchUrl(cleanName);
}
} }
else { else {
path = ssConfig.getGameSearchUrl(params.nameOverride); path = ssConfig.getGameSearchUrl(params.nameOverride);