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,6 +446,7 @@ const bool FileData::isArcadeGame() const
void FileData::addChild(FileData* file)
{
assert(mType == FOLDER);
if (!mSystem->getFlattenFolders())
assert(file->getParent() == nullptr);
const std::string key = file->getKey();

View file

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

View file

@ -185,17 +185,18 @@ SystemData::SystemData(const std::string& name,
const std::string& themeFolder,
bool CollectionSystem,
bool CustomCollectionSystem)
: mName(name)
, mFullName(fullName)
, mSortName(sortName)
, mEnvData(envData)
, mThemeFolder(themeFolder)
, mIsCollectionSystem(CollectionSystem)
, mIsCustomCollectionSystem(CustomCollectionSystem)
, mIsGroupedCustomCollectionSystem(false)
, mIsGameSystem(true)
, mScrapeFlag(false)
, mPlaceholder(nullptr)
: mName {name}
, mFullName {fullName}
, mSortName {sortName}
, mEnvData {envData}
, mThemeFolder {themeFolder}
, mIsCollectionSystem {CollectionSystem}
, mIsCustomCollectionSystem {CustomCollectionSystem}
, mIsGroupedCustomCollectionSystem {false}
, mIsGameSystem {true}
, mScrapeFlag {false}
, mFlattenFolders {false}
, mPlaceholder {nullptr}
{
mFilterIndex = new FileFilterIndex();
@ -271,6 +272,13 @@ bool SystemData::populateFolder(FileData* folder)
if (dirContent.size() == 0)
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();
it != dirContent.cend(); ++it) {
filePath = *it;
@ -344,6 +352,11 @@ bool SystemData::populateFolder(FileData* folder)
FileData* newFolder = new FileData(FOLDER, filePath, mEnvData, this);
populateFolder(newFolder);
if (mFlattenFolders) {
for (auto& entry : newFolder->getChildrenByFilename())
folder->addChild(entry.second);
}
else {
// Ignore folders that do not contain games.
if (newFolder->getChildrenByFilename().size() == 0)
delete newFolder;
@ -351,6 +364,7 @@ bool SystemData::populateFolder(FileData* folder)
folder->addChild(newFolder);
}
}
}
return true;
}

View file

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