2009-10-01 01:10:58 +02:00
|
|
|
/*
|
2010-09-24 02:48:03 +02:00
|
|
|
Load game information from XML - Lustar
|
2009-10-01 01:10:58 +02:00
|
|
|
- Mini-XML by Michael Sweet
|
|
|
|
- MiniZip adapted by Tantric
|
2010-09-24 02:48:03 +02:00
|
|
|
*/
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
#include <malloc.h>
|
2010-09-24 14:57:38 +02:00
|
|
|
#include <unzip/unzip.h>
|
2010-09-19 22:25:12 +02:00
|
|
|
#include "settings/CSettings.h"
|
2010-09-24 23:22:01 +02:00
|
|
|
#include "settings/CGameSettings.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "xml/xml.h"
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
extern void title_set(char *id, char *title);
|
|
|
|
extern char* trimcopy(char *dest, char *src, int size);
|
|
|
|
extern char game_partition[6];
|
2010-09-19 22:25:12 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* config */
|
|
|
|
static bool xmldebug = false;
|
2010-01-19 11:48:50 +01:00
|
|
|
static char xmlcfg_filename[100] = "wiitdb";
|
2009-10-01 01:10:58 +02:00
|
|
|
static int xmlmaxsize = 1572864;
|
|
|
|
|
|
|
|
struct gameXMLinfo gameinfo;
|
|
|
|
struct gameXMLinfo gameinfo_reset;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
static char langlist[11][22] = { { "Console Default" }, { "Japanese" }, { "English" }, { "German" }, { "French" }, {
|
|
|
|
"Spanish" }, { "Italian" }, { "Dutch" }, { "S. Chinese" }, { "T. Chinese" }, { "Korean" } };
|
|
|
|
|
|
|
|
static char langcodes[11][5] = { { "" }, { "JA" }, { "EN" }, { "DE" }, { "FR" }, { "ES" }, { "IT" }, { "NL" },
|
|
|
|
{ "ZHCN" }, // People's Republic of China
|
|
|
|
{ "ZHTW" }, // Taiwan
|
|
|
|
{ "KO" } };
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
static char element_text[5000];
|
2010-09-19 01:16:05 +02:00
|
|
|
static mxml_node_t *nodetree = NULL;
|
|
|
|
static mxml_node_t *nodedata = NULL;
|
|
|
|
static mxml_node_t *nodeid = NULL;
|
|
|
|
static mxml_node_t *nodeidtmp = NULL;
|
|
|
|
static mxml_node_t *nodefound = NULL;
|
|
|
|
static mxml_index_t *nodeindex = NULL;
|
|
|
|
static mxml_index_t *nodeindextmp = NULL;
|
2009-10-01 01:10:58 +02:00
|
|
|
int xmlloadtime = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
char * get_nodetext(mxml_node_t *node, char *buffer, int buflen);
|
2009-10-01 01:10:58 +02:00
|
|
|
bool xml_loaded = false;
|
|
|
|
|
|
|
|
/* load renamed titles from proper names and game info XML, needs to be after cfg_load_games */
|
2010-09-24 02:48:03 +02:00
|
|
|
bool OpenXMLDatabase(char* xmlfilepath, char* argdblang, bool argJPtoEN, bool openfile, bool loadtitles, bool keepopen)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!xml_loaded)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
bool opensuccess = false;
|
2010-01-19 11:48:50 +01:00
|
|
|
char pathname[200];
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(pathname, sizeof(pathname), "%s", xmlfilepath);
|
|
|
|
if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/", pathname);
|
|
|
|
snprintf(pathname, sizeof(pathname), "%s%s_%s.zip", pathname, xmlcfg_filename, game_partition);
|
|
|
|
if (openfile) opensuccess = OpenXMLFile(pathname);
|
|
|
|
if (!opensuccess)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(pathname, sizeof(pathname), "%s", xmlfilepath);
|
|
|
|
if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/", pathname);
|
|
|
|
snprintf(pathname, sizeof(pathname), "%swiitdb.zip", pathname);
|
|
|
|
if (openfile) opensuccess = OpenXMLFile(pathname);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!opensuccess && openfile)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
CloseXMLDatabase();
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (loadtitles) LoadTitlesFromXML(argdblang, argJPtoEN);
|
|
|
|
if (!keepopen) CloseXMLDatabase();
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (loadtitles) LoadTitlesFromXML(argdblang, argJPtoEN);
|
|
|
|
if (!keepopen) CloseXMLDatabase();
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void CloseXMLDatabase()
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
/* free memory */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (xml_loaded)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlDelete(nodedata);
|
|
|
|
mxmlDelete(nodetree);
|
2009-10-01 01:10:58 +02:00
|
|
|
xml_loaded = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, const char *nodename, const char *attributename,
|
|
|
|
char *value, int descend, char *dest, int destsize)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
*element_text = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(currentnode, topnode, nodename, attributename, value, descend);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (attributename != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(dest, mxmlElementGetAttr(nodefound, attributename), destsize);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
get_nodetext(nodefound, element_text, sizeof(element_text));
|
|
|
|
strlcpy(dest, element_text, destsize);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strcpy(dest, "");
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool OpenXMLFile(char *filename)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
//if (xmldebug) dbg_time1();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (xml_loaded) return false;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
gameinfo = gameinfo_reset;
|
2010-09-19 01:16:05 +02:00
|
|
|
nodedata = NULL;
|
|
|
|
nodetree = NULL;
|
|
|
|
nodeid = NULL;
|
|
|
|
nodeidtmp = NULL;
|
|
|
|
nodefound = NULL;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char* strresult = strstr(filename, ".zip");
|
|
|
|
if (strresult == NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
/* Load XML file */
|
|
|
|
FILE *filexml;
|
2010-09-24 02:48:03 +02:00
|
|
|
filexml = fopen(filename, "rb");
|
|
|
|
if (!filexml) return false;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodetree = mxmlLoadFile(NULL, filexml, MXML_OPAQUE_CALLBACK);
|
|
|
|
fclose(filexml);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
/* load zipped XML file */
|
2010-09-24 02:48:03 +02:00
|
|
|
unzFile unzfile = unzOpen(filename);
|
|
|
|
if (unzfile == NULL) return false;
|
|
|
|
unzOpenCurrentFile(unzfile);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
unz_file_info zipfileinfo;
|
2010-09-24 02:48:03 +02:00
|
|
|
unzGetCurrentFileInfo(unzfile, &zipfileinfo, NULL, 0, NULL, 0, NULL, 0);
|
2009-10-01 01:10:58 +02:00
|
|
|
int zipfilebuffersize = zipfileinfo.uncompressed_size;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (zipfilebuffersize >= xmlmaxsize)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
unzCloseCurrentFile(unzfile);
|
|
|
|
unzClose(unzfile);
|
2009-10-01 01:10:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char * zipfilebuffer = (char *) malloc(zipfilebuffersize);
|
|
|
|
memset(zipfilebuffer, 0, zipfilebuffersize);
|
|
|
|
if (zipfilebuffer == NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
unzCloseCurrentFile(unzfile);
|
|
|
|
unzClose(unzfile);
|
2009-10-01 01:10:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
unzReadCurrentFile(unzfile, zipfilebuffer, zipfilebuffersize);
|
|
|
|
unzCloseCurrentFile(unzfile);
|
|
|
|
unzClose(unzfile);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodetree = mxmlLoadString(NULL, zipfilebuffer, MXML_OPAQUE_CALLBACK);
|
|
|
|
free(zipfilebuffer);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (nodetree == NULL) return false;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodedata = mxmlFindElement(nodetree, nodetree, "datafile", NULL, NULL, MXML_DESCEND);
|
|
|
|
if (nodedata == NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
return false;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//if (xmldebug) xmlloadtime = dbg_time2(NULL);
|
2009-10-01 01:10:58 +02:00
|
|
|
xml_loaded = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char *GetLangSettingFromGame(char *gameid)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
int langcode;
|
2010-09-24 23:22:01 +02:00
|
|
|
GameCFG *game_cfg = GameSettings.GetGameCFG((u8*) gameid);
|
2010-09-24 02:48:03 +02:00
|
|
|
if (game_cfg)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
langcode = game_cfg->language;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
//langcode = CFG.language; // for Configurable Loader
|
|
|
|
langcode = Settings.language; // for Loader GX
|
|
|
|
}
|
|
|
|
char *langtxt = langlist[langcode];
|
|
|
|
return langtxt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert language text into ISO 639 two-letter language code (+ZHTW/ZHCN) */
|
2010-09-24 02:48:03 +02:00
|
|
|
const char *ConvertLangTextToCode(char *languagetxt)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
// do not convert if languagetext seems to be a language code (can be 2 or 4 letters)
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strlen(languagetxt) <= 4) return languagetxt;
|
2009-10-01 01:10:58 +02:00
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i <= 10; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcasecmp(languagetxt, langlist[i])) // case insensitive comparison
|
|
|
|
return langcodes[i];
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char ConvertRatingToIndex(char *ratingtext)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
int type = -1;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(ratingtext, "CERO"))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
type = 0;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(ratingtext, "ESRB"))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
type = 1;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(ratingtext, "PEGI"))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
type = 2;
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void ConvertRating(char *ratingvalue, char *fromrating, const char *torating, char *destvalue, int destsize)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(fromrating, torating))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(destvalue, ratingvalue, destsize);
|
2009-10-01 01:10:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
strcpy(destvalue, "");
|
2009-10-01 01:10:58 +02:00
|
|
|
int type = -1;
|
|
|
|
int desttype = -1;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
type = ConvertRatingToIndex(fromrating);
|
|
|
|
desttype = ConvertRatingToIndex((char *) torating);
|
|
|
|
if (type == -1 || desttype == -1) return;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* rating conversion table */
|
|
|
|
/* the list is ordered to pick the most likely value first: */
|
|
|
|
/* EC and AO are less likely to be used so they are moved down to only be picked up when converting ESRB to PEGI or CERO */
|
|
|
|
/* the conversion can never be perfect because ratings can differ between regions for the same game */
|
2010-09-24 02:48:03 +02:00
|
|
|
char ratingtable[12][3][5] = { { { "A" }, { "E" }, { "3" } }, { { "A" }, { "E" }, { "4" } }, { { "A" }, { "E" }, {
|
|
|
|
"6" } }, { { "A" }, { "E" }, { "7" } }, { { "A" }, { "EC" }, { "3" } }, { { "A" }, { "E10+" }, { "7" } }, {
|
|
|
|
{ "B" }, { "T" }, { "12" } }, { { "D" }, { "M" }, { "18" } }, { { "D" }, { "M" }, { "16" } }, { { "C" }, {
|
|
|
|
"T" }, { "16" } }, { { "C" }, { "T" }, { "15" } }, { { "Z" }, { "AO" }, { "18" } }, };
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i <= 11; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(ratingtable[i][type], ratingvalue))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(destvalue, ratingtable[i][desttype], destsize);
|
2009-10-01 01:10:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void LoadTitlesFromXML(char *langtxt, bool forcejptoen)
|
2009-10-01 01:10:58 +02:00
|
|
|
/* langtxt: set to "English","French","German", to force language for all titles, or "" to load title depending on each game's setting */
|
|
|
|
/* forcejptoen: set to true to load English title instead of Japanese title when game is set to Japanese */
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (nodedata == NULL) return;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
bool forcelang = false;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strcmp(langtxt, "")) forcelang = true;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
char langcode[10] = "";
|
2010-09-24 02:48:03 +02:00
|
|
|
if (forcelang) strcpy(langcode, ConvertLangTextToCode(langtxt)); /* convert language text into ISO 639 two-letter language code */
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* create index of <id> elements */
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindex = mxmlIndexNew(nodedata, "id", NULL);
|
|
|
|
nodeid = mxmlIndexReset(nodeindex);
|
2009-10-01 01:10:58 +02:00
|
|
|
*element_text = 0;
|
|
|
|
char id_text[10];
|
|
|
|
char title_text[200] = "";
|
|
|
|
char title_text_EN[200] = "";
|
|
|
|
|
|
|
|
/* search index of id elements, load all id/titles text */
|
2010-09-24 02:48:03 +02:00
|
|
|
while (nodeid != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeid = mxmlIndexFind(nodeindex, "id", NULL);
|
|
|
|
if (nodeid != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strcpy(title_text, "");
|
|
|
|
strcpy(title_text_EN, "");
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
get_nodetext(nodeid, element_text, sizeof(element_text));
|
|
|
|
snprintf(id_text, 7, "%s", element_text);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
// if language is not forced, use game language setting from config
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!forcelang)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
langtxt = GetLangSettingFromGame(id_text);
|
|
|
|
strcpy(langcode, ConvertLangTextToCode(langtxt));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if enabled, force English title for all games set to Japanese */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (forcejptoen && (!strcmp(langcode, "JA"))) strcpy(langcode, "EN");
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* load title from nodes */
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", "EN", MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, title_text_EN,
|
|
|
|
sizeof(title_text_EN));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", langcode, MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, title_text, sizeof(title_text));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fall back to English title if prefered language was not found */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(title_text, ""))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strcpy(title_text, title_text_EN);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(id_text, 7, "%s", id_text);
|
|
|
|
title_set(id_text, title_text);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// free memory
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlIndexDelete(nodeindex);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
//if (xmldebug) xmlloadtime = dbg_time2(NULL);
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GetPublisherFromGameid(char *idtxt, char *dest, int destsize)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
/* guess publisher from company list using last two characters from game id */
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindextmp = mxmlIndexNew(nodedata, "company", NULL);
|
|
|
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
*element_text = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
char publishercode[3];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(publishercode, "%c%c", idtxt[4], idtxt[5]);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
while (strcmp(element_text, publishercode) != 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeidtmp = mxmlIndexFind(nodeindextmp, "company", NULL);
|
|
|
|
if (nodeidtmp != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(element_text, mxmlElementGetAttr(nodeidtmp, "code"), sizeof(element_text));
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(element_text, publishercode))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(dest, mxmlElementGetAttr(nodeidtmp, "name"), destsize);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strcpy(dest, "");
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// free memory
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlIndexDelete(nodeindextmp);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool LoadGameInfoFromXML(char* gameid, char* langtxt)
|
2009-10-01 01:10:58 +02:00
|
|
|
/* gameid: full game id */
|
|
|
|
/* langtxt: "English","French","German" */
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
bool exist = false;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!xml_loaded || nodedata == NULL) return exist;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
// load game info using forced language, or game individual setting, or main language setting
|
|
|
|
char langcode[100] = "";
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(langtxt, "")) langtxt = GetLangSettingFromGame(gameid);
|
|
|
|
strlcpy(langcode, ConvertLangTextToCode(langtxt), sizeof(langcode));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* reset all game info */
|
|
|
|
gameinfo = gameinfo_reset;
|
|
|
|
|
|
|
|
/* index all IDs */
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindex = mxmlIndexNew(nodedata, "id", NULL);
|
|
|
|
nodeid = mxmlIndexReset(nodeindex);
|
2009-10-01 01:10:58 +02:00
|
|
|
*element_text = 0;
|
|
|
|
/* search for game matching gameid */
|
2010-09-24 02:48:03 +02:00
|
|
|
while (1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeid = mxmlIndexFind(nodeindex, "id", NULL);
|
|
|
|
if (nodeid != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
get_nodetext(nodeid, element_text, sizeof(element_text));
|
|
|
|
if (!strcmp(element_text, gameid))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(element_text, gameid))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
/* text from elements */
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(gameinfo.id, element_text, sizeof(gameinfo.id));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "region", NULL, NULL, MXML_NO_DESCEND, gameinfo.region,
|
|
|
|
sizeof(gameinfo.region));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "version", NULL, NULL, MXML_NO_DESCEND, gameinfo.version,
|
|
|
|
sizeof(gameinfo.version));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "genre", NULL, NULL, MXML_NO_DESCEND, gameinfo.genre, sizeof(gameinfo.genre));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "developer", NULL, NULL, MXML_NO_DESCEND, gameinfo.developer,
|
|
|
|
sizeof(gameinfo.developer));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "publisher", NULL, NULL, MXML_NO_DESCEND, gameinfo.publisher,
|
|
|
|
sizeof(gameinfo.publisher));
|
|
|
|
GetPublisherFromGameid(gameid, gameinfo.publisherfromid, sizeof(gameinfo.publisherfromid));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* text from attributes */
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodeid, nodedata, "date", "year", NULL, MXML_NO_DESCEND, gameinfo.year, sizeof(gameinfo.year));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "date", "month", NULL, MXML_NO_DESCEND, gameinfo.month,
|
|
|
|
sizeof(gameinfo.month));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "date", "day", NULL, MXML_NO_DESCEND, gameinfo.day, sizeof(gameinfo.day));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "rating", "type", NULL, MXML_NO_DESCEND, gameinfo.ratingtype,
|
|
|
|
sizeof(gameinfo.ratingtype));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "rating", "value", NULL, MXML_NO_DESCEND, gameinfo.ratingvalue,
|
|
|
|
sizeof(gameinfo.ratingvalue));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "rom", "crc", NULL, MXML_NO_DESCEND, gameinfo.iso_crc,
|
|
|
|
sizeof(gameinfo.iso_crc));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "rom", "md5", NULL, MXML_NO_DESCEND, gameinfo.iso_md5,
|
|
|
|
sizeof(gameinfo.iso_md5));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "rom", "sha1", NULL, MXML_NO_DESCEND, gameinfo.iso_sha1,
|
|
|
|
sizeof(gameinfo.iso_sha1));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* text from child elements */
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", "EN", MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, gameinfo.title_EN,
|
|
|
|
sizeof(gameinfo.title_EN));
|
|
|
|
GetTextFromNode(nodefound, nodedata, "synopsis", NULL, NULL, MXML_DESCEND, gameinfo.synopsis_EN,
|
|
|
|
sizeof(gameinfo.synopsis_EN));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", langcode, MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, gameinfo.title,
|
|
|
|
sizeof(gameinfo.title));
|
|
|
|
GetTextFromNode(nodefound, nodedata, "synopsis", NULL, NULL, MXML_DESCEND, gameinfo.synopsis,
|
|
|
|
sizeof(gameinfo.synopsis));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
// fall back to English title and synopsis if prefered language was not found
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(gameinfo.title, ""))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(gameinfo.title, gameinfo.title_EN, sizeof(gameinfo.title));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(gameinfo.synopsis, ""))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(gameinfo.synopsis, gameinfo.synopsis_EN, sizeof(gameinfo.synopsis));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* list locale lang attributes */
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", NULL, MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
int incr = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
while (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
++incr;
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(gameinfo.locales[incr], mxmlElementGetAttr(nodefound, "lang"), sizeof(gameinfo.locales[incr]));
|
|
|
|
nodefound = mxmlWalkNext(nodefound, nodedata, MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(nodefound, nodedata, "locale", "lang", NULL, MXML_NO_DESCEND);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unbounded child elements */
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodeid, nodedata, "wi-fi", "players", NULL, MXML_NO_DESCEND, gameinfo.wifiplayers,
|
|
|
|
sizeof(gameinfo.wifiplayers));
|
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "wi-fi", NULL, NULL, MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
gameinfo.wifiCnt = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindextmp = mxmlIndexNew(nodefound, "feature", NULL);
|
|
|
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
|
|
|
while (nodeidtmp != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeidtmp = mxmlIndexFind(nodeindextmp, "feature", NULL);
|
|
|
|
if (nodeidtmp != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
++gameinfo.wifiCnt;
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodeidtmp, nodedata, "feature", NULL, NULL, MXML_DESCEND,
|
|
|
|
gameinfo.wififeatures[gameinfo.wifiCnt], sizeof(gameinfo.wififeatures[gameinfo.wifiCnt]));
|
|
|
|
gameinfo.wififeatures[gameinfo.wifiCnt][0] = toupper(
|
|
|
|
(int) gameinfo.wififeatures[gameinfo.wifiCnt][0]);
|
|
|
|
if (gameinfo.wifiCnt == XML_ELEMMAX) break;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlIndexDelete(nodeindextmp); // placed after each mxmlIndexNew to prevent memory leak
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "rating", NULL, NULL, MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
gameinfo.descriptorCnt = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindextmp = mxmlIndexNew(nodefound, "descriptor", NULL);
|
|
|
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
|
|
|
while (nodeidtmp != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeidtmp = mxmlIndexFind(nodeindextmp, "descriptor", NULL);
|
|
|
|
if (nodeidtmp != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
++gameinfo.descriptorCnt;
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodeidtmp, nodedata, "descriptor", NULL, NULL, MXML_DESCEND,
|
|
|
|
gameinfo.ratingdescriptors[gameinfo.descriptorCnt],
|
|
|
|
sizeof(gameinfo.ratingdescriptors[gameinfo.descriptorCnt]));
|
|
|
|
if (gameinfo.descriptorCnt == XML_ELEMMAX) break;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlIndexDelete(nodeindextmp);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodeid, nodedata, "input", "players", NULL, MXML_NO_DESCEND, gameinfo.players,
|
|
|
|
sizeof(gameinfo.players));
|
|
|
|
nodefound = mxmlFindElement(nodeid, nodedata, "input", NULL, NULL, MXML_NO_DESCEND);
|
|
|
|
if (nodefound != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
gameinfo.accessoryCnt = 0;
|
|
|
|
gameinfo.accessoryReqCnt = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindextmp = mxmlIndexNew(nodefound, "control", NULL);
|
|
|
|
nodeidtmp = mxmlIndexReset(nodeindextmp);
|
|
|
|
while (nodeidtmp != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeidtmp = mxmlIndexFind(nodeindextmp, "control", NULL);
|
|
|
|
if (nodeidtmp != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(mxmlElementGetAttr(nodeidtmp, "required"), "true") && gameinfo.accessoryReqCnt
|
|
|
|
< XML_ELEMMAX)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
++gameinfo.accessoryReqCnt;
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(gameinfo.accessoriesReq[gameinfo.accessoryReqCnt],
|
|
|
|
mxmlElementGetAttr(nodeidtmp, "type"),
|
|
|
|
sizeof(gameinfo.accessoriesReq[gameinfo.accessoryReqCnt]));
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (gameinfo.accessoryCnt < XML_ELEMMAX)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
++gameinfo.accessoryCnt;
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(gameinfo.accessories[gameinfo.accessoryCnt], mxmlElementGetAttr(nodeidtmp, "type"),
|
|
|
|
sizeof(gameinfo.accessories[gameinfo.accessoryCnt]));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlIndexDelete(nodeindextmp);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert rating value */
|
2010-09-24 02:48:03 +02:00
|
|
|
ConvertRating(gameinfo.ratingvalue, gameinfo.ratingtype, "CERO", gameinfo.ratingvalueCERO,
|
|
|
|
sizeof(gameinfo.ratingvalueCERO));
|
|
|
|
ConvertRating(gameinfo.ratingvalue, gameinfo.ratingtype, "ESRB", gameinfo.ratingvalueESRB,
|
|
|
|
sizeof(gameinfo.ratingvalueESRB));
|
|
|
|
ConvertRating(gameinfo.ratingvalue, gameinfo.ratingtype, "PEGI", gameinfo.ratingvaluePEGI,
|
|
|
|
sizeof(gameinfo.ratingvaluePEGI));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* provide genre as an array: gameinfo.genresplit */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strcmp(gameinfo.genre, "") != 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
gameinfo.genreCnt = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
const char *delimgenre = ",;";
|
|
|
|
char genretxt[200];
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(genretxt, gameinfo.genre, sizeof(genretxt));
|
2009-10-01 01:10:58 +02:00
|
|
|
char *splitresult;
|
2010-09-24 02:48:03 +02:00
|
|
|
splitresult = strtok(genretxt, delimgenre);
|
|
|
|
if (splitresult != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
++gameinfo.genreCnt;
|
2010-09-24 02:48:03 +02:00
|
|
|
trimcopy(splitresult, splitresult, strlen(splitresult) + 1);
|
|
|
|
strlcpy(gameinfo.genresplit[gameinfo.genreCnt], splitresult,
|
|
|
|
sizeof(gameinfo.genresplit[gameinfo.genreCnt]));
|
|
|
|
gameinfo.genresplit[gameinfo.genreCnt][0] = toupper((int) gameinfo.genresplit[gameinfo.genreCnt][0]);
|
|
|
|
while (splitresult != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
splitresult = strtok(NULL, delimgenre);
|
|
|
|
if (splitresult != NULL && strcmp(splitresult, "") != 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
++gameinfo.genreCnt;
|
2010-09-24 02:48:03 +02:00
|
|
|
trimcopy(splitresult, splitresult, strlen(splitresult) + 1);
|
|
|
|
strlcpy(gameinfo.genresplit[gameinfo.genreCnt], splitresult,
|
|
|
|
sizeof(gameinfo.genresplit[gameinfo.genreCnt]));
|
|
|
|
gameinfo.genresplit[gameinfo.genreCnt][0] = toupper(
|
|
|
|
(int) gameinfo.genresplit[gameinfo.genreCnt][0]);
|
|
|
|
if (gameinfo.genreCnt == XML_ELEMMAX) break;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
exist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
/*game not found */
|
2010-09-19 01:16:05 +02:00
|
|
|
exist = false;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if game was not found or info is missing
|
|
|
|
// guess publisher from game id in case it is missing
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(gameinfo.publisher, ""))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
GetPublisherFromGameid(gameid, gameinfo.publisherfromid, sizeof(gameinfo.publisherfromid));
|
|
|
|
strlcpy(gameinfo.publisher, gameinfo.publisherfromid, sizeof(gameinfo.publisher));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if missing, get region from game ID
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(gameinfo.region, ""))
|
|
|
|
{
|
|
|
|
if (gameid[3] == 'E') strlcpy(gameinfo.region, "NTSC-U", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'J') strlcpy(gameinfo.region, "NTSC-J", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'W') strlcpy(gameinfo.region, "NTSC-J", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'K') strlcpy(gameinfo.region, "NTSC-K", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'P') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'D') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'F') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'I') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'S') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'H') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'U') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'X') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'Y') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
|
|
|
if (gameid[3] == 'Z') strlcpy(gameinfo.region, "PAL", sizeof(gameinfo.region));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// free memory
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlIndexDelete(nodeindex);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void PrintGameInfo(bool showfullinfo)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (showfullinfo)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
//Con_Clear();
|
|
|
|
|
|
|
|
//printf("id: %s version: %s region: %s",gameinfo.id, gameinfo.version, gameinfo.region);
|
|
|
|
//printf("title: %s\n",gameinfo.title);
|
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("languages:");
|
|
|
|
for (i = 1; strcmp(gameinfo.locales[i], "") != 0; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
printf(" %s", gameinfo.locales[i]);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("\n");
|
2009-10-01 01:10:58 +02:00
|
|
|
//printf("developer: %s\n",gameinfo.developer);
|
|
|
|
//printf("publisher: %s\n",gameinfo.publisher);
|
|
|
|
//printf("publisher from ID: %s\n",gameinfo.publisherfromid);
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("year:%s month:%s day:%s\n", gameinfo.year, gameinfo.month, gameinfo.day);
|
|
|
|
printf("genre: %s\n", gameinfo.genre);
|
2009-10-01 01:10:58 +02:00
|
|
|
//printf("rating: %s %s (CERO: %s ESRB: %s PEGI: %s)\n",gameinfo.ratingtype, gameinfo.ratingvalue,
|
|
|
|
// gameinfo.ratingvalueCERO,gameinfo.ratingvalueESRB,gameinfo.ratingvaluePEGI);
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("content descriptors:");
|
|
|
|
for (i = 1; strcmp(gameinfo.wififeatures[i], "") != 0; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
printf(" %s", gameinfo.ratingdescriptors[i]);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("\n");
|
|
|
|
printf("players: %s online: %s\n", gameinfo.players, gameinfo.wifiplayers);
|
|
|
|
printf("online features:");
|
|
|
|
for (i = 1; strcmp(gameinfo.wififeatures[i], "") != 0; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
printf(" %s", gameinfo.wififeatures[i]);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("\n");
|
|
|
|
printf("required accessories:");
|
|
|
|
for (i = 1; strcmp(gameinfo.accessoriesReq[i], "") != 0; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
printf(" %s", gameinfo.accessoriesReq[i]);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("\n");
|
|
|
|
printf("accessories:");
|
|
|
|
for (i = 1; strcmp(gameinfo.accessories[i], "") != 0; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
printf(" %s", gameinfo.accessories[i]);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("\n");
|
2009-10-01 01:10:58 +02:00
|
|
|
//printf("iso_crc: %s iso_md5: %s\n",gameinfo.iso_crc,gameinfo.iso_md5);
|
|
|
|
//printf("iso_sha1: %s\n",gameinfo.iso_sha1);
|
|
|
|
//printf("synopsis: %s\n",gameinfo.synopsis);
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
char linebuf[1000] = "";
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (xmldebug)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
//char xmltime[100];
|
|
|
|
//sprintf(xmltime,"%d",xmlloadtime);
|
|
|
|
//printf("xml load time: %s\n",xmltime);
|
|
|
|
/*
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("xml forcelang: %s\n",CFG.db_lang);
|
|
|
|
printf("xml url: %s\n",CFG.db_url);
|
|
|
|
printf("xml file: %s\n",CFG.db_filename);
|
|
|
|
char xmljptoen[100];
|
|
|
|
sprintf(xmljptoen,"%d",CFG.db_JPtoEN);
|
|
|
|
printf("xml JPtoEN: %s\n",xmljptoen);
|
|
|
|
*/
|
|
|
|
printf(MemInfo()); // guidebug
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//printf("%s: ",gameidfull);
|
|
|
|
//printf("%s\n",gameinfo.title);
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strcmp(gameinfo.year, "") != 0) snprintf(linebuf, sizeof(linebuf), "%s ", gameinfo.year);
|
|
|
|
if (strcmp(gameinfo.publisher, "") != 0) snprintf(linebuf, sizeof(linebuf), "%s%s", linebuf, gameinfo.publisher);
|
|
|
|
if (strcmp(gameinfo.developer, "") != 0 && strcmp(gameinfo.developer, gameinfo.publisher) != 0) snprintf(
|
|
|
|
linebuf, sizeof(linebuf), "%s / %s", linebuf, gameinfo.developer);
|
|
|
|
if (strlen(linebuf) >= 100)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
char buffer[200] = "";
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(buffer, linebuf, 100);
|
|
|
|
strcat(buffer, "...");
|
|
|
|
snprintf(linebuf, sizeof(linebuf), "%s", buffer);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("%s\n", linebuf);
|
|
|
|
strcpy(linebuf, "");
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strcmp(gameinfo.ratingvalue, "") != 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(linebuf, sizeof(linebuf), "rated %s", gameinfo.ratingvalue);
|
|
|
|
if (!strcmp(gameinfo.ratingtype, "PEGI")) snprintf(linebuf, sizeof(linebuf), "%s+ ", linebuf);
|
|
|
|
snprintf(linebuf, sizeof(linebuf), "%s ", linebuf);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strcmp(gameinfo.players, "") != 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(linebuf, sizeof(linebuf), "%sfor %s player", linebuf, gameinfo.players);
|
|
|
|
if (atoi(gameinfo.players) > 1) snprintf(linebuf, sizeof(linebuf), "%ss", linebuf);
|
|
|
|
if (atoi(gameinfo.wifiplayers) > 1) snprintf(linebuf, sizeof(linebuf), "%s (%s online)", linebuf,
|
|
|
|
gameinfo.wifiplayers);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("%s\n", linebuf);
|
|
|
|
strcpy(linebuf, "");
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
char *MemInfo()
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
char linebuf[300] = "";
|
|
|
|
char memtotal[20];
|
|
|
|
char memused[20];
|
|
|
|
char memnotinuse[20];
|
|
|
|
char memcanbefreed[20];
|
|
|
|
struct mallinfo mymallinfo = mallinfo();
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(memtotal, "%d", mymallinfo.arena / 1024);
|
|
|
|
sprintf(memused, "%d", mymallinfo.uordblks / 1024);
|
|
|
|
sprintf(memnotinuse, "%d", mymallinfo.fordblks / 1024);
|
|
|
|
sprintf(memcanbefreed, "%d", mymallinfo.keepcost / 1024);
|
|
|
|
snprintf(linebuf, sizeof(linebuf), "all:%sKB used:%sKB notused:%sKB canfree:%sKB", memtotal, memused, memnotinuse,
|
|
|
|
memcanbefreed);
|
2009-10-01 01:10:58 +02:00
|
|
|
char *minfo[300];
|
|
|
|
*minfo = linebuf;
|
|
|
|
return *minfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------------------*/
|
2009-12-12 19:04:35 +01:00
|
|
|
/* get_nodetext() - Get the text for a node, taken from mini-mxml example mxmldoc.c */
|
2010-09-24 02:48:03 +02:00
|
|
|
char * get_nodetext(mxml_node_t *node, char *buffer, int buflen) /* O - Text in node, I - Node to get, I - Buffer, I - Size of buffer */
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
char *ptr, *end; /* Pointer into buffer, End of buffer */
|
|
|
|
int len; /* Length of node */
|
|
|
|
mxml_node_t *current; /* Current node */
|
2009-10-01 01:10:58 +02:00
|
|
|
ptr = buffer;
|
|
|
|
end = buffer + buflen - 1;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (current = node->child; current && ptr < end; current = current->next)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (current->type == MXML_TEXT)
|
|
|
|
{
|
|
|
|
if (current->value.text.whitespace) *ptr++ = ' ';
|
|
|
|
len = (int) strlen(current->value.text.string);
|
|
|
|
if (len > (int) (end - ptr)) len = (int) (end - ptr);
|
|
|
|
memcpy(ptr, current->value.text.string, len);
|
2009-10-01 01:10:58 +02:00
|
|
|
ptr += len;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (current->type == MXML_OPAQUE)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
len = (int) strlen(current->value.opaque);
|
|
|
|
if (len > (int) (end - ptr)) len = (int) (end - ptr);
|
|
|
|
memcpy(ptr, current->value.opaque, len);
|
2009-10-01 01:10:58 +02:00
|
|
|
ptr += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ptr = '\0';
|
2010-09-24 02:48:03 +02:00
|
|
|
return (buffer);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
int GetRatingForGame(char *gameid)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
int retval = -1;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!xml_loaded || nodedata == NULL) return -1;
|
2009-12-10 21:27:36 +01:00
|
|
|
|
|
|
|
/* index all IDs */
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindex = mxmlIndexNew(nodedata, "id", NULL);
|
|
|
|
nodeid = mxmlIndexReset(nodeindex);
|
2009-12-10 21:27:36 +01:00
|
|
|
*element_text = 0;
|
|
|
|
/* search for game matching gameid */
|
2010-09-24 02:48:03 +02:00
|
|
|
while (1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeid = mxmlIndexFind(nodeindex, "id", NULL);
|
|
|
|
if (nodeid != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
get_nodetext(nodeid, element_text, sizeof(element_text));
|
|
|
|
if (!strcmp(element_text, gameid))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-12-10 21:27:36 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-10 21:27:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!strcmp(element_text, gameid))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
char type[5], value[5], dest[5];
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodeid, nodedata, "rating", "type", NULL, MXML_NO_DESCEND, type, sizeof(type));
|
|
|
|
GetTextFromNode(nodeid, nodedata, "rating", "value", NULL, MXML_NO_DESCEND, value, sizeof(value));
|
|
|
|
ConvertRating(value, type, "PEGI", dest, sizeof(dest));
|
2009-12-10 21:27:36 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
retval = atoi(dest);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
return retval;
|
2009-12-10 21:27:36 +01:00
|
|
|
}
|