2017-03-18 17:54:39 +00:00
|
|
|
#include "FileFilterIndex.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()
|
2017-09-08 13:20:07 +00:00
|
|
|
: filterByFavorites(false), filterByGenre(false), filterByHidden(false), filterByKidGame(false), filterByPlayers(false), filterByPubDev(false), filterByRatings(false)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2017-09-08 13:20:07 +00:00
|
|
|
clearAllFilters();
|
2017-03-18 17:54:39 +00:00
|
|
|
FilterDataDecl filterDecls[] = {
|
|
|
|
//type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel
|
2017-06-12 16:38:59 +00:00
|
|
|
{ FAVORITES_FILTER, &favoritesIndexAllKeys, &filterByFavorites, &favoritesIndexFilteredKeys,"favorite", false, "", "FAVORITES" },
|
2017-03-18 17:54:39 +00:00
|
|
|
{ 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" },
|
2017-09-08 13:20:07 +00:00
|
|
|
{ RATINGS_FILTER, &ratingsIndexAllKeys, &filterByRatings, &ratingsIndexFilteredKeys, "rating", false, "", "RATING" },
|
|
|
|
{ KIDGAME_FILTER, &kidGameIndexAllKeys, &filterByKidGame, &kidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME" },
|
|
|
|
{ HIDDEN_FILTER, &hiddenIndexAllKeys, &filterByHidden, &hiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN" }
|
2017-03-18 17:54:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
filterDataDecl = std::vector<FilterDataDecl>(filterDecls, filterDecls + sizeof(filterDecls) / sizeof(filterDecls[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
FileFilterIndex::~FileFilterIndex()
|
|
|
|
{
|
2017-07-18 09:45:50 +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
|
|
|
{
|
|
|
|
return filterDataDecl;
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void FileFilterIndex::importIndex(FileFilterIndex* indexToImport)
|
|
|
|
{
|
|
|
|
struct IndexImportStructure
|
2017-09-08 13:20:07 +00:00
|
|
|
{
|
|
|
|
std::map<std::string, int>* destinationIndex;
|
|
|
|
std::map<std::string, int>* sourceIndex;
|
|
|
|
};
|
2017-07-18 09:45:50 +00:00
|
|
|
|
|
|
|
IndexImportStructure indexStructDecls[] = {
|
|
|
|
{ &genreIndexAllKeys, &(indexToImport->genreIndexAllKeys) },
|
|
|
|
{ &playersIndexAllKeys, &(indexToImport->playersIndexAllKeys) },
|
|
|
|
{ &pubDevIndexAllKeys, &(indexToImport->pubDevIndexAllKeys) },
|
|
|
|
{ &ratingsIndexAllKeys, &(indexToImport->ratingsIndexAllKeys) },
|
2017-09-08 13:20:07 +00:00
|
|
|
{ &favoritesIndexAllKeys, &(indexToImport->favoritesIndexAllKeys) },
|
|
|
|
{ &hiddenIndexAllKeys, &(indexToImport->hiddenIndexAllKeys) },
|
|
|
|
{ &kidGameIndexAllKeys, &(indexToImport->kidGameIndexAllKeys) },
|
2017-07-18 09:45:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<IndexImportStructure> indexImportDecl = std::vector<IndexImportStructure>(indexStructDecls, indexStructDecls + sizeof(indexStructDecls) / sizeof(indexStructDecls[0]));
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<IndexImportStructure>::const_iterator indexesIt = indexImportDecl.cbegin(); indexesIt != indexImportDecl.cend(); ++indexesIt )
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::map<std::string, int>::const_iterator sourceIt = (*indexesIt).sourceIndex->cbegin(); sourceIt != (*indexesIt).sourceIndex->cend(); ++sourceIt )
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
if ((*indexesIt).destinationIndex->find((*sourceIt).first) == (*indexesIt).destinationIndex->cend())
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
// entry doesn't exist
|
|
|
|
(*((*indexesIt).destinationIndex))[(*sourceIt).first] = (*sourceIt).second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(*((*indexesIt).destinationIndex))[(*sourceIt).first] += (*sourceIt).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void FileFilterIndex::resetIndex()
|
|
|
|
{
|
|
|
|
clearAllFilters();
|
|
|
|
clearIndex(genreIndexAllKeys);
|
|
|
|
clearIndex(playersIndexAllKeys);
|
|
|
|
clearIndex(pubDevIndexAllKeys);
|
|
|
|
clearIndex(ratingsIndexAllKeys);
|
|
|
|
clearIndex(favoritesIndexAllKeys);
|
2017-09-08 13:20:07 +00:00
|
|
|
clearIndex(hiddenIndexAllKeys);
|
|
|
|
clearIndex(kidGameIndexAllKeys);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
std::string FileFilterIndex::getIndexableKey(FileData* game, FilterIndexType type, bool getSecondary)
|
|
|
|
{
|
|
|
|
std::string key = "";
|
2017-05-18 10:16:57 +00:00
|
|
|
switch(type)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
|
|
|
case GENRE_FILTER:
|
|
|
|
{
|
2018-01-27 17:04:28 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("genre"));
|
2018-01-26 18:53:19 +00:00
|
|
|
key = Utils::String::trim(key);
|
2017-03-18 17:54:39 +00:00
|
|
|
if (getSecondary && !key.empty()) {
|
|
|
|
std::istringstream f(key);
|
2017-05-18 10:16:57 +00:00
|
|
|
std::string newKey;
|
|
|
|
getline(f, newKey, '/');
|
|
|
|
if (!newKey.empty() && newKey != key)
|
|
|
|
{
|
|
|
|
key = newKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key = std::string();
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PLAYER_FILTER:
|
|
|
|
{
|
|
|
|
if (getSecondary)
|
|
|
|
break;
|
2017-05-18 10:16:57 +00:00
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
key = game->metadata.get("players");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PUBDEV_FILTER:
|
|
|
|
{
|
2018-01-27 17:04:28 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("publisher"));
|
2018-01-26 18:53:19 +00:00
|
|
|
key = Utils::String::trim(key);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
|
|
|
if ((getSecondary && !key.empty()) || (!getSecondary && key.empty()))
|
2018-01-27 17:04:28 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("developer"));
|
2017-03-18 17:54:39 +00:00
|
|
|
else
|
2018-01-27 17:04:28 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("publisher"));
|
2017-03-18 17:54:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RATINGS_FILTER:
|
|
|
|
{
|
|
|
|
int ratingNumber = 0;
|
2017-05-18 10:16:57 +00:00
|
|
|
if (!getSecondary)
|
|
|
|
{
|
2017-03-18 17:54:39 +00:00
|
|
|
std::string ratingString = game->metadata.get("rating");
|
|
|
|
if (!ratingString.empty()) {
|
|
|
|
try {
|
2017-11-01 22:21:10 +00:00
|
|
|
ratingNumber = (int)((std::stod(ratingString)*5)+0.5);
|
2017-03-18 17:54:39 +00:00
|
|
|
if (ratingNumber < 0)
|
|
|
|
ratingNumber = 0;
|
|
|
|
|
|
|
|
key = std::to_string(ratingNumber) + " STARS";
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
|
|
|
catch (int e)
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2017-10-18 14:19:32 +00:00
|
|
|
LOG(LogError) << "Error parsing Rating (invalid value, exception nr.): " << ratingString << ", " << e;
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
case FAVORITES_FILTER:
|
|
|
|
{
|
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
2018-01-27 17:04:28 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("favorite"));
|
2017-06-12 16:38:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-09-08 13:20:07 +00:00
|
|
|
case HIDDEN_FILTER:
|
|
|
|
{
|
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
2018-01-27 17:04:28 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("hidden"));
|
2017-09-08 13:20:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KIDGAME_FILTER:
|
|
|
|
{
|
|
|
|
if (game->getType() != GAME)
|
|
|
|
return "FALSE";
|
2018-01-27 17:04:28 +00:00
|
|
|
key = Utils::String::toUpper(game->metadata.get("kidgame"));
|
2017-09-08 13:20:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
2018-01-26 18:53:19 +00:00
|
|
|
key = Utils::String::trim(key);
|
2017-03-18 17:54:39 +00:00
|
|
|
if (key.empty() || (type == RATINGS_FILTER && key == "0 STARS")) {
|
|
|
|
key = UNKNOWN_LABEL;
|
|
|
|
}
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::addToIndex(FileData* game)
|
|
|
|
{
|
|
|
|
manageGenreEntryInIndex(game);
|
|
|
|
managePlayerEntryInIndex(game);
|
|
|
|
managePubDevEntryInIndex(game);
|
|
|
|
manageRatingsEntryInIndex(game);
|
2017-06-12 16:38:59 +00:00
|
|
|
manageFavoritesEntryInIndex(game);
|
2017-09-08 13:20:07 +00:00
|
|
|
manageHiddenEntryInIndex(game);
|
|
|
|
manageKidGameEntryInIndex(game);
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::removeFromIndex(FileData* game)
|
|
|
|
{
|
|
|
|
manageGenreEntryInIndex(game, true);
|
|
|
|
managePlayerEntryInIndex(game, true);
|
|
|
|
managePubDevEntryInIndex(game, true);
|
|
|
|
manageRatingsEntryInIndex(game, true);
|
2017-06-12 16:38:59 +00:00
|
|
|
manageFavoritesEntryInIndex(game, true);
|
2017-09-08 13:20:07 +00:00
|
|
|
manageHiddenEntryInIndex(game, true);
|
|
|
|
manageKidGameEntryInIndex(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
|
|
|
{
|
|
|
|
// test if it exists before setting
|
|
|
|
if(type == NONE)
|
|
|
|
{
|
|
|
|
clearAllFilters();
|
|
|
|
}
|
|
|
|
else
|
2017-05-18 10:16:57 +00:00
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin(); it != filterDataDecl.cend(); ++it ) {
|
2017-03-18 17:54:39 +00:00
|
|
|
if ((*it).type == type)
|
|
|
|
{
|
|
|
|
FilterDataDecl filterData = (*it);
|
|
|
|
*(filterData.filteredByRef) = values->size() > 0;
|
|
|
|
filterData.currentFilteredKeys->clear();
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<std::string>::const_iterator vit = values->cbegin(); vit != values->cend(); ++vit ) {
|
2017-05-18 10:16:57 +00:00
|
|
|
// check if exists
|
2017-11-11 14:56:22 +00:00
|
|
|
if (filterData.allIndexKeys->find(*vit) != filterData.allIndexKeys->cend()) {
|
2017-05-18 10:16:57 +00:00
|
|
|
filterData.currentFilteredKeys->push_back(std::string(*vit));
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
void FileFilterIndex::clearAllFilters()
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin(); it != filterDataDecl.cend(); ++it )
|
2017-05-18 10:16:57 +00:00
|
|
|
{
|
2017-03-18 17:54:39 +00:00
|
|
|
FilterDataDecl filterData = (*it);
|
|
|
|
*(filterData.filteredByRef) = false;
|
|
|
|
filterData.currentFilteredKeys->clear();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:20:07 +00:00
|
|
|
void FileFilterIndex::resetFilters()
|
|
|
|
{
|
|
|
|
clearAllFilters();
|
|
|
|
setUIModeFilters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::setUIModeFilters()
|
|
|
|
{
|
2018-05-10 20:08:04 +00:00
|
|
|
if(!Settings::getInstance()->getBool("ForceDisableFilters")){
|
|
|
|
if (!UIModeController::getInstance()->isUIModeFull())
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
LOG(LogInfo) << "Printing Indexes...";
|
2017-03-18 17:54:39 +00:00
|
|
|
for (auto x: playersIndexAllKeys) {
|
2017-07-18 09:45:50 +00:00
|
|
|
LOG(LogInfo) << "Multiplayer Index: " << x.first << ": " << x.second;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
for (auto x: genreIndexAllKeys) {
|
2017-07-18 09:45:50 +00:00
|
|
|
LOG(LogInfo) << "Genre Index: " << x.first << ": " << x.second;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
for (auto x: ratingsIndexAllKeys) {
|
2017-07-18 09:45:50 +00:00
|
|
|
LOG(LogInfo) << "Ratings Index: " << x.first << ": " << x.second;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
for (auto x: pubDevIndexAllKeys) {
|
2017-07-18 09:45:50 +00:00
|
|
|
LOG(LogInfo) << "PubDev Index: " << x.first << ": " << x.second;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
for (auto x: favoritesIndexAllKeys) {
|
2017-07-18 09:45:50 +00:00
|
|
|
LOG(LogInfo) << "Favorites Index: " << x.first << ": " << x.second;
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
|
|
|
for (auto x : hiddenIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "Hidden Index: " << x.first << ": " << x.second;
|
|
|
|
}
|
|
|
|
for (auto x : kidGameIndexAllKeys) {
|
|
|
|
LOG(LogInfo) << "KidGames 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
|
|
|
{
|
2017-03-18 17:54:39 +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
|
2017-05-18 10:16:57 +00:00
|
|
|
if (game->getType() == FOLDER) {
|
2017-03-18 17:54:39 +00:00
|
|
|
std::vector<FileData*> children = game->getChildren();
|
|
|
|
// iterate through all of the children, until there's a match
|
2017-05-18 10:16:57 +00:00
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<FileData*>::const_iterator it = children.cbegin(); it != children.cend(); ++it ) {
|
2017-03-18 17:54:39 +00:00
|
|
|
if (showFile(*it))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool keepGoing = false;
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin(); it != filterDataDecl.cend(); ++it ) {
|
2017-03-18 17:54:39 +00:00
|
|
|
FilterDataDecl filterData = (*it);
|
2017-05-18 10:16:57 +00:00
|
|
|
if(*(filterData.filteredByRef))
|
|
|
|
{
|
2017-03-18 17:54:39 +00:00
|
|
|
// try to find a match
|
2017-05-18 10:16:57 +00:00
|
|
|
std::string key = getIndexableKey(game, filterData.type, false);
|
|
|
|
keepGoing = isKeyBeingFilteredBy(key, filterData.type);
|
2017-03-18 17:54:39 +00:00
|
|
|
|
|
|
|
// if we didn't find a match, try for secondary keys - i.e. publisher and dev, or first genre
|
2017-05-18 10:16:57 +00:00
|
|
|
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)
|
2017-03-18 17:54:39 +00:00
|
|
|
return false;
|
2017-05-18 10:16:57 +00:00
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
2017-05-18 10:16:57 +00:00
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return keepGoing;
|
|
|
|
}
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type)
|
|
|
|
{
|
2017-09-08 13:20:07 +00:00
|
|
|
const FilterIndexType filterTypes[7] = { FAVORITES_FILTER, GENRE_FILTER, PLAYER_FILTER, PUBDEV_FILTER, RATINGS_FILTER,HIDDEN_FILTER, KIDGAME_FILTER };
|
|
|
|
std::vector<std::string> filterKeysList[7] = { favoritesIndexFilteredKeys, genreIndexFilteredKeys, playersIndexFilteredKeys, pubDevIndexFilteredKeys, ratingsIndexFilteredKeys, hiddenIndexFilteredKeys, kidGameIndexFilteredKeys };
|
2017-03-18 17:54:39 +00:00
|
|
|
|
2017-09-08 13:20:07 +00:00
|
|
|
for (int i = 0; i < 7; i++)
|
2017-05-18 10:16:57 +00:00
|
|
|
{
|
|
|
|
if (filterTypes[i] == type)
|
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<std::string>::const_iterator it = filterKeysList[i].cbegin(); it != filterKeysList[i].cend(); ++it )
|
2017-05-18 10:16:57 +00:00
|
|
|
{
|
|
|
|
if (key == (*it))
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
|
|
|
return false;
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::manageGenreEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string key = getIndexableKey(game, GENRE_FILTER, false);
|
|
|
|
|
|
|
|
// flag for including unknowns
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
|
|
|
|
// 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-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
|
|
|
|
manageIndexEntry(&genreIndexAllKeys, key, remove);
|
|
|
|
|
|
|
|
key = getIndexableKey(game, GENRE_FILTER, true);
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL)
|
|
|
|
{
|
|
|
|
manageIndexEntry(&genreIndexAllKeys, key, remove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::managePlayerEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
|
|
|
// flag for including unknowns
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
std::string key = getIndexableKey(game, PLAYER_FILTER, false);
|
|
|
|
|
|
|
|
// only add unknown in pubdev IF both dev and pub are empty
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL) {
|
|
|
|
// no valid player info found
|
|
|
|
return;
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
|
|
|
|
manageIndexEntry(&playersIndexAllKeys, key, remove);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::managePubDevEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
|
|
|
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;
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
|
|
|
|
if (unknownDev && unknownPub) {
|
|
|
|
// if no info at all
|
|
|
|
manageIndexEntry(&pubDevIndexAllKeys, pub, remove);
|
|
|
|
}
|
2017-05-18 10:16:57 +00:00
|
|
|
else
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
|
|
|
if (!unknownDev) {
|
|
|
|
// if no info at all
|
|
|
|
manageIndexEntry(&pubDevIndexAllKeys, dev, remove);
|
|
|
|
}
|
|
|
|
if (!unknownPub) {
|
|
|
|
// if no info at all
|
|
|
|
manageIndexEntry(&pubDevIndexAllKeys, pub, remove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::manageRatingsEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
|
|
|
std::string key = getIndexableKey(game, RATINGS_FILTER, false);
|
|
|
|
|
|
|
|
// flag for including unknowns
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL) {
|
|
|
|
// no valid rating info found
|
|
|
|
return;
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
|
|
|
|
manageIndexEntry(&ratingsIndexAllKeys, key, remove);
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
void FileFilterIndex::manageFavoritesEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
|
|
|
// flag for including unknowns
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
std::string key = getIndexableKey(game, FAVORITES_FILTER, false);
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL) {
|
|
|
|
// no valid favorites info found
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
manageIndexEntry(&favoritesIndexAllKeys, key, remove);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:20:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::manageKidGameEntryInIndex(FileData* game, bool remove)
|
|
|
|
{
|
|
|
|
// flag for including unknowns
|
|
|
|
bool includeUnknown = INCLUDE_UNKNOWN;
|
|
|
|
std::string key = getIndexableKey(game, KIDGAME_FILTER, false);
|
|
|
|
if (!includeUnknown && key == UNKNOWN_LABEL) {
|
|
|
|
// no valid kidgame info found
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
manageIndexEntry(&kidGameIndexAllKeys, key, remove);
|
|
|
|
}
|
|
|
|
|
2017-03-18 17:54:39 +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
|
2017-11-11 14:56:22 +00:00
|
|
|
if (index->find(key) == index->cend())
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
|
|
|
// this shouldn't happen
|
2017-06-12 16:38:59 +00:00
|
|
|
LOG(LogInfo) << "Couldn't find entry in index! " << key;
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
(index->at(key))--;
|
|
|
|
if(index->at(key) <= 0) {
|
|
|
|
index->erase(key);
|
|
|
|
}
|
|
|
|
}
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
|
|
|
else
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
|
|
|
// adding entry
|
2017-11-11 14:56:22 +00:00
|
|
|
if (index->find(key) == index->cend())
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
|
|
|
(*index)[key] = 1;
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
(index->at(key))++;
|
|
|
|
}
|
2017-05-18 10:16:57 +00:00
|
|
|
}
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileFilterIndex::clearIndex(std::map<std::string, int> indexMap)
|
|
|
|
{
|
2017-05-18 10:16:57 +00:00
|
|
|
indexMap.clear();
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|