Fixed a crash when attempting to use extension-less files in gamelists containing folders.

This commit is contained in:
Leon Styhre 2022-12-14 17:56:50 +01:00
parent 715c143324
commit d692e8f9cd
2 changed files with 16 additions and 2 deletions

View file

@ -38,6 +38,19 @@ namespace GamelistFileParser
bool found {false};
while (path_it != pathList.end()) {
// Workaround for an extremely rare issue that can basically only happen if a dot (.)
// has been defined as a valid extension for the system (meaning extension-less files
// are loaded), in combination with the "Only show ROMs from gamelist.xml files" option
// being enabled and a stale entry being present in the gamelist.xml file that perfectly
// matches a folder which is actually in use. The workaround is not a perfect solution
// but it at least prevents the application from crashing.
if (treeNode->getType() != FOLDER) {
LOG(LogWarning)
<< "Invalid gamelist entry caused by folder having the same name as a stale "
<< "extension-less game file (this may cause undefined behavior):";
return nullptr;
}
const std::unordered_map<std::string, FileData*>& children {
treeNode->getChildrenByFilename()};

View file

@ -319,7 +319,8 @@ bool SystemData::populateFolder(FileData* folder)
isGame = false;
if (std::find(mEnvData->mSearchExtensions.cbegin(), mEnvData->mSearchExtensions.cend(),
extension) != mEnvData->mSearchExtensions.cend()) {
extension) != mEnvData->mSearchExtensions.cend() &&
!(isDirectory && extension == ".")) {
FileData* newGame {new FileData(GAME, filePath, mEnvData, this)};
// If adding a configured file extension to a directory it will get interpreted as
@ -327,7 +328,7 @@ bool SystemData::populateFolder(FileData* folder)
// entries or for 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 (isDirectory) {
if (isDirectory && extension != ".") {
const std::string& folderName {newGame->metadata.get("name")};
newGame->metadata.set(
"name", folderName.substr(0, folderName.length() - extension.length()));