2010-09-19 01:16:05 +02:00
|
|
|
/****************************************************************************
|
2010-09-24 02:48:03 +02:00
|
|
|
* Copyright (C) 2010
|
|
|
|
* by Dimok
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
***************************************************************************/
|
2010-09-18 13:46:25 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <malloc.h>
|
2020-12-12 22:33:31 +01:00
|
|
|
|
2011-11-12 19:14:09 +01:00
|
|
|
#include "GUI/gui_searchbar.h"
|
2010-09-18 13:46:25 +02:00
|
|
|
#include "usbloader/wbfs.h"
|
2012-02-09 22:18:16 +01:00
|
|
|
#include "GameCube/GCGames.h"
|
2010-09-18 13:46:25 +02:00
|
|
|
#include "settings/newtitles.h"
|
2010-09-19 22:25:12 +02:00
|
|
|
#include "settings/CSettings.h"
|
2010-10-28 11:00:52 +02:00
|
|
|
#include "settings/CGameSettings.h"
|
2010-09-25 10:51:44 +02:00
|
|
|
#include "settings/CGameStatistics.h"
|
2010-10-28 11:00:52 +02:00
|
|
|
#include "settings/GameTitles.h"
|
2011-06-03 22:31:09 +02:00
|
|
|
#include "settings/CGameCategories.hpp"
|
2010-09-18 13:46:25 +02:00
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
#include "GameList.h"
|
2010-11-06 16:30:14 +01:00
|
|
|
#include "memory/memory.h"
|
2011-11-12 19:14:09 +01:00
|
|
|
#include "Channels/channels.h"
|
2020-12-12 22:33:31 +01:00
|
|
|
#include "cache/cache.hpp"
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DISABLED,
|
|
|
|
ENABLED,
|
|
|
|
HIDEFORBIDDEN
|
|
|
|
};
|
2012-06-17 20:02:25 +02:00
|
|
|
|
2010-09-18 13:46:25 +02:00
|
|
|
GameList gameList;
|
|
|
|
|
|
|
|
void GameList::clear()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
GameFilter.clear();
|
|
|
|
FullGameList.clear();
|
|
|
|
GamePartitionList.clear();
|
|
|
|
FilteredList.clear();
|
2023-01-01 18:00:14 +01:00
|
|
|
EnabledGameList.clear();
|
2011-07-26 00:28:22 +02:00
|
|
|
//! Clear memory of the vector completely
|
|
|
|
std::vector<struct discHdr *>().swap(FilteredList);
|
2023-01-01 18:00:14 +01:00
|
|
|
std::vector<struct discHdr *>().swap(EnabledGameList);
|
2011-07-26 00:28:22 +02:00
|
|
|
std::vector<struct discHdr>().swap(FullGameList);
|
|
|
|
std::vector<int>().swap(GamePartitionList);
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
struct discHdr *GameList::GetDiscHeader(const char *gameID) const
|
2010-10-27 21:50:48 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (!gameID)
|
|
|
|
return NULL;
|
2011-02-03 22:46:54 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
for (u32 i = 0; i < FilteredList.size(); ++i)
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (strncasecmp(gameID, (const char *)FilteredList[i]->id, 6) == 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
return FilteredList[i];
|
|
|
|
}
|
2010-10-27 21:50:48 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return NULL;
|
2010-10-27 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 19:30:15 +01:00
|
|
|
int GameList::GetPartitionNumber(const u8 *gameID) const
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (!gameID)
|
|
|
|
return -1;
|
2011-02-03 22:46:54 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
for (u32 i = 0; i < FullGameList.size(); ++i)
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (strncasecmp((const char *)gameID, (const char *)FullGameList[i].id, 6) == 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
return GamePartitionList[i];
|
|
|
|
}
|
2011-02-02 19:30:15 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return -1;
|
2011-02-02 19:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameList::RemovePartition(int part)
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
for (u32 i = 0; i < GamePartitionList.size(); ++i)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (GamePartitionList[i] == part)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
FullGameList.erase(FullGameList.begin() + i);
|
|
|
|
GamePartitionList.erase(GamePartitionList.begin() + i);
|
2011-07-26 00:28:22 +02:00
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
if (FullGameList.size() > 0)
|
2011-11-12 19:14:09 +01:00
|
|
|
FilterList();
|
2011-02-02 19:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int GameList::InternalReadList(int part)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
// Retrieve all stuff from WBFS
|
|
|
|
u32 cnt = 0;
|
|
|
|
|
|
|
|
int ret = WBFS_GetCount(part, &cnt);
|
2020-12-12 22:33:31 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
// We are done here if no games are there
|
2020-12-12 22:33:31 +01:00
|
|
|
if (cnt == 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
return 0;
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
// Sort the titles by game ID for faster searching
|
|
|
|
GameTitles.SortTitleList();
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Buffer length */
|
|
|
|
u32 len = sizeof(struct discHdr) * cnt;
|
|
|
|
|
|
|
|
/* Allocate memory */
|
2020-12-12 22:33:31 +01:00
|
|
|
struct discHdr *buffer = (struct discHdr *)allocate_memory(len);
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
/* Clear buffer */
|
|
|
|
memset(buffer, 0, len);
|
|
|
|
|
|
|
|
/* Get header list */
|
|
|
|
ret = WBFS_GetHeaders(part, buffer, cnt, sizeof(struct discHdr));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 oldSize = FullGameList.size();
|
|
|
|
std::vector<struct discHdr> PartGameList(cnt);
|
|
|
|
memcpy(&PartGameList[0], buffer, len);
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
for (u32 i = 0; i < PartGameList.size(); i++)
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
for (u32 j = 0; j < FullGameList.size(); j++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (strncasecmp((const char *)PartGameList[i].id, (const char *)FullGameList[j].id, 6) == 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
PartGameList.erase(PartGameList.begin() + i);
|
2011-07-26 00:28:22 +02:00
|
|
|
--i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
FullGameList.resize(oldSize + PartGameList.size());
|
|
|
|
memcpy(&FullGameList[oldSize], &PartGameList[0], PartGameList.size() * sizeof(struct discHdr));
|
2011-07-26 00:28:22 +02:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
GamePartitionList.resize(oldSize + PartGameList.size());
|
2011-07-26 00:28:22 +02:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
for (u32 i = oldSize; i < GamePartitionList.size(); ++i)
|
2011-07-26 00:28:22 +02:00
|
|
|
GamePartitionList[i] = part;
|
|
|
|
|
|
|
|
return PartGameList.size();
|
2011-02-02 19:30:15 +01:00
|
|
|
}
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
int GameList::ReadGameList(bool use_cache)
|
2011-02-02 19:30:15 +01:00
|
|
|
{
|
2023-01-01 18:00:14 +01:00
|
|
|
if (use_cache && Settings.CacheTitles && isCacheFile(WII_HEADER_CACHE_FILE))
|
2020-12-12 22:33:31 +01:00
|
|
|
{
|
|
|
|
if (FullGameList.empty() && GamePartitionList.empty())
|
|
|
|
LoadGameHeaderCache(FullGameList, GamePartitionList);
|
|
|
|
if (!FullGameList.empty())
|
2023-01-01 18:00:14 +01:00
|
|
|
return FullGameList.size();
|
2020-12-12 22:33:31 +01:00
|
|
|
}
|
2011-07-26 00:28:22 +02:00
|
|
|
// Clear list
|
2011-12-22 23:44:48 +01:00
|
|
|
FullGameList.clear();
|
|
|
|
GamePartitionList.clear();
|
|
|
|
//! Clear memory of the vector completely
|
|
|
|
std::vector<struct discHdr>().swap(FullGameList);
|
|
|
|
std::vector<int>().swap(GamePartitionList);
|
|
|
|
|
|
|
|
int cnt = 0;
|
2011-07-26 00:28:22 +02:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
if (!Settings.MultiplePartitions)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2011-12-22 23:44:48 +01:00
|
|
|
cnt = InternalReadList(Settings.partition);
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-22 19:57:37 +02:00
|
|
|
int partitions = DeviceHandler::GetUSBPartitionCount();
|
2011-02-02 19:30:15 +01:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
for (int part = 0; part < partitions; ++part)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
int ret = InternalReadList(part);
|
2020-12-12 22:33:31 +01:00
|
|
|
if (ret > 0)
|
|
|
|
cnt += ret;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
}
|
2011-02-02 19:30:15 +01:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
if (Settings.CacheTitles)
|
2020-12-12 22:33:31 +01:00
|
|
|
SaveGameHeaderCache(FullGameList, GamePartitionList);
|
2011-12-22 23:44:48 +01:00
|
|
|
return cnt;
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
void GameList::InternalFilterList(std::vector<struct discHdr *> &FullList)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2011-12-22 23:44:48 +01:00
|
|
|
for (u32 i = 0; i < FullList.size(); ++i)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2023-01-01 18:00:14 +01:00
|
|
|
struct discHdr *header = FullList[i];
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
/* Register game */
|
|
|
|
NewTitles::Instance()->CheckGame(header->id);
|
|
|
|
|
|
|
|
/* Filters */
|
|
|
|
if (Settings.GameSort & SORT_FAVORITE)
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
GameStatus *GameStats = GameStatistics.GetGameStatus(header->id);
|
2011-07-26 00:28:22 +02:00
|
|
|
if (Settings.marknewtitles)
|
|
|
|
{
|
|
|
|
bool isNew = NewTitles::Instance()->IsNew(header->id);
|
2020-12-12 22:33:31 +01:00
|
|
|
if (!isNew && (!GameStats || GameStats->FavoriteRank == 0))
|
|
|
|
continue;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (!GameStats || GameStats->FavoriteRank == 0)
|
|
|
|
continue;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
// Ignore uLoader cfg "iso". i was told it is "__CFG_" but not confirmed
|
2020-12-12 22:33:31 +01:00
|
|
|
if (strncasecmp((char *)header->id, "__CFG_", 6) == 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
continue;
|
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
GameCFG *GameConfig = GameSettings.GetGameCFG(header);
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
/* Rating based parental control method */
|
|
|
|
if (Settings.parentalcontrol != PARENTAL_LVL_ADULT && !Settings.godmode)
|
|
|
|
{
|
|
|
|
if (GameConfig && GameConfig->parentalcontrol > Settings.parentalcontrol)
|
|
|
|
continue;
|
|
|
|
|
2011-10-21 20:48:10 +02:00
|
|
|
// Check game rating in GameTDB, since the default Wii parental control setting is enabled
|
2020-12-12 22:33:31 +01:00
|
|
|
int rating = GameTitles.GetParentalRating((char *)header->id);
|
2011-07-26 00:28:22 +02:00
|
|
|
if (rating > Settings.parentalcontrol)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Per game lock method
|
2020-12-12 22:33:31 +01:00
|
|
|
if (!Settings.godmode && GameConfig && GameConfig->Locked)
|
2011-07-26 00:28:22 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
//! Category filter
|
|
|
|
u32 n;
|
2012-06-09 14:20:14 +02:00
|
|
|
int allType = DISABLED;
|
|
|
|
// verify the display mode for category "All"
|
2020-12-12 22:33:31 +01:00
|
|
|
for (n = 0; n < Settings.EnabledCategories.size(); ++n)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (Settings.EnabledCategories[n] == 0)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
|
|
|
allType = ENABLED; // All = Enabled
|
2011-07-26 00:28:22 +02:00
|
|
|
break;
|
2012-06-09 14:20:14 +02:00
|
|
|
}
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
for (n = 0; n < Settings.ForbiddenCategories.size(); ++n)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (Settings.ForbiddenCategories[n] == 0)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
|
|
|
allType = HIDEFORBIDDEN; // All = Enabled but hide Forbidden categories
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
|
|
|
|
if (allType == DISABLED)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
|
|
|
// Remove TitleID if it contains a forbidden categories
|
2020-12-12 22:33:31 +01:00
|
|
|
for (n = 0; n < Settings.ForbiddenCategories.size(); ++n)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (GameCategories.isInCategory((char *)header->id, Settings.ForbiddenCategories[n]))
|
2012-06-09 14:20:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
if (n < Settings.ForbiddenCategories.size())
|
2012-06-09 14:20:14 +02:00
|
|
|
continue;
|
2020-12-12 22:33:31 +01:00
|
|
|
|
2012-06-09 14:20:14 +02:00
|
|
|
// Remove TitleID is it doesn't contain a required categories
|
2020-12-12 22:33:31 +01:00
|
|
|
for (n = 0; n < Settings.RequiredCategories.size(); ++n)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (!GameCategories.isInCategory((char *)header->id, Settings.RequiredCategories[n]))
|
2012-06-09 14:20:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
if (n < Settings.RequiredCategories.size())
|
2012-06-09 14:20:14 +02:00
|
|
|
continue;
|
2020-12-12 22:33:31 +01:00
|
|
|
|
2012-06-09 14:20:14 +02:00
|
|
|
// If there's no required categories, verify if the TitleID should be kept or removed
|
2020-12-12 22:33:31 +01:00
|
|
|
if (Settings.RequiredCategories.size() == 0)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
for (n = 0; n < Settings.EnabledCategories.size(); ++n)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (GameCategories.isInCategory((char *)header->id, Settings.EnabledCategories[n]))
|
2012-06-09 14:20:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
if (n == Settings.EnabledCategories.size())
|
2012-06-09 14:20:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
|
|
|
|
if (allType == HIDEFORBIDDEN)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
|
|
|
// Remove TitleID if it contains a forbidden categories
|
2020-12-12 22:33:31 +01:00
|
|
|
for (n = 0; n < Settings.ForbiddenCategories.size(); ++n)
|
2012-06-09 14:20:14 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (GameCategories.isInCategory((char *)header->id, Settings.ForbiddenCategories[n]))
|
|
|
|
if (Settings.ForbiddenCategories[n] > 0)
|
2012-06-09 14:20:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
if (n < Settings.ForbiddenCategories.size())
|
2012-06-09 14:20:14 +02:00
|
|
|
continue;
|
2020-12-12 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
FilteredList.push_back(header);
|
|
|
|
}
|
2011-12-22 23:44:48 +01:00
|
|
|
}
|
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
int GameList::FilterList(const wchar_t *gameFilter)
|
2011-12-22 23:44:48 +01:00
|
|
|
{
|
|
|
|
if (gameFilter)
|
|
|
|
GameFilter.assign(gameFilter);
|
|
|
|
|
|
|
|
FilteredList.clear();
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
EnabledList();
|
|
|
|
InternalFilterList(EnabledGameList);
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
NewTitles::Instance()->Save();
|
2011-11-12 19:14:09 +01:00
|
|
|
GuiSearchBar::FilterList(FilteredList, GameFilter);
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
SortList();
|
|
|
|
|
|
|
|
return FilteredList.size();
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
void GameList::InternalLoadUnfiltered(std::vector<struct discHdr *> &FullList)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2011-12-22 23:44:48 +01:00
|
|
|
for (u32 i = 0; i < FullList.size(); ++i)
|
|
|
|
{
|
2023-01-01 18:00:14 +01:00
|
|
|
struct discHdr *header = FullList[i];
|
2011-11-12 19:14:09 +01:00
|
|
|
|
2011-12-22 23:44:48 +01:00
|
|
|
/* Register game */
|
|
|
|
NewTitles::Instance()->CheckGame(header->id);
|
2011-11-12 19:14:09 +01:00
|
|
|
|
2011-12-22 23:44:48 +01:00
|
|
|
FilteredList.push_back(header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GameList::LoadUnfiltered()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
GameFilter.clear();
|
|
|
|
FilteredList.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
EnabledList();
|
|
|
|
InternalLoadUnfiltered(EnabledGameList);
|
2020-12-12 22:33:31 +01:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
NewTitles::Instance()->Save();
|
|
|
|
GuiSearchBar::FilterList(FilteredList, GameFilter);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
SortList();
|
2012-02-09 22:18:16 +01:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
return FilteredList.size();
|
|
|
|
}
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
int GameList::EnabledList()
|
|
|
|
{
|
|
|
|
EnabledGameList.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
if (Settings.TitlesType == TITLETYPE_FROMWIITDB)
|
|
|
|
GameTitles.LoadTitlesFromGameTDB(Settings.titlestxt_path);
|
|
|
|
|
|
|
|
GetGameListHeaders(EnabledGameList, Settings.LoaderMode);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
return EnabledGameList.size();
|
|
|
|
}
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
void GameList::InternalGetGameListHeaders(std::vector<struct discHdr *> &tmplist, std::vector<struct discHdr> &FullList)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < FullList.size(); ++i)
|
|
|
|
{
|
|
|
|
struct discHdr *header = &FullList[i];
|
|
|
|
tmplist.push_back(header);
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
int GameList::GetGameListHeaders(std::vector<struct discHdr *> &tmplist, short LoaderMode)
|
|
|
|
{
|
|
|
|
// Filter current game list if selected
|
|
|
|
if (LoaderMode & MODE_WIIGAMES)
|
|
|
|
{
|
|
|
|
if (FullGameList.size() == 0)
|
|
|
|
ReadGameList(true);
|
|
|
|
InternalGetGameListHeaders(tmplist, FullGameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter GC game list if selected
|
|
|
|
if (LoaderMode & MODE_GCGAMES)
|
|
|
|
InternalGetGameListHeaders(tmplist, GCGames::Instance()->GetHeaders());
|
|
|
|
|
|
|
|
// Filter NAND channel list if selected
|
|
|
|
if (LoaderMode & MODE_NANDCHANNELS)
|
|
|
|
InternalGetGameListHeaders(tmplist, Channels::Instance()->GetNandHeaders());
|
|
|
|
|
|
|
|
// Filter EmuNAND channel list if selected
|
|
|
|
if (LoaderMode & MODE_EMUCHANNELS)
|
|
|
|
InternalGetGameListHeaders(tmplist, Channels::Instance()->GetEmuHeaders());
|
|
|
|
|
|
|
|
return tmplist.size();
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameList::SortList()
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
if (FilteredList.size() < 2)
|
|
|
|
return;
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
if (Settings.GameSort & SORT_PLAYCOUNT)
|
|
|
|
{
|
|
|
|
std::sort(FilteredList.begin(), FilteredList.end(), PlaycountSortCallback);
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
else if (Settings.GameSort & SORT_RANKING)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
std::sort(FilteredList.begin(), FilteredList.end(), RankingSortCallback);
|
|
|
|
}
|
2020-12-12 22:33:31 +01:00
|
|
|
else if (Settings.GameSort & SORT_PLAYERS)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
std::sort(FilteredList.begin(), FilteredList.end(), PlayersSortCallback);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::sort(FilteredList.begin(), FilteredList.end(), NameSortCallback);
|
|
|
|
}
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 17:12:16 +02:00
|
|
|
bool GameList::NameSortCallback(const struct discHdr *a, const struct discHdr *b)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
return (strcasecmp(GameTitles.GetTitle((struct discHdr *)a), GameTitles.GetTitle((struct discHdr *)b)) < 0);
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 17:12:16 +02:00
|
|
|
bool GameList::PlaycountSortCallback(const struct discHdr *a, const struct discHdr *b)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
int count1 = GameStatistics.GetPlayCount(a->id);
|
|
|
|
int count2 = GameStatistics.GetPlayCount(b->id);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
if (count1 == count2)
|
|
|
|
return NameSortCallback(a, b);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return (count1 > count2);
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2010-11-07 21:31:45 +01:00
|
|
|
bool GameList::RankingSortCallback(const struct discHdr *a, const struct discHdr *b)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
int fav1 = GameStatistics.GetFavoriteRank(a->id);
|
2010-09-25 10:51:44 +02:00
|
|
|
int fav2 = GameStatistics.GetFavoriteRank(b->id);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
if (fav1 == fav2)
|
|
|
|
return NameSortCallback(a, b);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return (fav1 > fav2);
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
2011-02-02 19:30:15 +01:00
|
|
|
|
|
|
|
bool GameList::PlayersSortCallback(const struct discHdr *a, const struct discHdr *b)
|
|
|
|
{
|
2020-12-12 22:33:31 +01:00
|
|
|
int count1 = GameTitles.GetPlayersCount((const char *)a->id);
|
|
|
|
int count2 = GameTitles.GetPlayersCount((const char *)b->id);
|
2011-02-02 19:30:15 +01:00
|
|
|
|
2020-12-12 22:33:31 +01:00
|
|
|
if (count1 == count2)
|
|
|
|
return NameSortCallback(a, b);
|
2011-02-02 19:30:15 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return (count1 > count2);
|
2011-02-02 19:30:15 +01:00
|
|
|
}
|