From c97c8877755ba1c6ce03b61e16560f0d68f37a9f Mon Sep 17 00:00:00 2001 From: "lustar.mii" Date: Sun, 22 Nov 2009 16:42:53 +0000 Subject: [PATCH] For people who use two partitions (FAT32 and WBFS), wiitdb.zip won't be overwritten anymore when they update. The file is now loaded and saved as wiitdb_(partition).zip, so you can switch partitions and keep titles/infos. If wiitdb_(partition).zip is not found it loads wiitdb.zip. When exiting settings, the partition is now reloaded only when needed. WiiTDB update should work again for people who own more than 240 games. Fixed a rare crash that could be issue 1083. --- source/menu/menu_check.cpp | 7 +++++++ source/network/http.c | 4 ++-- source/prompts/PromptWindows.cpp | 13 +++++++------ source/prompts/gameinfo.cpp | 22 +++++++++++----------- source/settings/Settings.cpp | 32 +++++++++++++++++++++----------- source/settings/cfg.c | 10 ---------- source/xml/xml.c | 18 ++++++++++-------- svnrev.sh | 2 +- 8 files changed, 59 insertions(+), 49 deletions(-) diff --git a/source/menu/menu_check.cpp b/source/menu/menu_check.cpp index a5b6ac67..be187d9c 100644 --- a/source/menu/menu_check.cpp +++ b/source/menu/menu_check.cpp @@ -146,6 +146,13 @@ int MenuCheck() { USBDevice_Init(); SDCard_Init(); } + + // open database if needed, load titles if needed + OpenXMLDatabase(Settings.titlestxt_path,Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride==1?true:false, true); + + // titles.txt loaded after database to override database titles with custom titles + //snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path); + //cfg_parsefile(pathname, &title_set); return menu; } diff --git a/source/network/http.c b/source/network/http.c index 1c74c17b..ecfd5729 100644 --- a/source/network/http.c +++ b/source/network/http.c @@ -175,8 +175,8 @@ struct block downloadfile(const char *url) { //Form a nice request header to send to the webserver char* headerformat = "GET %s HTTP/1.0\r\nHost: %s\r\nReferer: %s\r\nUser-Agent: USBLoaderGX r%s\r\n\r\n";; - char header[strlen(headerformat) + strlen(domain) + strlen(path)+strlen(url)]; - sprintf(header, headerformat, path, domain, url, GetRev()); + char header[strlen(headerformat) + strlen(path) + strlen(domain) + strlen(domain)]; + sprintf(header, headerformat, path, domain, domain, GetRev()); //Do the request and get the response send_message(connection, header); diff --git a/source/prompts/PromptWindows.cpp b/source/prompts/PromptWindows.cpp index 18e5087e..b1d0950b 100644 --- a/source/prompts/PromptWindows.cpp +++ b/source/prompts/PromptWindows.cpp @@ -57,6 +57,7 @@ extern u8 shutdown; extern u8 reset; extern u8 mountMethod; extern struct discHdr *dvdheader; +extern char game_partition[6]; /*** Extern functions ***/ extern void ResumeGui(); @@ -2640,8 +2641,8 @@ int ProgressUpdateWindow() { char wiitdbpathtmp[200]; struct block file = downloadfile(XMLurl); if (file.data != NULL) { - snprintf(wiitdbpath, sizeof(wiitdbpath), "%swiitdb.zip", Settings.titlestxt_path); - snprintf(wiitdbpathtmp, sizeof(wiitdbpathtmp), "%swiitmp.zip", Settings.titlestxt_path); + snprintf(wiitdbpath, sizeof(wiitdbpath), "%swiitdb_%s.zip", Settings.titlestxt_path,game_partition); + snprintf(wiitdbpathtmp, sizeof(wiitdbpathtmp), "%swiitmp_%s.zip", Settings.titlestxt_path,game_partition); rename(wiitdbpath,wiitdbpathtmp); pfile = fopen(wiitdbpath, "wb"); fwrite(file.data,1,file.size,pfile); @@ -3020,8 +3021,8 @@ int ProgressUpdateWindow() { file = downloadfile(XMLurl); if (file.data != NULL) { subfoldercreate(Settings.titlestxt_path); - snprintf(wiitdbpath, sizeof(wiitdbpath), "%swiitdb.zip", Settings.titlestxt_path); - snprintf(wiitdbpathtmp, sizeof(wiitdbpathtmp), "%swiitmp.zip", Settings.titlestxt_path); + snprintf(wiitdbpath, sizeof(wiitdbpath), "%swiitdb_%s.zip", Settings.titlestxt_path,game_partition); + snprintf(wiitdbpathtmp, sizeof(wiitdbpathtmp), "%swiitmp_%s.zip", Settings.titlestxt_path,game_partition); rename(wiitdbpath,wiitdbpathtmp); pfile = fopen(wiitdbpath, "wb"); fwrite(file.data,1,file.size,pfile); @@ -3058,8 +3059,8 @@ int ProgressUpdateWindow() { struct block file = downloadfile(XMLurl); if (file.data != NULL) { subfoldercreate(Settings.titlestxt_path); - snprintf(wiitdbpath, sizeof(wiitdbpath), "%swiitdb.zip", Settings.titlestxt_path); - snprintf(wiitdbpathtmp, sizeof(wiitdbpathtmp), "%swiitmp.zip", Settings.titlestxt_path); + snprintf(wiitdbpath, sizeof(wiitdbpath), "%swiitdb_%s.zip", Settings.titlestxt_path,game_partition); + snprintf(wiitdbpathtmp, sizeof(wiitdbpathtmp), "%swiitmp_%s.zip", Settings.titlestxt_path,game_partition); rename(wiitdbpath,wiitdbpathtmp); FILE *pfile = fopen(wiitdbpath, "wb"); fwrite(file.data,1,file.size,pfile); diff --git a/source/prompts/gameinfo.cpp b/source/prompts/gameinfo.cpp index a03c7615..6a354565 100644 --- a/source/prompts/gameinfo.cpp +++ b/source/prompts/gameinfo.cpp @@ -42,13 +42,11 @@ int showGameInfo(char *ID) { HaltGui();//put this first to try to get rid of the code dump caused by loading this window at the same time as loading images from the SD card mainWindow->SetState(STATE_DISABLED); ResumeGui(); - //load the xml shit + bool databaseopened = true; - //OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, false, true); // open file, do not load titles, keep in memory if (databaseopened) { LoadGameInfoFromXML(ID, Settings.db_language); - //CloseXMLDatabase(); bool showmeminfo = false; @@ -711,17 +709,19 @@ int showGameInfo(char *ID) { wifiY-=20; gameinfoWindow.Append(wifiTxt[i]); } - if (strcmp(gameinfo.wififeatures[1],"") != 0) { + if (strcmp(gameinfo.wififeatures[1],"") !=0) { snprintf(linebuf, sizeof(linebuf), "%s:",tr("WiFi Features")); - wifiTxt[0] = new GuiText(linebuf, 16, (GXColor) {0,0,0, 255}); - wifiTxt[0]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - wifiTxt[0]->SetPosition(205,200+wifiY); - gameinfoWindow.Append(wifiTxt[0]); - } + } else { + strcpy(linebuf,""); + } + wifiTxt[0] = new GuiText(linebuf, 16, (GXColor) {0,0,0, 255}); + wifiTxt[0]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); + wifiTxt[0]->SetPosition(205,200+wifiY); + gameinfoWindow.Append(wifiTxt[0]); //synopsis int pagesize=12; - if (strcmp(gameinfo.synopsis,"") != 0) { + if (strcmp(gameinfo.synopsis,"") !=0) { snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis); synopsisTxt = new GuiText(linebuf, 16, (GXColor) {0,0,0, 255}); synopsisTxt->SetMaxWidth(350,GuiText::WRAP); @@ -1112,7 +1112,7 @@ void MemInfoPrompt() void build_XML_URL(char *XMLurl, int XMLurlsize) { __Menu_GetEntries(1); - // NET_BUFFER_SIZE in http.c needs to be set to size of XMLurl + 40 + // NET_BUFFER_SIZE in http.c needs to be set to size of XMLurl + headerformat char url[3540]; char filename[10]; snprintf(url,sizeof(url),"http://wiitdb.com/wiitdb.zip?LANG=%s&ID=", Settings.db_language); diff --git a/source/settings/Settings.cpp b/source/settings/Settings.cpp index 514d3084..75b118f7 100644 --- a/source/settings/Settings.cpp +++ b/source/settings/Settings.cpp @@ -19,13 +19,13 @@ #include "cfg.h" #include "usbloader/partition_usbloader.h" #include "usbloader/utils.h" +#include "xml/xml.h" #define MAXOPTIONS 13 /*** Extern functions ***/ extern void ResumeGui(); extern void HaltGui(); -extern bool Database(char* xmlfilepath, char* argdblang, bool argJPtoEN, bool openfile, bool loadtitles, bool keepopen); extern void titles_default(); /*** Extern variables ***/ @@ -73,6 +73,9 @@ int MenuSettings() strcpy(opt_lang,Settings.language_path); // backup title override setting int opt_override = Settings.titlesOverride; + // backup partition index + u8 settingspartitionold = Settings.partition; + enum { @@ -2052,23 +2055,30 @@ int MenuSettings() w.SetEffect(EFFECT_FADE, -20); while (w.GetEffect()>0) usleep(50); - + // if partition has changed, Reinitialize it + PartInfo pinfo = partitions.pinfo[Settings.partition]; + load_from_fat = pinfo.fs_type == FS_TYPE_FAT32; + if (Settings.partition != settingspartitionold) { + WBFS_Close(); + WBFS_OpenPart(load_from_fat, Settings.partition, partitions.pentry[Settings.partition].sector, partitions.pentry[Settings.partition].size, (char *) &game_partition); + } + // if language has changed, reload titles char opt_langnew[100]; strcpy(opt_langnew,Settings.language_path); int opt_overridenew = Settings.titlesOverride; - if (strcmp(opt_lang,opt_langnew) || (opt_override != opt_overridenew && Settings.titlesOverride==1)) - OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, false, Settings.titlesOverride==1?true:false, true); // open file, reload titles, keep in memory - // disable titles from database + bool reloaddatabasefile = false; + if (strcmp(opt_lang,opt_langnew) || (opt_override != opt_overridenew && Settings.titlesOverride==1) || (Settings.partition != settingspartitionold)) { + if (Settings.partition != settingspartitionold) { + reloaddatabasefile = true; + CloseXMLDatabase(); + } + OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, reloaddatabasefile, Settings.titlesOverride==1?true:false, true); // open file, reload titles, keep in memory + } + // disable titles from database if setting has changed if (opt_override != opt_overridenew && Settings.titlesOverride==0) titles_default(); - // Reinitialize WBFS partition, it might have changed - PartInfo pinfo = partitions.pinfo[Settings.partition]; - load_from_fat = pinfo.fs_type == FS_TYPE_FAT32; - WBFS_Close(); - WBFS_OpenPart(load_from_fat, Settings.partition, partitions.pentry[Settings.partition].sector, partitions.pentry[Settings.partition].size, (char *) &game_partition); - HaltGui(); mainWindow->RemoveAll(); diff --git a/source/settings/cfg.c b/source/settings/cfg.c index f0fbd911..0ac5c8d0 100644 --- a/source/settings/cfg.c +++ b/source/settings/cfg.c @@ -5,7 +5,6 @@ #include #include #include -#include #include "language/gettext.h" #include "listfiles.h" @@ -1771,15 +1770,6 @@ void CFG_Load(void) { if (CONF_GetArea() == CONF_AREA_AUS) strcpy(Settings.db_language,"AU"); - // open database if needed, load titles if needed - OpenXMLDatabase(Settings.titlestxt_path,Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride==1?true:false, true); - - // titles.txt loaded after database to override database titles with custom titles - //took out this titles.txt shit because it is useless now. teh xml has all the titles in it - //snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path); - //cfg_parsefile(pathname, &title_set); - -// cfg_parsearg(argc, argv); // if GUI language is set to default Settings.language_path needs to remain "notset" (if the detected setting was kept detection wouldn't work next time) if (langisdefault) sprintf(Settings.language_path, "notset"); diff --git a/source/xml/xml.c b/source/xml/xml.c index e2c0bd11..471f631e 100644 --- a/source/xml/xml.c +++ b/source/xml/xml.c @@ -11,18 +11,18 @@ Load game information from XML - Lustar //#include "cfg.h" //#include "xml.h" +extern struct SSettings Settings; // for loader GX +extern void title_set(char *id, char *title); +extern char* trimcopy(char *dest, char *src, int size); +extern char game_partition[6]; + /* config */ static bool xmldebug = false; -static char xmlcfg_filename[100] = "wiitdb.zip"; +static char xmlcfg_filename[100] = "wiitdb"; static int xmlmaxsize = 1572864; -extern struct SSettings Settings; // for loader GX - -extern void title_set(char *id, char *title); -extern char* trimcopy(char *dest, char *src, int size); - struct gameXMLinfo gameinfo; struct gameXMLinfo gameinfo_reset; @@ -72,9 +72,11 @@ bool OpenXMLDatabase(char* xmlfilepath, char* argdblang, bool argJPtoEN, bool op char pathname[200]; snprintf(pathname, sizeof(pathname), "%s", xmlfilepath); if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/",pathname); - snprintf(pathname, sizeof(pathname), "%s%s", pathname, xmlcfg_filename); + snprintf(pathname, sizeof(pathname), "%s%s_%s.zip", pathname, xmlcfg_filename, game_partition); if (openfile) opensuccess = OpenXMLFile(pathname); if (!opensuccess) { + 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); } @@ -387,7 +389,7 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt) char langcode[100] = ""; if (!strcmp(langtxt,"")) langtxt = GetLangSettingFromGame(gameid); - strcpy(langcode,ConvertLangTextToCode(langtxt)); + strlcpy(langcode,ConvertLangTextToCode(langtxt),sizeof(langcode)); /* reset all game info */ gameinfo = gameinfo_reset; diff --git a/svnrev.sh b/svnrev.sh index c798528e..96b7eec8 100644 --- a/svnrev.sh +++ b/svnrev.sh @@ -36,7 +36,7 @@ EOF echo >&2 rev_new=`expr $rev_new + 1` - rev_date=`date +%Y%m%d%k%M` + rev_date=`date +%Y%m%d%H%M -u` cat < ./HBC/META.XML