Fixed multiple issues with hidden games.

This commit is contained in:
Leon Styhre 2020-11-08 18:33:28 +01:00
parent 56ae90cc67
commit 3aa10177cf
3 changed files with 49 additions and 7 deletions

View file

@ -431,12 +431,30 @@ void FileData::sort(ComparisonFunction& comparator, bool ascending,
mOnlyFolders = true;
mHasFolders = false;
bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
bool showHiddenGames = Settings::getInstance()->getBool("ShowHiddenGames");
std::vector<FileData*> mChildrenFolders;
std::vector<FileData*> mChildrenOthers;
if (mSystem->isGroupedCustomCollection())
gameCount = {};
if (!showHiddenGames) {
for (auto it = mChildren.begin(); it != mChildren.end();) {
// If the option to hide hidden games has been set and the game is hidden,
// then skip it. Normally games are hidden during loading of the gamelists in
// Gamelist::parseGamelist() and this code should only run when a user has marked
// an entry manually as hidden. So upon the next application startup, this game
// should be filtered already at that earlier point.
if ((*it)->getHidden())
it = mChildren.erase(it);
// Also hide folders where all its entries have been hidden.
else if ((*it)->getType() == FOLDER && (*it)->getChildren().size() == 0)
it = mChildren.erase(it);
else
it++;
}
}
// The main custom collections view is sorted during startup in CollectionSystemManager.
// The individual collections are however sorted as any normal systems/folders.
if (mSystem->isCollection() && mSystem->getFullName() == "collections") {
@ -524,11 +542,12 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending
{
mOnlyFolders = true;
mHasFolders = false;
bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
bool showHiddenGames = Settings::getInstance()->getBool("ShowHiddenGames");
std::vector<FileData*> mChildrenFolders;
std::vector<FileData*> mChildrenFavoritesFolders;
std::vector<FileData*> mChildrenFavorites;
std::vector<FileData*> mChildrenOthers;
bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
if (mSystem->isGroupedCustomCollection())
gameCount = {};
@ -549,6 +568,17 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending
}
for (unsigned int i = 0; i < mChildren.size(); i++) {
// If the option to hide hidden games has been set and the game is hidden,
// then skip it. Normally games are hidden during loading of the gamelists in
// Gamelist::parseGamelist() and this code should only run when a user has marked
// an entry manually as hidden. So upon the next application startup, this game
// should be filtered already at that earlier point.
if (!showHiddenGames && mChildren[i]->getHidden())
continue;
// Also hide folders where all its entries have been hidden.
else if (mChildren[i]->getType() == FOLDER && mChildren[i]->getChildren().size() == 0)
continue;
// Game count, which will be displayed in the system view.
if (mChildren[i]->getType() == GAME && mChildren[i]->getCountAsGame()) {
if (!mChildren[i]->getFavorite())

View file

@ -164,12 +164,18 @@ void parseGamelist(SystemData* system)
// games, then delete the entry. This leaves no trace of the entry at all in ES
// but that is fine as the option to show hidden files is defined as requiring an
// application restart.
if (!Settings::getInstance()->getBool("ShowHiddenGames") && file->getHidden()) {
if (!Settings::getInstance()->getBool("ShowHiddenGames")) {
if (file->getHidden()) {
LOG(LogDebug) << "Gamelist::parseGamelist(): Skipping hidden " <<
(type == GAME ? "file" : "folder") << " entry \"" <<
file->getName() << "\"" << " (\"" << file->getPath() << "\")";
delete file;
}
// Also delete any folders which are empty, i.e. all their entries are hidden.
else if (file->getType() == FOLDER && file->getChildren().size() == 0) {
delete file;
}
}
}
}
}

View file

@ -352,7 +352,7 @@ void GuiMetaDataEd::save()
mMetaData->set(mMetaDataDecl.at(i).key, mEditors.at(i)->getValue());
}
// If hidden games are not shown and the hide flag was set for the game, then write the
// If hidden games are not shown and the hide flag was set for the entry, then write the
// metadata immediately regardless of the SaveGamelistsMode setting. Otherwise the file
// will never be written as the game will be filtered from the gamelist. This solution is not
// really good as the gamelist will be written twice, but it's a very special and hopefully
@ -376,6 +376,12 @@ void GuiMetaDataEd::save()
mScraperParams.system->onMetaDataSavePoint();
// If hidden games are not shown and the hide flag was set for the entry, we also need
// to re-sort the gamelist as we may need to remove the parent folder if all the entries
// within this folder are now hidden.
if (hideGameWhileHidden)
mScraperParams.system->sortSystem(true);
// Make sure that the cached background is updated to reflect any possible visible
// changes to the gamelist (e.g. the game name).
mWindow->invalidateCachedBackground();