Remove filtering options from the GameList

This commit is contained in:
Maschell 2020-02-24 18:44:02 +01:00
parent e07c0aa47c
commit 7815e5b3fc
3 changed files with 34 additions and 152 deletions

View File

@ -9,10 +9,17 @@
#include "GameList.h"
#include "common/common.h"
#include "fs/DirList.h"
#include "fs/FSUtils.h"
#include "utils/logger.h"
#include "utils/StringTools.h"
GameList::GameList() {
}
GameList::~GameList() {
stopAsyncLoading = true;
DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading));
clear();
};
void GameList::clear() {
lock();
@ -25,24 +32,24 @@ void GameList::clear() {
delete x;
}
}
gameFilter.clear();
fullGameList.clear();
filteredList.clear();
//! Clear memory of the vector completely
std::vector<gameInfo *>().swap(filteredList);
std::vector<gameInfo*>().swap(fullGameList);
unlock();
titleListChanged(this);
}
gameInfo * GameList::getGameInfo(uint64_t titleId) const {
for (uint32_t i = 0; i < filteredList.size(); ++i) {
if(titleId == filteredList[i]->titleId)
return filteredList[i];
gameInfo * GameList::getGameInfo(uint64_t titleId){
gameInfo * result = NULL;
lock();
for (uint32_t i = 0; i < fullGameList.size(); ++i) {
if(titleId == fullGameList[i]->titleId){
result = fullGameList[i];
break;
}
}
return NULL;
unlock();
return result;
}
extern "C" int ACPGetTitleMetaXml(uint64_t titleid, ACPMetaXml*);
@ -82,7 +89,7 @@ int32_t GameList::readGameList() {
}
for (auto title_candidate : titles) {
if((title_candidate.titleId & 0xFFFFFFFF00000000L) == 0x0005000000000000L) {
if(true || (title_candidate.titleId & 0xFFFFFFFF00000000L) == 0x0005000000000000L) {
gameInfo* newGameInfo = new gameInfo;
newGameInfo->titleId = title_candidate.titleId;
newGameInfo->gamePath = title_candidate.path;
@ -183,78 +190,17 @@ void GameList::updateTitleInfo() {
}
}
void GameList::internalFilterList(std::vector<gameInfo*> &fullList) {
for (uint32_t i = 0; i < fullList.size(); ++i) {
gameInfo *header = fullList[i];
if (StringTools::findStringIC(header->name,gameFilter)) {
filteredList.push_back(header);
}
}
}
int32_t GameList::filterList(const char * filter) {
lock();
if(filter) {
gameFilter = filter;
}
if(fullGameList.size() == 0) {
readGameList();
}
filteredList.clear();
// Filter current game list if selected
internalFilterList(fullGameList);
sortList();
titleListChanged(this);
AsyncExecutor::execute([&] { updateTitleInfo();});
int32_t res = filteredList.size();
unlock();
return res;
}
void GameList::internalLoadUnfiltered(std::vector<gameInfo*> & fullList) {
for (uint32_t i = 0; i < fullList.size(); ++i) {
gameInfo *header = fullList[i];
filteredList.push_back(header);
}
}
int32_t GameList::loadUnfiltered() {
int32_t GameList::load() {
lock();
if(fullGameList.size() == 0) {
readGameList();
}
gameFilter.clear();
filteredList.clear();
// Filter current game list if selected
internalLoadUnfiltered(fullGameList);
sortList();
AsyncExecutor::execute([&] { updateTitleInfo();});
titleListChanged(this);
int res = filteredList.size();
int res = fullGameList.size();
unlock();
return res;
}
void GameList::sortList() {
lock();
std::sort(filteredList.begin(), filteredList.end(), nameSortCallback);
unlock();
}
bool GameList::nameSortCallback(const gameInfo *a, const gameInfo *b) {
return (strcasecmp(((gameInfo *) a)->name.c_str(), ((gameInfo *) b)->name.c_str()) < 0);
}

View File

@ -18,16 +18,12 @@ typedef struct _gameInfo {
class GameList {
public:
GameList() : selectedGame(0) { };
~GameList() {
stopAsyncLoading = true;
DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading));
clear();
};
GameList();
~GameList();
int32_t size() {
lock();
int32_t res = filteredList.size();
int32_t res = fullGameList.size();
unlock();
return res;
}
@ -37,8 +33,6 @@ public:
unlock();
return res;
}
int32_t filterList(const char * gameFilter = NULL);
int32_t loadUnfiltered();
gameInfo * at(int32_t i) {
return operator[](i);
@ -46,68 +40,24 @@ public:
gameInfo * operator[](int32_t i) {
lock();
gameInfo * res = NULL;
if (i < 0 || i >= (int32_t) filteredList.size())
if (i < 0 || i >= (int32_t) fullGameList.size()) {
res = NULL;
res = filteredList[i];
} else {
res = fullGameList[i];
}
unlock();
return res;
}
gameInfo * getGameInfo(uint64_t titleId) const;
gameInfo * getGameInfo(uint64_t titleId);
const char * getCurrentFilter() const {
return gameFilter.c_str();
}
void sortList();
void clear();
bool operator!() {
lock();
bool res = (fullGameList.size() == 0);
unlock();
return res;
}
//! Gamelist scrolling operators
int32_t operator+=(int32_t i) {
lock();
int32_t res = (selectedGame = (selectedGame+i) % filteredList.size());
unlock();
return res;
}
int32_t operator-=(int32_t i) {
lock();
int32_t res = (selectedGame = (selectedGame-i+filteredList.size()) % filteredList.size());
unlock();
return res;
}
int32_t operator++() {
lock();
int32_t res = (selectedGame = (selectedGame+1) % filteredList.size());
unlock();
return res;
}
int32_t operator--() {
lock();
int32_t res = (selectedGame = (selectedGame-1+filteredList.size()) % filteredList.size());
unlock();
return res;
}
int32_t operator++(int32_t i) {
return operator++();
}
int32_t operator--(int32_t i) {
return operator--();
}
gameInfo * GetCurrentSelected() {
return operator[](selectedGame);
}
std::vector<gameInfo *> & getfilteredList(void) {
return filteredList;
}
std::vector<gameInfo *> & getFullGameList(void) {
return fullGameList;
}
int32_t load();
sigslot::signal1<GameList *> titleListChanged;
sigslot::signal1<gameInfo *> titleUpdated;
sigslot::signal1<gameInfo *> titleAdded;
@ -115,25 +65,13 @@ public:
void lock() {
_lock.lock();
}
void unlock(){
void unlock() {
_lock.unlock();
}
protected:
int32_t readGameList();
void internalFilterList(std::vector<gameInfo*> & fullList);
void internalLoadUnfiltered(std::vector<gameInfo*> & fullList);
void updateTitleInfo();
static bool nameSortCallback(const gameInfo *a, const gameInfo *b);
static GameList *gameListInstance;
std::string gameFilter;
int32_t selectedGame;
std::vector<gameInfo *> filteredList;
std::vector<gameInfo *> fullGameList;
std::recursive_mutex _lock;

View File

@ -45,7 +45,7 @@ MainWindow::MainWindow(int32_t w, int32_t h)
gameList.titleListChanged.connect(this, &MainWindow::OnGameTitleListChanged);
gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated);
gameList.titleAdded.connect(this, &MainWindow::OnGameTitleAdded);
AsyncExecutor::execute([&] {gameList.loadUnfiltered();});
AsyncExecutor::execute([&] {gameList.load();});
}
@ -119,8 +119,6 @@ void MainWindow::process() {
currentTvFrame->clearState(GuiElement::STATE_DISABLED);
currentDrcFrame->clearState(GuiElement::STATE_DISABLED);
mainSwitchButtonFrame->clearState(GuiElement::STATE_DISABLED);
gameList.filterList(result.c_str());
} else {
}
}