mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-12 17:58:53 +01:00
Added support for directory hierarchy in the roms when list.includeMissingItems = false. When list.includeMissingItems = true, the rom directory doesn't get taken into account.
This commit is contained in:
parent
9967c8063f
commit
ecaad97a41
@ -276,8 +276,6 @@ bool CollectionInfoBuilder::ImportBasicList(CollectionInfo *info, std::string fi
|
||||
|
||||
bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string mergedCollectionName)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
std::string path = info->listpath;
|
||||
std::vector<Item *> includeFilterUnsorted;
|
||||
std::map<std::string, Item *> includeFilter;
|
||||
@ -309,19 +307,6 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
|
||||
ImportBasicList(info, excludeFile, excludeFilter);
|
||||
}
|
||||
|
||||
std::vector<std::string> extensions;
|
||||
std::vector<std::string>::iterator extensionsIt;
|
||||
|
||||
info->extensionList(extensions);
|
||||
|
||||
dp = opendir(path.c_str());
|
||||
|
||||
Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Scanning directory \"" + path + "\"");
|
||||
if(dp == NULL)
|
||||
{
|
||||
Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Could not read directory \"" + path + "\". Ignore if this is a menu.");
|
||||
}
|
||||
|
||||
if (showMissing)
|
||||
{
|
||||
for(std::vector<Item *>::iterator it = includeFilterUnsorted.begin(); it != includeFilterUnsorted.end(); ++it)
|
||||
@ -333,44 +318,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
|
||||
}
|
||||
}
|
||||
|
||||
while(!showMissing && dp != NULL && (dirp = readdir(dp)) != NULL)
|
||||
// Read ROM directory if showMissing is false
|
||||
if (!showMissing)
|
||||
{
|
||||
std::string file = dirp->d_name;
|
||||
|
||||
size_t position = file.find_last_of(".");
|
||||
std::string basename = (std::string::npos == position)? file : file.substr(0, position);
|
||||
|
||||
// if there is an include list, only include roms that are found and are in the include list
|
||||
// if there is an exclude list, exclude those roms
|
||||
if((includeFilter.size() == 0 || (!showMissing && includeFilter.find(basename) != includeFilter.end())) &&
|
||||
(excludeFilter.size() == 0 || excludeFilter.find(basename) == excludeFilter.end()))
|
||||
{
|
||||
// iterate through all known file extensions
|
||||
for(extensionsIt = extensions.begin(); extensionsIt != extensions.end(); ++extensionsIt)
|
||||
{
|
||||
std::string comparator = "." + *extensionsIt;
|
||||
int start = file.length() - comparator.length() + 1;
|
||||
|
||||
if(start >= 0)
|
||||
{
|
||||
if(file.compare(start, comparator.length(), *extensionsIt) == 0)
|
||||
{
|
||||
Item *i = new Item();
|
||||
i->name = basename;
|
||||
i->fullTitle = basename;
|
||||
i->title = basename;
|
||||
i->collectionInfo = info;
|
||||
|
||||
info->items.push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dp != NULL)
|
||||
{
|
||||
closedir(dp);
|
||||
ImportRomDirectory(path, info, includeFilter, excludeFilter);
|
||||
}
|
||||
|
||||
while(includeFilter.size() > 0)
|
||||
@ -432,6 +383,78 @@ void CollectionInfoBuilder::addFavorites(CollectionInfo *info)
|
||||
}
|
||||
|
||||
|
||||
void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo *info, std::map<std::string, Item *> includeFilter, std::map<std::string, Item *> excludeFilter)
|
||||
{
|
||||
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
std::vector<std::string> extensions;
|
||||
std::vector<std::string>::iterator extensionsIt;
|
||||
|
||||
info->extensionList(extensions);
|
||||
|
||||
dp = opendir(path.c_str());
|
||||
|
||||
Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Scanning directory \"" + path + "\"");
|
||||
if (dp == NULL)
|
||||
{
|
||||
Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Could not read directory \"" + path + "\". Ignore if this is a menu.");
|
||||
}
|
||||
|
||||
while(dp != NULL && (dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
std::string file = dirp->d_name;
|
||||
|
||||
// Check if the file is a directory or a file
|
||||
struct stat sb;
|
||||
if (file != "." && file != ".." && stat( Utils::combinePath( path, file ).c_str(), &sb ) == 0 && S_ISDIR( sb.st_mode ))
|
||||
{
|
||||
ImportRomDirectory( Utils::combinePath( path, file ), info, includeFilter, excludeFilter );
|
||||
}
|
||||
else if (file != "." && file != "..")
|
||||
{
|
||||
size_t position = file.find_last_of(".");
|
||||
std::string basename = (std::string::npos == position)? file : file.substr(0, position);
|
||||
|
||||
// if there is an include list, only include roms that are found and are in the include list
|
||||
// if there is an exclude list, exclude those roms
|
||||
if ((includeFilter.size() == 0 || (includeFilter.find(basename) != includeFilter.end())) &&
|
||||
(excludeFilter.size() == 0 || excludeFilter.find(basename) == excludeFilter.end()))
|
||||
{
|
||||
// iterate through all known file extensions
|
||||
for(extensionsIt = extensions.begin(); extensionsIt != extensions.end(); ++extensionsIt)
|
||||
{
|
||||
std::string comparator = "." + *extensionsIt;
|
||||
int start = file.length() - comparator.length() + 1;
|
||||
|
||||
if (start >= 0)
|
||||
{
|
||||
if (file.compare(start, comparator.length(), *extensionsIt) == 0)
|
||||
{
|
||||
Item *i = new Item();
|
||||
|
||||
i->name = basename;
|
||||
i->fullTitle = basename;
|
||||
i->title = basename;
|
||||
i->collectionInfo = info;
|
||||
i->filepath = path + Utils::pathSeparator;
|
||||
|
||||
info->items.push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dp != NULL)
|
||||
{
|
||||
closedir(dp);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CollectionInfoBuilder::injectMetadata(CollectionInfo *info)
|
||||
|
||||
@ -41,4 +41,5 @@ private:
|
||||
bool ImportBasicList(CollectionInfo *info, std::string file, std::map<std::string, Item *> &list);
|
||||
bool ImportBasicList(CollectionInfo *info, std::string file, std::vector<Item *> &list);
|
||||
bool ImportDirectory(CollectionInfo *info, std::string mergedCollectionName);
|
||||
void ImportRomDirectory(std::string path, CollectionInfo *info, std::map<std::string, Item *> includeFilter, std::map<std::string, Item *> excludeFilter);
|
||||
};
|
||||
|
||||
@ -67,6 +67,13 @@ bool Launcher::run(std::string collection, Item *collectionItem)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Overwrite selectedItemsDirectory if already set in the file
|
||||
if (collectionItem->filepath != "")
|
||||
{
|
||||
selectedItemsDirectory = collectionItem->filepath;
|
||||
}
|
||||
|
||||
// It is ok to continue if the file could not be found. We could be launching a merged romset
|
||||
findFile(selectedItemsPath, matchedExtension, selectedItemsDirectory, collectionItem->name, extensionstr);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user