2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-22 15:27:53 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-22 15:27:53 +00:00
|
|
|
// FileFilterIndex.cpp
|
|
|
|
//
|
|
|
|
// Gamelist filters.
|
|
|
|
//
|
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
#include "FileFilterIndex.h"
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
#include "math/Misc.h"
|
2017-11-29 19:57:43 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2017-11-18 22:23:56 +00:00
|
|
|
#include "views/UIModeController.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "FileData.h"
|
|
|
|
#include "Log.h"
|
2017-11-18 22:23:56 +00:00
|
|
|
#include "Settings.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
#define UNKNOWN_LABEL "UNKNOWN"
|
|
|
|
#define INCLUDE_UNKNOWN false;
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
FileFilterIndex::FileFilterIndex()
|
2020-11-08 15:34:33 +00:00
|
|
|
: mFilterByText(false),
|
|
|
|
filterByFavorites(false),
|
2020-06-22 15:27:53 +00:00
|
|
|
filterByGenre(false),
|
|
|
|
filterByPlayers(false),
|
|
|
|
filterByPubDev(false),
|
2020-10-27 19:58:42 +00:00
|
|
|
filterByRatings(false),
|
|
|
|
filterByKidGame(false),
|
|
|
|
filterByCompleted(false),
|
|
|
|
filterByBroken(false),
|
|
|
|
filterByHidden(false)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
clearAllFilters();
|
|
|
|
|
|
|
|
FilterDataDecl filterDecls[] = {
|
|
|
|
//type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel
|
2020-10-27 19:58:42 +00:00
|
|
|
{ FAVORITES_FILTER, &favoritesIndexAllKeys, &filterByFavorites, &favoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES" },
|
|
|
|
{ GENRE_FILTER, &genreIndexAllKeys, &filterByGenre, &genreIndexFilteredKeys, "genre", true, "genre", "GENRE" },
|
|
|
|
{ PLAYER_FILTER, &playersIndexAllKeys, &filterByPlayers, &playersIndexFilteredKeys, "players", false, "", "PLAYERS" },
|
|
|
|
{ PUBDEV_FILTER, &pubDevIndexAllKeys, &filterByPubDev, &pubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER" },
|
|
|
|
{ RATINGS_FILTER, &ratingsIndexAllKeys, &filterByRatings, &ratingsIndexFilteredKeys, "rating", false, "", "RATING" },
|
|
|
|
{ KIDGAME_FILTER, &kidGameIndexAllKeys, &filterByKidGame, &kidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME" },
|
|
|
|
{ COMPLETED_FILTER, &completedIndexAllKeys, &filterByCompleted, &completedIndexFilteredKeys, "completed", false, "", "COMPLETED" },
|
|
|
|
{ BROKEN_FILTER, &brokenIndexAllKeys, &filterByBroken, &brokenIndexFilteredKeys, "broken", false, "", "BROKEN" },
|
|
|
|
{ HIDDEN_FILTER, &hiddenIndexAllKeys, &filterByHidden, &hiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN" }
|
2020-06-22 15:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
filterDataDecl = std::vector<FilterDataDecl>(filterDecls, filterDecls +
|
|
|
|
sizeof(filterDecls) / sizeof(filterDecls[0]));
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileFilterIndex::~FileFilterIndex()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
resetIndex();
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
std::vector<FilterDataDecl>& FileFilterIndex::getFilterDataDecls()
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
return filterDataDecl;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void FileFilterIndex::importIndex(FileFilterIndex* indexToImport)
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
struct IndexImportStructure {
|
|
|
|
std::map<std::string, int>* destinationIndex;
|
|
|
|
std::map<std::string, int>* sourceIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
IndexImportStructure indexStructDecls[] = {
|
2020-10-27 19:58:42 +00:00
|
|
|
{ &favoritesIndexAllKeys, &(indexToImport->favoritesIndexAllKeys) },
|
2020-06-22 15:27:53 +00:00
|
|
|
{ &genreIndexAllKeys, &(indexToImport->genreIndexAllKeys) },
|
|
|
|
{ &playersIndexAllKeys, &(indexToImport->playersIndexAllKeys) },
|
|
|
|
{ &pubDevIndexAllKeys, &(indexToImport->pubDevIndexAllKeys) },
|
|
|
|
{ &ratingsIndexAllKeys, &(indexToImport->ratingsIndexAllKeys) },
|
|
|
|
{ &kidGameIndexAllKeys, &(indexToImport->kidGameIndexAllKeys) },
|
2020-10-27 19:58:42 +00:00
|
|
|
{ &completedIndexAllKeys, &(indexToImport->completedIndexAllKeys) },
|
|
|
|
{ &brokenIndexAllKeys, &(indexToImport->brokenIndexAllKeys) },
|
|
|
|
{ &hiddenIndexAllKeys, &(indexToImport->hiddenIndexAllKeys) },
|
2020-06-22 15:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<IndexImportStructure> indexImportDecl =
|
|
|
|
std::vector<IndexImportStructure>(indexStructDecls, indexStructDecls +
|
|
|
|
sizeof(indexStructDecls) / sizeof(indexStructDecls[0]));
|
|
|
|
|
|
|
|
for (std::vector<IndexImportStructure>::const_iterator indexesIt =
|
|
|
|
indexImportDecl.cbegin(); indexesIt != indexImportDecl.cend(); ++indexesIt )
|
|
|
|
{
|
|
|
|
for (std::map<std::string, int>::const_iterator sourceIt =
|
|
|
|
(*indexesIt).sourceIndex->cbegin(); sourceIt !=
|
|
|
|
(*indexesIt).sourceIndex->cend(); ++sourceIt ) {
|
|
|
|
if ((*indexesIt).destinationIndex->find((*sourceIt).first) ==
|
|
|
|
(*indexesIt).destinationIndex->cend())
|
|
|
|
// Entry doesn't exist.
|
|
|
|
(*((*indexesIt).destinationIndex))[(*sourceIt).first] = (*sourceIt).second;
|
|
|
|
else
|
|
|
|
(*((*indexesIt).destinationIndex))[(*sourceIt).first] += (*sourceIt).second;
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2020-06-22 15:27:53 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void FileFilterIndex::resetIndex()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
clearAllFilters();
|
2020-10-27 19:58:42 +00:00
|
|
|
clearIndex(favoritesIndexAllKeys);
|
2020-06-22 15:27:53 +00:00
|
|
|
clearIndex(genreIndexAllKeys);
|
|
|
|
clearIndex(playersIndexAllKeys);
|
|
|
|
clearIndex(pubDevIndexAllKeys);
|
|
|
|
clearIndex(ratingsIndexAllKeys);
|
|
|
|
clearIndex(kidGameIndexAllKeys);
|
2020-10-27 19:58:42 +00:00
|
|
|
clearIndex(completedIndexAllKeys);
|
|
|
|
clearIndex(brokenIndexAllKeys);
|
|
|
|
clearIndex(hiddenIndexAllKeys);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string FileFilterIndex::getIndexableKey(FileData* game,
|
|
|
|
FilterIndexType type, bool getSecondary)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string key = "";
|
|
|
|
switch (type) {
|
2020-10-27 19:58:42 +00:00
|
|
|
case FAVORITES_FILTER: {
|
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
|
|
|
key = Utils::String::toUpper(game->metadata.get("favorite"));
|
|
|
|
break;
|
|
|
|
}
|
2020-06-22 15:27:53 +00:00
|
|
|
case GENRE_FILTER: {
|
|
|
|
key = Utils::String::toUpper(game->metadata.get("genre"));
|
|
|
|
key = Utils::String::trim(key);
|
|
|
|
if (getSecondary && !key.empty()) {
|
|
|
|
std::istringstream f(key);
|
|
|
|
std::string newKey;
|
|
|
|
getline(f, newKey, '/');
|
|
|
|
if (!newKey.empty() && newKey != key)
|
|
|
|
key = newKey;
|
|
|
|
else
|
|
|
|
key = std::string();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PLAYER_FILTER: {
|
|
|
|
if (getSecondary)
|
|
|
|
break;
|
|
|
|
|
2020-10-18 17:11:19 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("players"));
|
2020-06-22 15:27:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PUBDEV_FILTER: {
|
|
|
|
key = Utils::String::toUpper(game->metadata.get("publisher"));
|
|
|
|
key = Utils::String::trim(key);
|
|
|
|
|
|
|
|
if ((getSecondary && !key.empty()) || (!getSecondary && key.empty()))
|
|
|
|
key = Utils::String::toUpper(game->metadata.get("developer"));
|
|
|
|
else
|
|
|
|
key = Utils::String::toUpper(game->metadata.get("publisher"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RATINGS_FILTER: {
|
|
|
|
int ratingNumber = 0;
|
|
|
|
if (!getSecondary) {
|
|
|
|
std::string ratingString = game->metadata.get("rating");
|
|
|
|
if (!ratingString.empty()) {
|
|
|
|
try {
|
2020-10-27 19:58:42 +00:00
|
|
|
// Round up fractional values such as 0.75 to 0.8.
|
|
|
|
// These values should only exist if a third party application has
|
|
|
|
// been used for scraping the ratings, or if the gamelist.xml file
|
|
|
|
// has been manually edited.
|
|
|
|
ratingNumber = static_cast<int>(
|
|
|
|
(Math::ceilf(stof(ratingString) / 0.1) / 10) * 5);
|
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
if (ratingNumber < 0)
|
|
|
|
ratingNumber = 0;
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
if (ratingNumber == 5)
|
|
|
|
key = "5 STARS";
|
|
|
|
else
|
|
|
|
key = std::to_string(ratingNumber) + " - " +
|
|
|
|
std::to_string(ratingNumber) + ".5 STARS";
|
2020-06-22 15:27:53 +00:00
|
|
|
}
|
|
|
|
catch (int e) {
|
|
|
|
LOG(LogError) << "Error parsing Rating (invalid value, exception nr.): " <<
|
|
|
|
ratingString << ", " << e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-10-27 19:58:42 +00:00
|
|
|
case KIDGAME_FILTER: {
|
2020-06-22 15:27:53 +00:00
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
2020-10-27 19:58:42 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("kidgame"));
|
2020-06-22 15:27:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-10-27 19:58:42 +00:00
|
|
|
case COMPLETED_FILTER: {
|
2020-06-22 15:27:53 +00:00
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
2020-10-27 19:58:42 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("completed"));
|
2020-06-22 15:27:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-10-27 19:58:42 +00:00
|
|
|
case BROKEN_FILTER: {
|
2020-06-22 15:27:53 +00:00
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
2020-10-27 19:58:42 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("broken"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HIDDEN_FILTER: {
|
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
|
|
|
key = Utils::String::toUpper(game->metadata.get("hidden"));
|
2020-06-22 15:27:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-06-25 17:52:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
2020-06-22 15:27:53 +00:00
|
|
|
}
|
|
|
|
key = Utils::String::trim(key);
|
|
|
|
if (key.empty() || (type == RATINGS_FILTER && key == "0 STARS")) {
|
|
|
|
key = UNKNOWN_LABEL;
|
|
|
|
}
|
|
|
|
return key;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::addToIndex(FileData* game)
|
|
|
|
{
|
2020-10-27 19:58:42 +00:00
|
|
|
manageFavoritesEntryInIndex(game);
|
2020-06-22 15:27:53 +00:00
|
|
|
manageGenreEntryInIndex(game);
|
|
|
|
managePlayerEntryInIndex(game);
|
|
|
|
managePubDevEntryInIndex(game);
|
|
|
|
manageRatingsEntryInIndex(game);
|
|
|
|
manageKidGameEntryInIndex(game);
|
2020-10-27 19:58:42 +00:00
|
|
|
manageCompletedEntryInIndex(game);
|
|
|
|
manageBrokenEntryInIndex(game);
|
|
|
|
manageHiddenEntryInIndex(game);
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::removeFromIndex(FileData* game)
|
|
|
|
{
|
2020-10-27 19:58:42 +00:00
|
|
|
manageFavoritesEntryInIndex(game, true);
|
2020-06-22 15:27:53 +00:00
|
|
|
manageGenreEntryInIndex(game, true);
|
|
|
|
managePlayerEntryInIndex(game, true);
|
|
|
|
managePubDevEntryInIndex(game, true);
|
|
|
|
manageRatingsEntryInIndex(game, true);
|
|
|
|
manageKidGameEntryInIndex(game, true);
|
2020-10-27 19:58:42 +00:00
|
|
|
manageCompletedEntryInIndex(game, true);
|
|
|
|
manageBrokenEntryInIndex(game, true);
|
|
|
|
manageHiddenEntryInIndex(game, true);
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
void FileFilterIndex::setFilter(FilterIndexType type, std::vector<std::string>* values)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
// Test if it exists before setting.
|
|
|
|
if (type == NONE) {
|
|
|
|
clearAllFilters();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin();
|
|
|
|
it != filterDataDecl.cend(); ++it ) {
|
|
|
|
if ((*it).type == type) {
|
|
|
|
FilterDataDecl filterData = (*it);
|
|
|
|
*(filterData.filteredByRef) = values->size() > 0;
|
|
|
|
filterData.currentFilteredKeys->clear();
|
|
|
|
for (std::vector<std::string>::const_iterator vit =
|
|
|
|
values->cbegin(); vit != values->cend(); ++vit ) {
|
2020-10-27 19:58:42 +00:00
|
|
|
// Check if it exists.
|
2020-06-22 15:27:53 +00:00
|
|
|
if (filterData.allIndexKeys->find(*vit) != filterData.allIndexKeys->cend()) {
|
|
|
|
filterData.currentFilteredKeys->push_back(std::string(*vit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-08 15:34:33 +00:00
|
|
|
void FileFilterIndex::setTextFilter(std::string textFilter)
|
|
|
|
{
|
|
|
|
mTextFilter = textFilter;
|
|
|
|
|
|
|
|
if (textFilter == "")
|
|
|
|
mFilterByText = false;
|
|
|
|
else
|
|
|
|
mFilterByText = true;
|
|
|
|
};
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
void FileFilterIndex::clearAllFilters()
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin();
|
|
|
|
it != filterDataDecl.cend(); ++it ) {
|
|
|
|
FilterDataDecl filterData = (*it);
|
|
|
|
*(filterData.filteredByRef) = false;
|
|
|
|
filterData.currentFilteredKeys->clear();
|
|
|
|
}
|
|
|
|
return;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:20:07 +00:00
|
|
|
void FileFilterIndex::resetFilters()
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
clearAllFilters();
|
|
|
|
setUIModeFilters();
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::setUIModeFilters()
|
|
|
|
{
|
2020-11-05 17:18:11 +00:00
|
|
|
if (Settings::getInstance()->getBool("GamelistFilters")){
|
2020-06-22 15:27:53 +00:00
|
|
|
if (UIModeController::getInstance()->isUIModeKiosk()) {
|
|
|
|
filterByHidden = true;
|
|
|
|
std::vector<std::string> val = { "FALSE" };
|
|
|
|
setFilter(HIDDEN_FILTER, &val);
|
|
|
|
}
|
|
|
|
if (UIModeController::getInstance()->isUIModeKid()) {
|
|
|
|
filterByKidGame = true;
|
|
|
|
std::vector<std::string> val = { "TRUE" };
|
|
|
|
setFilter(KIDGAME_FILTER, &val);
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
void FileFilterIndex::debugPrintIndexes()
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
LOG(LogInfo) << "Printing Indexes...";
|
2020-10-27 19:58:42 +00:00
|
|
|
for (auto x: favoritesIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Favorites Index: " << x.first << ": " << x.second;
|
2020-06-22 15:27:53 +00:00
|
|
|
}
|
|
|
|
for (auto x: genreIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Genre Index: " << x.first << ": " << x.second;
|
|
|
|
}
|
2020-10-27 19:58:42 +00:00
|
|
|
for (auto x: playersIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Multiplayer Index: " << x.first << ": " << x.second;
|
2020-06-22 15:27:53 +00:00
|
|
|
}
|
|
|
|
for (auto x: pubDevIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "PubDev Index: " << x.first << ": " << x.second;
|
|
|
|
}
|
2020-10-27 19:58:42 +00:00
|
|
|
for (auto x: ratingsIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Ratings Index: " << x.first << ": " << x.second;
|
2020-06-22 15:27:53 +00:00
|
|
|
}
|
|
|
|
for (auto x : kidGameIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "KidGames Index: " << x.first << ": " << x.second;
|
|
|
|
}
|
2020-10-27 19:58:42 +00:00
|
|
|
for (auto x : completedIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Completed Index: " << x.first << ": " << x.second;
|
|
|
|
}
|
|
|
|
for (auto x : brokenIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Broken Index: " << x.first << ": " << x.second;
|
|
|
|
}
|
|
|
|
for (auto x : hiddenIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Hidden Index: " << x.first << ": " << x.second;
|
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileFilterIndex::showFile(FileData* game)
|
2017-05-18 10:16:57 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
// This shouldn't happen, but just in case let's get it out of the way.
|
|
|
|
if (!isFiltered())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If folder, needs further inspection - i.e. see if folder contains at least one element
|
|
|
|
// that should be shown.
|
|
|
|
if (game->getType() == FOLDER) {
|
|
|
|
std::vector<FileData*> children = game->getChildren();
|
|
|
|
// Iterate through all of the children, until there's a match.
|
|
|
|
for (std::vector<FileData*>::const_iterator it = children.cbegin();
|
|
|
|
it != children.cend(); ++it ) {
|
|
|
|
if (showFile(*it))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-08 15:34:33 +00:00
|
|
|
bool nameMatch = false;
|
2020-06-22 15:27:53 +00:00
|
|
|
bool keepGoing = false;
|
|
|
|
|
2020-11-08 15:34:33 +00:00
|
|
|
// Name filters take precedence over all other filters, so if there is no match for
|
|
|
|
// the game name, then always return false.
|
|
|
|
if (mTextFilter != "" && !(Utils::String::toUpper(game->
|
|
|
|
getName()).find(mTextFilter) != std::string::npos)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (mTextFilter != "") {
|
|
|
|
nameMatch = true;
|
|
|
|
}
|
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin();
|
|
|
|
it != filterDataDecl.cend(); ++it ) {
|
|
|
|
FilterDataDecl filterData = (*it);
|
|
|
|
if (*(filterData.filteredByRef)) {
|
|
|
|
// Try to find a match.
|
|
|
|
std::string key = getIndexableKey(game, filterData.type, false);
|
|
|
|
keepGoing = isKeyBeingFilteredBy(key, filterData.type);
|
|
|
|
|
|
|
|
// If we didn't find a match, try for secondary keys - i.e.
|
|
|
|
// publisher and dev, or first genre.
|
|
|
|
if (!keepGoing) {
|
|
|
|
if (!filterData.hasSecondaryKey)
|
|
|
|
return false;
|
|
|
|
std::string secKey = getIndexableKey(game, filterData.type, true);
|
|
|
|
if (secKey != UNKNOWN_LABEL)
|
|
|
|
keepGoing = isKeyBeingFilteredBy(secKey, filterData.type);
|
|
|
|
}
|
|
|
|
// If still nothing, then it's not a match.
|
|
|
|
if (!keepGoing)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-11-08 15:34:33 +00:00
|
|
|
|
|
|
|
// If there is a match for the game name, but not for any other filters, then return
|
|
|
|
// true as it means that the name filter is the only applied filter.
|
|
|
|
if (!keepGoing && nameMatch)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return keepGoing;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type)
|
|
|
|
{
|
2020-10-27 19:58:42 +00:00
|
|
|
const FilterIndexType filterTypes[9] = { FAVORITES_FILTER, GENRE_FILTER,
|
|
|
|
PLAYER_FILTER, PUBDEV_FILTER, RATINGS_FILTER, KIDGAME_FILTER,
|
|
|
|
COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER };
|
|
|
|
std::vector<std::string> filterKeysList[9] = { favoritesIndexFilteredKeys,
|
2020-06-22 15:27:53 +00:00
|
|
|
genreIndexFilteredKeys, playersIndexFilteredKeys, pubDevIndexFilteredKeys,
|
2020-10-27 19:58:42 +00:00
|
|
|
ratingsIndexFilteredKeys, kidGameIndexFilteredKeys, completedIndexFilteredKeys,
|
|
|
|
brokenIndexFilteredKeys, hiddenIndexFilteredKeys };
|
2020-06-22 15:27:53 +00:00
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
for (int i = 0; i < 9; i++) {
|
2020-06-22 15:27:53 +00:00
|
|
|
if (filterTypes[i] == type) {
|
|
|
|
for (std::vector<std::string>::const_iterator it = filterKeysList[i].cbegin();
|
|
|
|
it != filterKeysList[i].cend(); ++it ) {
|
|
|
|
if (key == (*it))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
void FileFilterIndex::manageFavoritesEntryInIndex(FileData* game, bool remove)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-10-27 19:58:42 +00:00
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
std::string key = getIndexableKey(game, FAVORITES_FILTER, false);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
|
|
|
// No valid favorites info found.
|
|
|
|
return;
|
|
|
|
|
|
|
|
manageIndexEntry(&favoritesIndexAllKeys, key, remove);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string key = getIndexableKey(game, GENRE_FILTER, false);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
// Only add unknown in pubdev IF both dev and pub are empty.
|
|
|
|
if (!includeUnknown && (key == UNKNOWN_LABEL || key == "BIOS"))
|
|
|
|
// No valid genre info found.
|
|
|
|
return;
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
manageIndexEntry(&genreIndexAllKeys, key, remove);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
key = getIndexableKey(game, GENRE_FILTER, true);
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
|
|
|
manageIndexEntry(&genreIndexAllKeys, key, remove);
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
std::string key = getIndexableKey(game, PLAYER_FILTER, false);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
// Only add unknown in pubdev IF both dev and pub are empty.
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
|
|
|
// No valid player info found.
|
|
|
|
return;
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
manageIndexEntry(&playersIndexAllKeys, key, remove);
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::managePubDevEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string pub = getIndexableKey(game, PUBDEV_FILTER, false);
|
|
|
|
std::string dev = getIndexableKey(game, PUBDEV_FILTER, true);
|
|
|
|
|
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
bool unknownPub = false;
|
|
|
|
bool unknownDev = false;
|
|
|
|
|
|
|
|
if (pub == UNKNOWN_LABEL)
|
|
|
|
unknownPub = true;
|
|
|
|
|
|
|
|
if (dev == UNKNOWN_LABEL)
|
|
|
|
unknownDev = true;
|
|
|
|
|
|
|
|
if (!includeUnknown && unknownDev && unknownPub)
|
|
|
|
// No valid rating info found.
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (unknownDev && unknownPub) {
|
|
|
|
// If no info at all.
|
|
|
|
manageIndexEntry(&pubDevIndexAllKeys, pub, remove);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!unknownDev) {
|
|
|
|
// If no info at all.
|
|
|
|
manageIndexEntry(&pubDevIndexAllKeys, dev, remove);
|
|
|
|
}
|
|
|
|
if (!unknownPub) {
|
|
|
|
// If no info at all.
|
|
|
|
manageIndexEntry(&pubDevIndexAllKeys, pub, remove);
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::manageRatingsEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
std::string key = getIndexableKey(game, RATINGS_FILTER, false);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
|
|
|
// No valid rating info found.
|
|
|
|
return;
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
manageIndexEntry(&ratingsIndexAllKeys, key, remove);
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
void FileFilterIndex::manageKidGameEntryInIndex(FileData* game, bool remove)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
2020-10-27 19:58:42 +00:00
|
|
|
std::string key = getIndexableKey(game, KIDGAME_FILTER, false);
|
2020-06-22 15:27:53 +00:00
|
|
|
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
2020-10-27 19:58:42 +00:00
|
|
|
// No valid kidgame info found.
|
2020-06-22 15:27:53 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
manageIndexEntry(&kidGameIndexAllKeys, key, remove);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
void FileFilterIndex::manageCompletedEntryInIndex(FileData* game, bool remove)
|
2017-09-08 13:20:07 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
2020-10-27 19:58:42 +00:00
|
|
|
std::string key = getIndexableKey(game, COMPLETED_FILTER, false);
|
2020-06-22 15:27:53 +00:00
|
|
|
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
2020-10-27 19:58:42 +00:00
|
|
|
// No valid completed info found.
|
2020-06-22 15:27:53 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
manageIndexEntry(&completedIndexAllKeys, key, remove);
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
void FileFilterIndex::manageBrokenEntryInIndex(FileData* game, bool remove)
|
2017-09-08 13:20:07 +00:00
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
2020-10-27 19:58:42 +00:00
|
|
|
std::string key = getIndexableKey(game, BROKEN_FILTER, false);
|
2020-06-22 15:27:53 +00:00
|
|
|
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
2020-10-27 19:58:42 +00:00
|
|
|
// No valid broken info found.
|
2020-06-22 15:27:53 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-27 19:58:42 +00:00
|
|
|
manageIndexEntry(&brokenIndexAllKeys, key, remove);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::manageHiddenEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
|
|
|
// Flag for including unknowns.
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
std::string key = getIndexableKey(game, HIDDEN_FILTER, false);
|
|
|
|
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
|
|
|
// No valid hidden info found.
|
|
|
|
return;
|
|
|
|
|
|
|
|
manageIndexEntry(&hiddenIndexAllKeys, key, remove);
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 15:27:53 +00:00
|
|
|
void FileFilterIndex::manageIndexEntry(std::map<std::string, int>* index,
|
|
|
|
std::string key, bool remove)
|
|
|
|
{
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (remove) {
|
|
|
|
// Removing entry.
|
|
|
|
if (index->find(key) == index->cend()) {
|
2020-10-27 19:58:42 +00:00
|
|
|
// Disabled for now as this could happen because default values are assigned as
|
|
|
|
// filters, for example 'FALSE' for favorites and kidgames for non-game entries.
|
|
|
|
// LOG(LogDebug) << "Couldn't find entry in index! " << key;
|
2020-06-22 15:27:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
(index->at(key))--;
|
|
|
|
if (index->at(key) <= 0) {
|
|
|
|
index->erase(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Adding entry.
|
|
|
|
if (index->find(key) == index->cend())
|
|
|
|
(*index)[key] = 1;
|
|
|
|
else
|
|
|
|
(index->at(key))++;
|
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::clearIndex(std::map<std::string, int> indexMap)
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
indexMap.clear();
|
|
|
|
}
|