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>
|
|
|
|
#include "usbloader/wbfs.h"
|
|
|
|
#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"
|
2010-09-18 13:46:25 +02:00
|
|
|
#include "xml/xml.h"
|
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
#include "GameList.h"
|
2010-11-06 16:30:14 +01:00
|
|
|
#include "memory/memory.h"
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
GameList gameList;
|
|
|
|
|
|
|
|
void GameList::clear()
|
|
|
|
{
|
2010-10-31 10:30:53 +01:00
|
|
|
GameFilter.clear();
|
|
|
|
AvailableSearchChars.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
FullGameList.clear();
|
|
|
|
FilteredList.clear();
|
|
|
|
//! Clear memory of the vector completely
|
2010-09-24 02:48:03 +02:00
|
|
|
std::vector<struct discHdr *>().swap(FilteredList);
|
|
|
|
std::vector<struct discHdr>().swap(FullGameList);
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
struct discHdr * GameList::GetDiscHeader(const char * gameID) const
|
2010-10-27 21:50:48 +02:00
|
|
|
{
|
|
|
|
for (u32 i = 0; i < FilteredList.size(); ++i)
|
|
|
|
{
|
|
|
|
if(strncasecmp(gameID, (const char *) FilteredList[i]->id, 6) == 0)
|
|
|
|
return FilteredList[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-18 13:46:25 +02:00
|
|
|
int GameList::ReadGameList()
|
|
|
|
{
|
2010-10-31 10:30:53 +01:00
|
|
|
// Clear list
|
|
|
|
clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
// Retrieve all stuff from WBFS
|
|
|
|
u32 cnt;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
int ret = WBFS_GetCount(&cnt);
|
|
|
|
if (ret < 0) return -1;
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-10-31 10:30:53 +01:00
|
|
|
// We are done here if no games are there
|
|
|
|
if(cnt == 0)
|
|
|
|
return 0;
|
|
|
|
|
2010-09-18 13:46:25 +02:00
|
|
|
/* Buffer length */
|
2010-09-24 02:48:03 +02:00
|
|
|
u32 len = sizeof(struct discHdr) * cnt;
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
/* Allocate memory */
|
2010-09-24 02:48:03 +02:00
|
|
|
struct discHdr *buffer = (struct discHdr *) allocate_memory( len );
|
|
|
|
if (!buffer) return -1;
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
/* Clear buffer */
|
2010-09-24 02:48:03 +02:00
|
|
|
memset(buffer, 0, len);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
/* Get header list */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = WBFS_GetHeaders(buffer, cnt, sizeof(struct discHdr));
|
|
|
|
if (ret < 0)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (buffer) free(buffer);
|
2010-09-18 13:46:25 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
FullGameList.resize(cnt);
|
|
|
|
memcpy(&FullGameList[0], buffer, len);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
free(buffer);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return LoadUnfiltered();
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 17:12:16 +02:00
|
|
|
static bool WCharSortCallback(const wchar_t char1, const wchar_t char2)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (char2 == 0) return true;
|
|
|
|
if (char1 == 0) return false;
|
2010-09-19 17:12:16 +02:00
|
|
|
|
2010-09-18 13:46:25 +02:00
|
|
|
return char2 > char1;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
int GameList::FilterList(const wchar_t * gameFilter)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (FullGameList.size() == 0) ReadGameList();
|
|
|
|
if (gameFilter) GameFilter.assign(gameFilter);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
FilteredList.clear();
|
|
|
|
AvailableSearchChars.clear();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u32 i = 0; i < FullGameList.size(); ++i)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
struct discHdr *header = &FullGameList[i];
|
|
|
|
|
|
|
|
/* Register game */
|
2010-09-24 02:48:03 +02:00
|
|
|
NewTitles::Instance()->CheckGame(header->id);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
/* Filters */
|
2010-11-07 21:31:45 +01:00
|
|
|
if (Settings.GameSort & SORT_FAVORITE)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-25 10:51:44 +02:00
|
|
|
GameStatus * GameStats = GameStatistics.GetGameStatus(header->id);
|
2011-01-16 14:12:07 +01:00
|
|
|
if (Settings.marknewtitles)
|
|
|
|
{
|
|
|
|
bool isNew = NewTitles::Instance()->IsNew(header->id);
|
|
|
|
if (!isNew && (!GameStats || GameStats->FavoriteRank == 0)) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!GameStats || GameStats->FavoriteRank == 0) continue;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//ignore uLoader cfg "iso". i was told it is "__CFG_" but not confirmed
|
2010-10-28 11:00:52 +02:00
|
|
|
if (strncasecmp((char*) header->id, "__CFG_", 6) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
GameCFG * GameConfig = GameSettings.GetGameCFG(header);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
/* Rating based parental control method */
|
2011-01-20 16:00:55 +01:00
|
|
|
if (Settings.parentalcontrol != PARENTAL_LVL_ADULT && !Settings.godmode)
|
2010-10-28 11:00:52 +02:00
|
|
|
{
|
2010-12-29 11:22:11 +01:00
|
|
|
if (GameConfig && GameConfig->parentalcontrol > Settings.parentalcontrol)
|
2010-10-28 11:00:52 +02:00
|
|
|
continue;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
// Check game rating in WiiTDB, since the default Wii parental control setting is enabled
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
int rating = GameTitles.GetParentalRating((char *) header->id);
|
|
|
|
if (rating > Settings.parentalcontrol)
|
2010-09-19 01:16:05 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-10-28 11:00:52 +02:00
|
|
|
//! Per game lock method
|
2011-01-20 16:00:55 +01:00
|
|
|
if(!Settings.godmode && GameConfig && GameConfig->Locked)
|
2010-09-28 20:58:56 +02:00
|
|
|
continue;
|
|
|
|
|
2010-10-28 11:00:52 +02:00
|
|
|
wchar_t *gameName = charToWideChar(GameTitles.GetTitle(header));
|
2010-09-24 02:48:03 +02:00
|
|
|
if (gameName && *GameFilter.c_str())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (wcsnicmp(gameName, GameFilter.c_str(), GameFilter.size()) != 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-01-01 14:02:26 +01:00
|
|
|
delete [] gameName;
|
2010-09-19 01:16:05 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (gameName)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-01-01 14:02:26 +01:00
|
|
|
if (wcslen(gameName) > GameFilter.size() && AvailableSearchChars.find(gameName[GameFilter.size()]) == std::string::npos)
|
|
|
|
AvailableSearchChars.push_back(gameName[GameFilter.size()]);
|
|
|
|
|
|
|
|
delete [] gameName;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
FilteredList.push_back(header);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
NewTitles::Instance()->Save();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
AvailableSearchChars.push_back(L'\0');
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
if (FilteredList.size() < 2)
|
|
|
|
AvailableSearchChars.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
SortList();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return FilteredList.size();
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int GameList::LoadUnfiltered()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (FullGameList.size() == 0) ReadGameList();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
GameFilter.clear();
|
|
|
|
AvailableSearchChars.clear();
|
|
|
|
FilteredList.clear();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u32 i = 0; i < FullGameList.size(); ++i)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
struct discHdr *header = &FullGameList[i];
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Register game */
|
2010-09-24 02:48:03 +02:00
|
|
|
NewTitles::Instance()->CheckGame(header->id);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-10-28 11:00:52 +02:00
|
|
|
wchar_t *gameName = charToWideChar(GameTitles.GetTitle(header));
|
2010-09-24 02:48:03 +02:00
|
|
|
if (gameName)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-01-13 20:05:31 +01:00
|
|
|
if (wcslen(gameName) > GameFilter.size() && AvailableSearchChars.find(gameName[GameFilter.size()]) == std::string::npos)
|
|
|
|
AvailableSearchChars.push_back(gameName[GameFilter.size()]);
|
2010-09-24 02:48:03 +02:00
|
|
|
delete[] gameName;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
FilteredList.push_back(header);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
NewTitles::Instance()->Save();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
AvailableSearchChars.push_back(L'\0');
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
if (FilteredList.size() < 2)
|
|
|
|
AvailableSearchChars.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
|
|
|
SortList();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return FilteredList.size();
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameList::SortList()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (FilteredList.size() < 2) return;
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-11-07 21:31:45 +01:00
|
|
|
if (Settings.GameSort & SORT_PLAYCOUNT)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
std::sort(FilteredList.begin(), FilteredList.end(), PlaycountSortCallback);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-11-07 21:31:45 +01:00
|
|
|
else if(Settings.GameSort & SORT_RANKING)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-11-07 21:31:45 +01:00
|
|
|
std::sort(FilteredList.begin(), FilteredList.end(), RankingSortCallback);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
std::sort(FilteredList.begin(), FilteredList.end(), NameSortCallback);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
if (AvailableSearchChars.size() > 1)
|
|
|
|
std::sort(AvailableSearchChars.begin(), AvailableSearchChars.end(), WCharSortCallback);
|
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
|
|
|
{
|
2010-10-28 11:00:52 +02: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
|
|
|
{
|
2010-09-25 10:51:44 +02:00
|
|
|
int count1 = GameStatistics.GetPlayCount(a->id);
|
|
|
|
int count2 = GameStatistics.GetPlayCount(b->id);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (count1 == count2) return NameSortCallback(a, b);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 17:12:16 +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
|
|
|
{
|
2010-09-25 10:51:44 +02:00
|
|
|
int fav1 = GameStatistics.GetFavoriteRank(a->id);
|
|
|
|
int fav2 = GameStatistics.GetFavoriteRank(b->id);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (fav1 == fav2) return NameSortCallback(a, b);
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 17:12:16 +02:00
|
|
|
return (fav1 > fav2);
|
2010-09-18 13:46:25 +02:00
|
|
|
}
|