usbloadergx/source/settings/GameTitles.cpp
dimok321 6f63f9cf05 *Prepare source code for devkitPPC r23 - replaced removed directory functions
*Added additional sort mode - "Sort by number of players"
*Added support for multiple game partitions.

Note: You can activate multiple game partitions support in the Loader Settings. When it is active, all games from all partitions will be listed in the game list. Partitions can be mixed up as you wish wbfs/fat/ntfs/ext. When the multiple partitions feature is activated than the partition in "Game/Install Partition" setting is taken for new game installation. Also the free space amount will be shown from that game installation partition. This will be clickable in the future listing all partitions with their sizes.
2011-02-02 18:30:15 +00:00

144 lines
3.2 KiB
C++

#include <string.h>
#include "GameTitles.h"
#include "CSettings.h"
#include "usbloader/GameList.h"
#include "xml/xml.h"
#include "xml/WiiTDB.hpp"
CGameTitles GameTitles;
void CGameTitles::SetGameTitle(const char * id, const char * title)
{
if(!id || !title)
return;
for(u32 i = 0; i < TitleList.size(); ++i)
{
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
{
TitleList[i].Title = title;
return;
}
}
GameTitle newTitle;
newTitle.Title = title;
//! Just in case a 0 termination is missing
int n;
for(n = 0; n < 6; ++n)
newTitle.GameID[n] = id[n];
newTitle.GameID[n] = '\0';
TitleList.push_back(newTitle);
}
const char * CGameTitles::GetTitle(const char * id) const
{
if(!id)
return NULL;
for(u32 i = 0; i < TitleList.size(); ++i)
{
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
return TitleList[i].Title.c_str();
}
return NULL;
}
const char * CGameTitles::GetTitle(const struct discHdr *header) const
{
if(!header)
return NULL;
for(u32 i = 0; i < TitleList.size(); ++i)
{
if(strncasecmp((const char *) header->id, TitleList[i].GameID, 6) == 0)
return TitleList[i].Title.c_str();
}
return header->title;
}
int CGameTitles::GetParentalRating(const char * id) const
{
if(!id)
return -1;
for(u32 i = 0; i < TitleList.size(); ++i)
{
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
return TitleList[i].ParentalRating;
}
return -1;
}
int CGameTitles::GetPlayersCount(const char * id) const
{
if(!id)
return 1;
for(u32 i = 0; i < TitleList.size(); ++i)
{
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
return TitleList[i].PlayersCount;
}
return 1;
}
void CGameTitles::SetDefault()
{
TitleList.clear();
//! Free vector memory
std::vector<GameTitle>().swap(TitleList);
}
void CGameTitles::LoadTitlesFromWiiTDB(const char * path)
{
this->SetDefault();
if(!path || !Settings.titlesOverride)
return;
gameList.LoadUnfiltered();
std::string Title;
std::string Filepath = path;
if(path[strlen(path)-1] != '/')
Filepath += '/';
Filepath += "wiitdb.xml";
WiiTDB XML_DB(Filepath.c_str());
XML_DB.SetLanguageCode(Settings.db_language);
int Rating;
std::string RatValTxt;
for(int i = 0; i < gameList.GameCount(); ++i)
{
if(!XML_DB.GetTitle((const char *) gameList[i]->id, Title))
continue;
this->SetGameTitle(gameList[i]->id, Title.c_str());
TitleList[TitleList.size()-1].ParentalRating = -1;
TitleList[TitleList.size()-1].PlayersCount = 1;
Rating = XML_DB.GetRating((const char *) gameList[i]->id);
if(Rating < 0)
continue;
if(!XML_DB.GetRatingValue((const char *) gameList[i]->id, RatValTxt))
continue;
TitleList[TitleList.size()-1].ParentalRating = ConvertRating(RatValTxt.c_str(), WiiTDB::RatingToString(Rating), "PEGI");
int ret = XML_DB.GetPlayers((const char *) gameList[i]->id);
if(ret > 0)
TitleList[TitleList.size()-1].PlayersCount = ret;
}
}