Added experimental support for folder flattening.

This commit is contained in:
Leon Styhre 2022-05-18 19:47:51 +02:00
parent 43191e4005
commit 9ee56da021
4 changed files with 42 additions and 23 deletions

View file

@ -446,7 +446,8 @@ const bool FileData::isArcadeGame() const
void FileData::addChild(FileData* file) void FileData::addChild(FileData* file)
{ {
assert(mType == FOLDER); assert(mType == FOLDER);
assert(file->getParent() == nullptr); if (!mSystem->getFlattenFolders())
assert(file->getParent() == nullptr);
const std::string key = file->getKey(); const std::string key = file->getKey();
if (mChildrenByFilename.find(key) == mChildrenByFilename.cend()) { if (mChildrenByFilename.find(key) == mChildrenByFilename.cend()) {

View file

@ -85,12 +85,14 @@ namespace GamelistFileParser
return nullptr; return nullptr;
} }
// Create missing folder. if (!system->getFlattenFolders()) {
FileData* folder = new FileData( // Create missing folder.
FOLDER, Utils::FileSystem::getStem(treeNode->getPath()) + "/" + *path_it, FileData* folder {new FileData(
system->getSystemEnvData(), system); FOLDER, Utils::FileSystem::getStem(treeNode->getPath()) + "/" + *path_it,
treeNode->addChild(folder); system->getSystemEnvData(), system)};
treeNode = folder; treeNode->addChild(folder);
treeNode = folder;
}
} }
++path_it; ++path_it;

View file

@ -185,17 +185,18 @@ SystemData::SystemData(const std::string& name,
const std::string& themeFolder, const std::string& themeFolder,
bool CollectionSystem, bool CollectionSystem,
bool CustomCollectionSystem) bool CustomCollectionSystem)
: mName(name) : mName {name}
, mFullName(fullName) , mFullName {fullName}
, mSortName(sortName) , mSortName {sortName}
, mEnvData(envData) , mEnvData {envData}
, mThemeFolder(themeFolder) , mThemeFolder {themeFolder}
, mIsCollectionSystem(CollectionSystem) , mIsCollectionSystem {CollectionSystem}
, mIsCustomCollectionSystem(CustomCollectionSystem) , mIsCustomCollectionSystem {CustomCollectionSystem}
, mIsGroupedCustomCollectionSystem(false) , mIsGroupedCustomCollectionSystem {false}
, mIsGameSystem(true) , mIsGameSystem {true}
, mScrapeFlag(false) , mScrapeFlag {false}
, mPlaceholder(nullptr) , mFlattenFolders {false}
, mPlaceholder {nullptr}
{ {
mFilterIndex = new FileFilterIndex(); mFilterIndex = new FileFilterIndex();
@ -271,6 +272,13 @@ bool SystemData::populateFolder(FileData* folder)
if (dirContent.size() == 0) if (dirContent.size() == 0)
return false; return false;
if (std::find(dirContent.cbegin(), dirContent.cend(), mEnvData->mStartPath + "/flatten.txt") !=
dirContent.cend()) {
LOG(LogInfo) << "A flatten.txt file is present for the \"" << mName
<< "\" system, folder flattening will be applied";
mFlattenFolders = true;
}
for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin(); for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin();
it != dirContent.cend(); ++it) { it != dirContent.cend(); ++it) {
filePath = *it; filePath = *it;
@ -344,11 +352,17 @@ bool SystemData::populateFolder(FileData* folder)
FileData* newFolder = new FileData(FOLDER, filePath, mEnvData, this); FileData* newFolder = new FileData(FOLDER, filePath, mEnvData, this);
populateFolder(newFolder); populateFolder(newFolder);
// Ignore folders that do not contain games. if (mFlattenFolders) {
if (newFolder->getChildrenByFilename().size() == 0) for (auto& entry : newFolder->getChildrenByFilename())
delete newFolder; folder->addChild(entry.second);
else }
folder->addChild(newFolder); else {
// Ignore folders that do not contain games.
if (newFolder->getChildrenByFilename().size() == 0)
delete newFolder;
else
folder->addChild(newFolder);
}
} }
} }
return true; return true;

View file

@ -97,6 +97,7 @@ public:
std::string getThemePath() const; std::string getThemePath() const;
std::pair<unsigned int, unsigned int> getDisplayedGameCount() const; std::pair<unsigned int, unsigned int> getDisplayedGameCount() const;
const bool getFlattenFolders() const { return mFlattenFolders; }
const bool getScrapeFlag() const { return mScrapeFlag; } const bool getScrapeFlag() const { return mScrapeFlag; }
void setScrapeFlag(bool scrapeflag) { mScrapeFlag = scrapeflag; } void setScrapeFlag(bool scrapeflag) { mScrapeFlag = scrapeflag; }
@ -156,6 +157,7 @@ private:
bool mIsGroupedCustomCollectionSystem; bool mIsGroupedCustomCollectionSystem;
bool mIsGameSystem; bool mIsGameSystem;
bool mScrapeFlag; // Only used by scraper GUI to remember which systems to scrape. bool mScrapeFlag; // Only used by scraper GUI to remember which systems to scrape.
bool mFlattenFolders;
bool populateFolder(FileData* folder); bool populateFolder(FileData* folder);
void indexAllGameFilters(const FileData* folder); void indexAllGameFilters(const FileData* folder);