Several small fixes + enabled displaying titles from database in main list and game info screen. The titles now change to the language that is set in the Game Info settings and individual game settings will override it. All titles default to English if the preferred language is not available for a game.

This commit is contained in:
lustar.mii 2009-06-14 03:42:46 +00:00
parent bc8084fe75
commit 1efc9d1f89
8 changed files with 123 additions and 100 deletions

View File

@ -1264,6 +1264,7 @@ static int MenuDiscList()
mainWindow->Remove(&w);
ResumeGui();
int settret = GameSettings(header);
menu = MENU_DISCLIST; // refresh titles (needed if the language setting has changed)
HaltGui();
if (Settings.gameDisplay==list) mainWindow->Append(gameBrowser);
else if (Settings.gameDisplay==grid) mainWindow->Append(gameGrid);

View File

@ -36,17 +36,16 @@ int
showGameInfo(char *ID, u8 *headerID)
{
u8 nodata=1;
//load the xml shit
//load the xml shit
char pathname[100];
snprintf(pathname, sizeof(pathname), "%s%s", Settings.titlestxt_path, "wiitdb.zip");
// database should always be zipped, while it may be convenient detecting and loading from .xml may lead to confusion:
bool fileexists = OpenXMLFile(pathname);
if(!fileexists) {
snprintf(pathname, sizeof(pathname), "%s%s", Settings.titlestxt_path, "wiitdb.xml");
fileexists = OpenXMLFile(pathname);
}
if(fileexists) {
snprintf(pathname, sizeof(pathname), "English");
if (Settings.titlesOverride==1)LoadTitlesFromXML(pathname, false); // options can be added to set force title language to any language and force Japanese title to English
int choice = -1;
//int i = 0;
@ -116,7 +115,7 @@ showGameInfo(char *ID, u8 *headerID)
GuiText * genreTxt = NULL;
GuiText * betaTxt = NULL;
GuiText * beta1Txt = NULL;
// GuiText ** wifiTxt = NULL;
GuiText ** wifiTxt = NULL;
GuiWindow gameinfoWindow(600,308);
gameinfoWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
@ -160,8 +159,8 @@ showGameInfo(char *ID, u8 *headerID)
nextBtn.SetPosition(20,20);
nextBtn.SetTrigger(&trigA);
gameinfoWindow.Append(&nextBtn);
/*struct Game_CFG *game_cfg = NULL;
struct Game_CFG *game_cfg = NULL;
int opt_lang;
char langtexttmp[11][22] =
{{"Console Default"},
@ -175,14 +174,13 @@ showGameInfo(char *ID, u8 *headerID)
{"S. Chinese"},
{"T. Chinese"},
{"Korean"}};
game_cfg = CFG_get_game_opt(headerID);
game_cfg = CFG_get_game_opt((u8*)ID);
if (game_cfg) {
opt_lang = game_cfg->language;
} else {
opt_lang = Settings.language;
}*/
if (LoadGameInfoFromXML(ID,pathname))nodata=0;
//LoadGameInfoFromXML(ID,langtexttmp[opt_lang]);
}
if (LoadGameInfoFromXML(ID,langtexttmp[opt_lang]))nodata=0;
char linebuf[1000] = "";
char linebuf2[100] = "";
@ -504,8 +502,6 @@ showGameInfo(char *ID, u8 *headerID)
titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt->SetPosition(txtXOffset,12+y); y+=24;
gameinfoWindow.Append(titleTxt);}
//date
snprintf(linebuf2, sizeof(linebuf2), " ");
if (strcmp(gameinfo.day,"") != 0)
@ -593,21 +589,22 @@ showGameInfo(char *ID, u8 *headerID)
beta1Txt->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); beta1Txt->SetPosition(-17,-10);
gameinfoWindow.Append(beta1Txt);
// WiFi Shit commented out cause it has a code dump in it still
// wifiTxt = new GuiText * [gameinfo.wifiCnt];
// int wifiY=0;
/*for (int i=gameinfo.wifiCnt;strcmp(gameinfo.wififeatures[i],"") != 0;i--)
{
snprintf(linebuf, sizeof(linebuf), "%s",gameinfo.wififeatures[i]);
wifiTxt[i] = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
wifiTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); wifiTxt[i]->SetPosition(215,200+wifiY); wifiY-=(20 * newline);
gameinfoWindow.Append(wifiTxt[i]);}*/
wifiTxt = new GuiText * [gameinfo.wifiCnt + 1];
int wifiY=0;
for (int i=1;i<=gameinfo.wifiCnt;i++)
{
snprintf(linebuf, sizeof(linebuf), "%s",gameinfo.wififeatures[i]);
wifiTxt[i] = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
wifiTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); wifiTxt[i]->SetPosition(215,200+wifiY); wifiY-=(20 * newline);
gameinfoWindow.Append(wifiTxt[i]);
}
/*if (strcmp(gameinfo.wififeatures[1],"") != 0){
if (strcmp(gameinfo.wififeatures[1],"") != 0){
snprintf(linebuf, sizeof(linebuf), "%s:",LANGUAGE.wififeatures);
wifiTxt[0] = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
wifiTxt[0]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); wifiTxt[0]->SetPosition(205,200+wifiY); //wifiY+=(20 * newline);
gameinfoWindow.Append(wifiTxt[0]);}*/
gameinfoWindow.Append(wifiTxt[0]);
}
//synopsis
if (strcmp(gameinfo.synopsis,"") != 0)
{snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis);
@ -758,19 +755,13 @@ showGameInfo(char *ID, u8 *headerID)
delete genreTxt;
delete betaTxt;
delete beta1Txt;
/*if (gameinfo.wifiCnt>0){
for(int i=0; i<gameinfo.wifiCnt; i++)
if (gameinfo.wifiCnt>0){
for(int i=1; i<=gameinfo.wifiCnt; i++)
{
delete wifiTxt[i];
}
}*/
}
if (nodata==0)FreeXMLMemory();
//void FreeXMLDeletePart();
/*
nodeid
<dimok> nodefound
*/
ResumeGui();}
else {
gameinfoWindow2.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 50);
@ -779,7 +770,7 @@ showGameInfo(char *ID, u8 *headerID)
mainWindow->Remove(&gameinfoWindow2);
mainWindow->SetState(STATE_DEFAULT);
ResumeGui();}
//FreeXMLMemory();
FreeXMLMemory();
return choice;
/* File not found */

View File

@ -37,6 +37,10 @@ int MenuSettings()
int ret;
int choice = 0;
bool exit = false;
// backup game language setting
int opt_lang = 0;
opt_lang = Settings.language;
enum {
FADE,
@ -1628,9 +1632,20 @@ int MenuSettings()
w.SetEffect(EFFECT_FADE, -20);
while(w.GetEffect()>0) usleep(50);
// if language has changed, reload titles
int opt_langnew = 0;
opt_langnew = Settings.language;
if (Settings.titlesOverride==1 && opt_lang != opt_langnew) {
CFG_LoadXml(true, true, false); // open file, reload titles, do not keep in memory
menu = MENU_DISCLIST;
}
HaltGui();
mainWindow->RemoveAll();
mainWindow->Append(bgImg);
ResumeGui();
return menu;
}
@ -1644,7 +1659,7 @@ int GameSettings(struct discHdr * header)
bool exit = false;
int ret;
int retVal = 0;
char gameName[31];
if (strlen(get_title(header)) < (27 + 3)) {
@ -1766,7 +1781,9 @@ int GameSettings(struct discHdr * header)
parentalcontrolChoice = 0;
fix002 = off;
}
int opt_lang = languageChoice; // backup language setting
ResumeGui();
while(!exit)
@ -1868,6 +1885,14 @@ int GameSettings(struct discHdr * header)
if(isInserted(bootDevice)) {
if (CFG_save_game_opt(header->id))
{
// if language has changed, reload titles
int opt_langnew = 0;
game_cfg = CFG_get_game_opt(header->id);
if (game_cfg) opt_langnew = game_cfg->language;
if (Settings.titlesOverride==1 && opt_lang != opt_langnew) {
CFG_LoadXml(true, true, false); // open file, reload titles, do not keep in memory
}
// titles are refreshed in menu.cpp as soon as this function returns
WindowPrompt(LANGUAGE.SuccessfullySaved, 0, LANGUAGE.ok, 0,0,0);
}
else

View File

@ -10,5 +10,4 @@
int MenuSettings();
int GameSettings(struct discHdr * header);
#endif

View File

@ -1564,15 +1564,17 @@ bool CFG_forget_game_opt(u8 *id)
return cfg_save_games();
}
void CFG_LoadXml()
void CFG_LoadXml(bool openfile, bool loadtitles, bool freemem)
{
char pathname[200];
/* load renamed titles from proper names and game info XML, needs to be after cfg_load_games - Lustar */
snprintf(pathname, sizeof(pathname), "%s%s", Settings.titlestxt_path, "wiitdb.xml");
OpenXMLFile(pathname);
LoadTitlesFromXML("English", false); // options can be added to set force title language to any language and force Japanese title to English
}
char pathname[200];
snprintf(pathname, sizeof(pathname), "%s%s", Settings.titlestxt_path, "wiitdb.zip");
if (openfile) OpenXMLFile(pathname);
char forcedlanguage[100] = "";
if (loadtitles) LoadTitlesFromXML(forcedlanguage, true); // options can be added to set force title language to any language and force Japanese title to English
// true = force english for al Japanese tiles, this should be set to true as long as Japanese titles are not displayed properly
if (freemem) FreeXMLMemory(); // free memory as soon as titles are loaded, the file will need to be loaded again if needed
}
void CFG_Load(void)
{
@ -1595,9 +1597,6 @@ void CFG_Load(void)
snprintf(pathname, sizeof(pathname), Settings.language_path);
cfg_parsefile(pathname, &language_set);
snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path);
cfg_parsefile(pathname, &title_set);
snprintf(pathname, sizeof(pathname), "%s/config/GXGameSettings.cfg", bootDevice);
cfg_parsefile(pathname, &parental_set);
@ -1605,11 +1604,15 @@ void CFG_Load(void)
cfg_load_games();
cfg_load_game_num();
if (Settings.titlesOverride==1)CFG_LoadXml();
Global_Default(); //global default depends on theme information
CFG_LoadGlobal();
if (Settings.titlesOverride==1) CFG_LoadXml(true, true, false); // load titles, do not keep in memory
// loaded after database to override database titles with custom titles
snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path);
cfg_parsefile(pathname, &title_set);
// cfg_parsearg(argc, argv);
}

View File

@ -90,8 +90,8 @@ struct THEME
short favorite_x;
short favorite_y;
short abc_x;
short abc_y;
short list_x;
short abc_y;
short list_x;
short list_y;
short grid_x;
short grid_y;
@ -157,7 +157,7 @@ extern u8 parentalcontrolChoice;
extern u8 fix002;
extern u8 xflip;
extern u8 qboot;
extern u8 sort;
extern u8 sort;
extern u8 fave;
extern u8 wsprompt;
extern u8 keyset;
@ -314,7 +314,7 @@ struct SSettings {
int wsprompt;
int keyset;
int unicodefix;
int sort;
int sort;
int fave;
int wiilight;
int gameDisplay;
@ -336,7 +336,7 @@ struct SSettings {
void CFG_LoadGlobal(void);
bool cfg_save_global(void);
void CFG_LoadXml();
void CFG_LoadXml(bool openfile, bool loadtitles, bool freemem);
//Astidof - End of modification
char *get_title(struct discHdr *header);

View File

@ -4,17 +4,19 @@ Load game information from XML - Lustar
- MiniZip adapted by Tantric
*/
#include <malloc.h>
#include <mxml.h>
#include "unzip/unzip.h"
#include "settings/cfg.h"
#include "xml/xml.h"
#include "unzip/unzip.h"
//#include "cfg.h"
//#include "xml.h"
bool xml_loaded = false;
static bool xmldebug = false;
extern struct SSettings Settings; // for loader GX
static char langlist[11][22] =
{{"Console Default"},
{"Japanese"},
@ -53,17 +55,6 @@ static mxml_index_t *nodeindextmp=NULL;
int xmlloadtime = 0;
void FreeXMLDeletePart()
{
/* free memory */
mxmlIndexDelete(nodeindex);
mxmlIndexDelete(nodeindextmp);
mxmlDelete(nodeid);
mxmlDelete(nodeidtmp);
mxmlDelete(nodefound);
mxmlDelete(nodedata);
mxmlDelete(nodetree);
}
/* get_text() taken as is from mini-mxml example mxmldoc.c */
@ -123,10 +114,7 @@ void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, char *noden
bool OpenXMLFile(char *filename)
{
mxml_node_t *nodetree;
// if (xmldebug)
// dbg_time1();
// if (xmldebug) dbg_time1();
char* strresult = strstr(filename,".zip");
if (strresult == NULL) {
@ -149,9 +137,13 @@ bool OpenXMLFile(char *filename)
unz_file_info zipfileinfo;
unzGetCurrentFileInfo(unzfile, &zipfileinfo, NULL, 0, NULL, 0, NULL, 0);
int zipfilebuffersize = zipfileinfo.uncompressed_size;
char * zipfilebuffer = (char *) calloc(1,zipfilebuffersize);
if (zipfilebuffer == NULL)
char * zipfilebuffer = malloc(zipfilebuffersize);
memset(zipfilebuffer, 0, zipfilebuffersize);
if (zipfilebuffer == NULL) {
unzCloseCurrentFile(unzfile);
unzClose(unzfile);
return false;
}
unzReadCurrentFile(unzfile, zipfilebuffer, zipfilebuffersize);
unzCloseCurrentFile(unzfile);
@ -175,6 +167,7 @@ bool OpenXMLFile(char *filename)
} else {
//if (xmldebug);
// xmlloadtime = dbg_time2(NULL);
xml_loaded = true;
return true;
}
}
@ -183,13 +176,15 @@ bool OpenXMLFile(char *filename)
void FreeXMLMemory()
{
/* free memory */
mxmlIndexDelete(nodeindex);
mxmlIndexDelete(nodeindextmp);
mxmlDelete(nodeid);
mxmlDelete(nodeidtmp);
mxmlDelete(nodefound);
mxmlDelete(nodedata);
mxmlDelete(nodetree);
if (xml_loaded) {
mxmlIndexDelete(nodeindex);
mxmlIndexDelete(nodeindextmp);
mxmlDelete(nodeidtmp);
mxmlDelete(nodefound);
mxmlDelete(nodedata);
mxmlDelete(nodetree);
xml_loaded = false;
}
}
@ -284,7 +279,6 @@ void LoadTitlesFromXML(char *langtxt, bool forcejptoen)
char id_text[10];
char title_text[500] = "";
char title_text_EN[500] = "";
/* search index of id elements, load all id/titles text */
while (nodeid != NULL)
{
@ -304,8 +298,8 @@ void LoadTitlesFromXML(char *langtxt, bool forcejptoen)
if (game_cfg) {
opt_lang = game_cfg->language;
} else {
// opt_lang = CFG.language; // for config loader
opt_lang = Settings.language; // for loader GX
//opt_lang = CFG.language; // for Configurable Loader
opt_lang = Settings.language; // for Loader GX
}
strcpy(langcode,ConvertLangTextToCode(langlist[opt_lang]));
}
@ -373,7 +367,7 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
/* langcode: "English","French","German" */
{
bool exist=false;
if (nodeindex == NULL)
if (nodeindex == NULL || nodedata == NULL)
return exist;
/* convert language text into ISO 639 two-letter language codes */
@ -428,13 +422,12 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
/* text from child elements */
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", "EN", MXML_NO_DESCEND);
if (nodefound != NULL) {
//if (Settings.titlesOverride==1)
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, gameinfo.title_EN);
GetTextFromNode(nodefound, nodedata, "synopsis", NULL, NULL, MXML_DESCEND, gameinfo.synopsis_EN);
}
nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", langcode, MXML_NO_DESCEND);
if (nodefound != NULL) {
//GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, gameinfo.title);
GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, gameinfo.title);
GetTextFromNode(nodefound, nodedata, "synopsis", NULL, NULL, MXML_DESCEND, gameinfo.synopsis);
}
// fall back to English title and synopsis if prefered language was not found
@ -480,7 +473,7 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
nodefound = mxmlFindElement(nodeid, nodedata, "rating", NULL, NULL, MXML_NO_DESCEND);
if (nodefound != NULL) {
int incr = 0;
gameinfo.descriptorCnt=0;
nodeindextmp = mxmlIndexNew(nodefound,"descriptor", NULL);
nodeidtmp = mxmlIndexReset(nodeindextmp);
@ -488,8 +481,8 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
{
nodeidtmp = mxmlIndexFind(nodeindextmp,"descriptor", NULL);
if (nodeidtmp != NULL) {
++incr;
GetTextFromNode(nodeidtmp, nodedata, "descriptor", NULL, NULL, MXML_DESCEND, gameinfo.ratingdescriptors[incr]);
++gameinfo.descriptorCnt;
GetTextFromNode(nodeidtmp, nodedata, "descriptor", NULL, NULL, MXML_DESCEND, gameinfo.ratingdescriptors[gameinfo.descriptorCnt]);
}
}
}
@ -497,8 +490,6 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
GetTextFromNode(nodeid, nodedata, "input", "players", NULL, MXML_NO_DESCEND, gameinfo.players);
nodefound = mxmlFindElement(nodeid, nodedata, "input", NULL, NULL, MXML_NO_DESCEND);
if (nodefound != NULL) {
//int incr = 0;
//int incrreq = 0;
gameinfo.accessoryCnt=0;
gameinfo.accessoryReqCnt=0;
@ -513,7 +504,6 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
++gameinfo.accessoryReqCnt;
strcpy(gameinfo.accessories_required[gameinfo.accessoryReqCnt],mxmlElementGetAttr(nodeidtmp, "type"));
} else {
//++incr;
++gameinfo.accessoryCnt;
strcpy(gameinfo.accessories[gameinfo.accessoryCnt],mxmlElementGetAttr(nodeidtmp, "type"));
}
@ -527,9 +517,11 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
ConvertRating(gameinfo.ratingvalue, gameinfo.ratingtype, "PEGI",gameinfo.ratingvaluePEGI);
//PrintGameInfo();
exist=true;
} else {exist=false;
exist=true;
} else {
/*game not found */
exist=false;
}return exist;
}
@ -590,9 +582,9 @@ void PrintGameInfo(bool showfullinfo)
char linebuf[1000] = "";
if (xmldebug) {
char xmltime[100];
sprintf(xmltime,"%d",xmlloadtime);
printf("xml load time: %s\n",xmltime);
//char xmltime[100];
//sprintf(xmltime,"%d",xmlloadtime);
//printf("xml load time: %s\n",xmltime);
/*
printf("xml forcelang: %s\n",CFG.db_lang);
printf("xml url: %s\n",CFG.db_url);
@ -601,8 +593,20 @@ void PrintGameInfo(bool showfullinfo)
sprintf(xmljptoen,"%d",CFG.db_JPtoEN);
printf("xml JPtoEN: %s\n",xmljptoen);
*/
// guidebug
struct mallinfo mymallinfo = mallinfo();
char memtotal[100];
char memused[100];
char memnotinuse[100];
char memcanbefreed[100];
sprintf(memtotal,"%d",mymallinfo.arena/1024);
sprintf(memused,"%d",mymallinfo.uordblks/1024);
sprintf(memnotinuse,"%d",mymallinfo.fordblks/1024);
sprintf(memcanbefreed,"%d",mymallinfo.keepcost/1024);
printf("allocated:%sKB used:%sKB notused:%sKB canbefreed:%s", memtotal, memused, memnotinuse, memcanbefreed);
}
//printf("%s: ",gameidfull);
//printf("%s\n",gameinfo.title);
if (strcmp(gameinfo.year,"") != 0)

View File

@ -41,6 +41,7 @@ struct gameXMLinfo
char iso_crc[10];
char iso_md5[50];
char iso_sha1[50];
int descriptorCnt;
int accessoryCnt;
int accessoryReqCnt;
int wifiCnt;
@ -58,7 +59,6 @@ char *ConvertLangTextToCode(char *langtext);
void ConvertRating(char *ratingvalue, char *fromrating, char *torating, char *destvalue);
void PrintGameInfo(bool showfullinfo);
void FreeXMLMemory();
void FreeXMLDeletePart();
void title_set(char *id, char *title);