From 500dc4020f8b17b65ee806297b730ece13887efd Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Fri, 3 Dec 2010 18:38:57 +0000 Subject: [PATCH] *Reworked the whole WiiTDB.xml parsing. This is now done with mxml due to a lack of memory the file is now streamed. Now the full wiitdb.xml file with all languages is always used. The update of WiiTDB is also changed. It is now only updated if the version of the wiitdb.xml file does not match the version of the online file. *WiiTDB now falls back to english if the locale language is not found for Titles/Synopsis *Some clean up and memory leak fixes in game info prompt and adjusted the info get to the new WiiTDB reading method. *Added a few new useful functions from WiiXplorer (DownloadToFileWithProgress, ShowError,...) *Disabled the console output after the GUI is started up. The info is only output to gecko in GUI mode now. --- HBC/META.XML | 4 +- gui.pnproj | 2 +- source/gecko.c | 43 + source/gecko.h | 1 + source/homebrewboot/HomebrewBrowser.cpp | 5 +- source/language/UpdateLanguage.cpp | 4 +- source/main.cpp | 3 + source/menu/MountGamePartition.cpp | 9 +- source/network/FileDownloader.cpp | 280 +++ source/network/FileDownloader.h | 32 + source/network/networkops.cpp | 81 +- source/network/networkops.h | 6 +- source/network/update.cpp | 78 + source/network/update.h | 69 +- source/prompts/PromptWindows.cpp | 155 +- source/prompts/gameinfo.cpp | 1916 ++++++++++----------- source/settings/GameTitles.cpp | 28 + source/settings/GameTitles.h | 2 + source/settings/menus/GUISettingsMenu.cpp | 8 +- source/settings/menus/GameLoadSM.cpp | 8 +- source/themes/Theme_Downloader.cpp | 3 +- source/utils/ShowError.cpp | 21 + source/utils/ShowError.h | 14 + source/xml/WiiTDB.cpp | 998 +++++++++++ source/xml/WiiTDB.hpp | 150 ++ 25 files changed, 2730 insertions(+), 1190 deletions(-) create mode 100644 source/network/FileDownloader.cpp create mode 100644 source/network/FileDownloader.h create mode 100644 source/utils/ShowError.cpp create mode 100644 source/utils/ShowError.h create mode 100644 source/xml/WiiTDB.cpp create mode 100644 source/xml/WiiTDB.hpp diff --git a/HBC/META.XML b/HBC/META.XML index 1b247c97..6c75fa50 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 1.0 r1006 - 201011300400 + 1.0 r1007 + 201012031819 Loads games from USB-devices USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. diff --git a/gui.pnproj b/gui.pnproj index 4cd0f061..931f250b 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/gecko.c b/source/gecko.c index 2310cd44..21bbf356 100644 --- a/source/gecko.c +++ b/source/gecko.c @@ -2,6 +2,7 @@ #include #include #include +#include /* init-globals */ static bool geckoinit = false; @@ -75,4 +76,46 @@ void hexdump(void *d, int len) } } +static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len) +{ + if(geckoinit && ptr) + { + u32 level; + level = IRQ_Disable(); + usb_sendbuffer(1, ptr, len); + IRQ_Restore(level); + } + + return len; +} + +static const devoptab_t gecko_out = { + "stdout", // device name + 0, // size of file structure + NULL, // device open + NULL, // device close + __out_write,// device write + NULL, // device read + NULL, // device seek + NULL, // device fstat + NULL, // device stat + NULL, // device link + NULL, // device unlink + NULL, // device chdir + NULL, // device rename + NULL, // device mkdir + 0, // dirStateSize + NULL, // device diropen_r + NULL, // device dirreset_r + NULL, // device dirnext_r + NULL, // device dirclose_r + NULL // device statvfs_r +}; + +void USBGeckoOutput() +{ + devoptab_list[STD_OUT] = &gecko_out; + devoptab_list[STD_ERR] = &gecko_out; +} + #endif /* NO_DEBUG */ diff --git a/source/gecko.h b/source/gecko.h index aa4d9793..029257cb 100644 --- a/source/gecko.h +++ b/source/gecko.h @@ -14,6 +14,7 @@ extern "C" void gprintf(const char *str, ...); bool InitGecko(); void hexdump(void *d, int len); + void USBGeckoOutput(); #else #define gprintf(...) #define InitGecko() false diff --git a/source/homebrewboot/HomebrewBrowser.cpp b/source/homebrewboot/HomebrewBrowser.cpp index 807d14a5..b6bc5846 100644 --- a/source/homebrewboot/HomebrewBrowser.cpp +++ b/source/homebrewboot/HomebrewBrowser.cpp @@ -37,6 +37,7 @@ extern u32 infilesize; extern u32 uncfilesize; extern char wiiloadVersion[2]; +extern int connection; HomebrewBrowser::HomebrewBrowser() : FlyingButtonsMenu(tr( "Homebrew Launcher" )) @@ -293,7 +294,7 @@ int HomebrewBrowser::ReceiveFile() len = infilesize - read; else len = NETWORKBLOCKSIZE; - int result = network_read(buffer+read, len); + int result = network_read(connection, buffer+read, len); if (result < 0) { @@ -310,7 +311,7 @@ int HomebrewBrowser::ReceiveFile() } char filename[101]; - network_read((u8*) &filename, 100); + network_read(connection, (u8*) &filename, 100); // Do we need to unzip this thing? if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) diff --git a/source/language/UpdateLanguage.cpp b/source/language/UpdateLanguage.cpp index 4a2c0e10..97fefb69 100644 --- a/source/language/UpdateLanguage.cpp +++ b/source/language/UpdateLanguage.cpp @@ -17,7 +17,7 @@ int updateLanguageFiles() { char languageFiles[50][MAXLANGUAGEFILES]; - + DirList Dir(Settings.languagefiles_path); //give up now if we didn't find any @@ -48,7 +48,7 @@ int updateLanguageFiles() char codeurl[200]; snprintf(codeurl, sizeof(codeurl), "http://usbloader-gui.googlecode.com/svn/trunk/Languages/%s", languageFiles[j]); - snprintf(savepath, sizeof(savepath), "%s%s", Settings.languagefiles_path, languageFiles[j]); + snprintf(savepath, sizeof(savepath), "%s/%s", Settings.languagefiles_path, languageFiles[j]); struct block file = downloadfile(codeurl); diff --git a/source/main.cpp b/source/main.cpp index 4adff58a..edbe0dd5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -118,6 +118,9 @@ int main(int argc, char *argv[]) return BootGame(argv[1]); } + //! Now we startup the GUI so no need for console prints. Output only to gecko. + USBGeckoOutput(); + //! Init the rest of the System Sys_Init(); SetupPads(); diff --git a/source/menu/MountGamePartition.cpp b/source/menu/MountGamePartition.cpp index 756bc2d4..4f222f6c 100644 --- a/source/menu/MountGamePartition.cpp +++ b/source/menu/MountGamePartition.cpp @@ -8,7 +8,9 @@ #include "wpad.h" #include "fatmounter.h" #include "usbloader/wbfs.h" -#include "xml/xml.h" +#include "usbloader/GameList.h" +#include "settings/GameTitles.h" +#include "xml/WiiTDB.hpp" extern int load_from_fs; extern char game_partition[6]; @@ -163,11 +165,8 @@ int MountGamePartition(bool ShowGUI) } gprintf("\tOpenXMLDatabase\n"); - // open database if needed, load titles if needed - if (CheckFile(Settings.titlestxt_path)) - OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride, true); - gprintf("MountGamePartition() return: %i\n", ret); + GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); return ret; } diff --git a/source/network/FileDownloader.cpp b/source/network/FileDownloader.cpp new file mode 100644 index 00000000..de7d52a6 --- /dev/null +++ b/source/network/FileDownloader.cpp @@ -0,0 +1,280 @@ +/*************************************************************************** + * 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. + * + * for WiiXplorer 2010 + ***************************************************************************/ +#include +#include +#include +#include "language/gettext.h" +#include "networkops.h" +#include "http.h" +#include "FileOperations/fileops.h" +#include "prompts/PromptWindows.h" +#include "prompts/ProgressWindow.h" +#include "utils/ShowError.h" + +/**************************************************************************** + * Download a file from a given url with a Progressbar + ****************************************************************************/ +int DownloadFileToMem(const char *url, u8 **inbuffer, u32 *size) +{ + if(strncasecmp(url, "http://", strlen("http://")) != 0) + { + ShowError(tr("Not a valid URL")); + return -1; + } + char *path = strchr(url + strlen("http://"), '/'); + + if(!path) + { + ShowError(tr("Not a valid URL path")); + return -2; + } + + int domainlength = path - url - strlen("http://"); + + if(domainlength == 0) + { + ShowError(tr("Not a valid domain")); + return -3; + } + + char domain[domainlength + 1]; + strncpy(domain, url + strlen("http://"), domainlength); + domain[domainlength] = '\0'; + + int connection = GetConnection(domain); + + if(connection < 0) + { + ShowError(tr("Could not connect to the server.")); + return -4; + } + + char header[1024]; + char * ptr = header; + ptr += sprintf(ptr, "GET %s HTTP/1.1\r\n", path); + ptr += sprintf(ptr, "Host: %s\r\n", domain); + ptr += sprintf(ptr, "Referer: %s\r\n", domain); + ptr += sprintf(ptr, "User-Agent: USB Loader GX\r\n"); + ptr += sprintf(ptr, "Pragma: no-cache\r\n"); + ptr += sprintf(ptr, "Cache-Control: no-cache\r\n"); + ptr += sprintf(ptr, "Connection: close\r\n\r\n"); + + char filename[255]; + memset(filename, 0, sizeof(filename)); + + u32 filesize = network_request(connection, header, (char *) &filename); + + if(!filesize) + { + net_close(connection); + ShowError(tr("Filesize is 0 Byte.")); + return -5; + } + + u32 blocksize = 10*1024; + + u8 * buffer = (u8 *) malloc(filesize); + if(!buffer) + { + net_close(connection); + ShowError(tr("Not enough memory.")); + return -6; + } + + u32 done = 0; + + while(done < filesize) + { + ShowProgress(tr("Downloading file..."), 0, filename, (f32) done, (f32) filesize, true, true); + + if(blocksize > filesize - done) + blocksize = filesize - done; + + + s32 read = network_read(connection, buffer+done, blocksize); + + if(read < 0) + { + free(buffer); + ProgressStop(); + net_close(connection); + ShowError(tr("Transfer failed")); + return -8; + } + else if(!read) + break; + + done += read; + } + + ProgressStop(); + net_close(connection); + + *inbuffer = buffer; + *size = filesize; + + return 1; +} + +/**************************************************************************** + * Download a file from a given url to a given path with a Progressbar + ****************************************************************************/ +int DownloadFileToPath(const char *orig_url, const char *dest, bool UseFilename) +{ + if(!orig_url || !dest) + { + ShowError(tr("No URL or Path specified.")); + return -2; + } + + bool addhttp = false; + + if(strncasecmp(orig_url, "http://", strlen("http://")) != 0) + { + addhttp = true; + } + + char url[strlen(orig_url) + (addhttp ? strlen("http://") : 0) + 1]; + + if(addhttp) + snprintf(url, sizeof(url), "http://%s", orig_url); + else + strcpy(url, orig_url); + + char *path = strchr(url + strlen("http://"), '/'); + + if(!path) + { + ShowError(tr("Not a valid URL path")); + return -2; + } + + int domainlength = path - url - strlen("http://"); + + if(domainlength == 0) + { + ShowError(tr("Not a valid domain")); + return -3; + } + + char domain[domainlength + 1]; + strncpy(domain, url + strlen("http://"), domainlength); + domain[domainlength] = '\0'; + + int connection = GetConnection(domain); + + if(connection < 0) + { + ShowError(tr("Could not connect to the server.")); + return -4; + } + + char header[1024]; + char * ptr = header; + ptr += sprintf(ptr, "GET %s HTTP/1.1\r\n", path); + ptr += sprintf(ptr, "Host: %s\r\n", domain); + ptr += sprintf(ptr, "Referer: %s\r\n", domain); + ptr += sprintf(ptr, "User-Agent: WiiXplorer\r\n"); + ptr += sprintf(ptr, "Pragma: no-cache\r\n"); + ptr += sprintf(ptr, "Cache-Control: no-cache\r\n"); + ptr += sprintf(ptr, "Connection: close\r\n\r\n"); + + char filename[255]; + memset(filename, 0, sizeof(filename)); + + u32 filesize = network_request(connection, header, (char *) &filename); + + if(!filesize) + { + net_close(connection); + ShowError(tr("Filesize is 0 Byte.")); + return -5; + } + + u32 blocksize = 10*1024; + + u8 *buffer = (u8 *) malloc(blocksize); + if(!buffer) + { + net_close(connection); + ShowError(tr("Not enough memory.")); + return -6; + } + + if(UseFilename) + { + if(dest[strlen(dest)-1] != '/') + strcat((char *) dest, "/"); + + CreateSubfolder(dest); + + strcat((char *) dest, filename); + } + + FILE *file = fopen(dest, "wb"); + if(!file) + { + net_close(connection); + free(buffer); + ShowError(tr("Cannot write to destination.")); + return -7; + } + + u32 done = 0; + + while(done < filesize) + { + ShowProgress(tr("Downloading file..."), 0, filename, (f32) done, (f32) filesize, true, true); + + if(blocksize > filesize - done) + blocksize = filesize - done; + + s32 read = network_read(connection, buffer, blocksize); + + if(read < 0) + { + free(buffer); + ProgressStop(); + net_close(connection); + fclose(file); + ShowError(tr("Transfer failed")); + return -8; + } + else if(!read) + break; + + fwrite(buffer, 1, read, file); + + done += read; + } + + free(buffer); + ProgressStop(); + net_close(connection); + fclose(file); + + return done; +} diff --git a/source/network/FileDownloader.h b/source/network/FileDownloader.h new file mode 100644 index 00000000..3fd2f24b --- /dev/null +++ b/source/network/FileDownloader.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * 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. + * + * for WiiXplorer 2010 + ***************************************************************************/ +#ifndef FILE_DOWNLOADER_H_ +#define FILE_DOWNLOADER_H_ + +int DownloadFileToMem(const char *url, u8 **inbuffer, u32 *size); +int DownloadFileToPath(const char *url, const char *dest, bool UseFilename = true); + +#endif diff --git a/source/network/networkops.cpp b/source/network/networkops.cpp index 23c9f991..aaffb6aa 100644 --- a/source/network/networkops.cpp +++ b/source/network/networkops.cpp @@ -14,10 +14,12 @@ #include "prompts/PromptWindows.h" #include "language/gettext.h" #include "settings/CSettings.h" +#include "networkops.h" #include "main.h" #include "http.h" #include "svnrev.h" #include "buildtype.h" +#include "gecko.h" #include "update.h" #define PORT 4299 @@ -110,7 +112,7 @@ bool ShutdownWC24() return onlinefix; } -s32 network_request(const char * request, char * filename) +s32 network_request(s32 connect, const char * request, char * filename) { char buf[1024]; char *ptr = NULL; @@ -119,7 +121,7 @@ s32 network_request(const char * request, char * filename) s32 ret; /* Send request */ - ret = net_send(connection, request, strlen(request), 0); + ret = net_send(connect, request, strlen(request), 0); if (ret < 0) return ret; /* Clear buffer */ @@ -127,7 +129,7 @@ s32 network_request(const char * request, char * filename) /* Read HTTP header */ for (cnt = 0; !strstr(buf, "\r\n\r\n"); cnt++) - if (net_recv(connection, buf + cnt, 1, 0) <= 0) return -1; + if (net_recv(connect, buf + cnt, 1, 0) <= 0) return -1; /* HTTP request OK? */ if (!strstr(buf, "HTTP/1.1 200 OK")) return -1; @@ -157,7 +159,7 @@ s32 network_request(const char * request, char * filename) return size; } -s32 network_read(u8 *buf, u32 len) +s32 network_read(s32 connect, u8 *buf, u32 len) { u32 read = 0; s32 ret = -1; @@ -166,7 +168,7 @@ s32 network_read(u8 *buf, u32 len) while (read < len) { /* Read network data */ - ret = net_read(connection, buf + read, len - read); + ret = net_read(connect, buf + read, len - read); if (ret < 0) return ret; /* Read finished */ @@ -221,11 +223,78 @@ s32 download_request(const char * url, char * filename) char header[strlen(path) + strlen(domain) + strlen(url) + 100]; sprintf(header, "GET %s HTTP/1.1\r\nHost: %s\r\nReferer: %s\r\nConnection: close\r\n\r\n", path, domain, url); - s32 filesize = network_request(header, filename); + s32 filesize = network_request(connection, header, filename); return filesize; } +/**************************************************************************** + * HTML HEAD request + ***************************************************************************/ +char * HEAD_Request(const char * url) +{ + if(strncmp(url, "http://", strlen("http://")) != 0) + { + gprintf("Not a valid URL"); + return NULL; + } + char *path = strchr(url + strlen("http://"), '/'); + + if(!path) + { + gprintf("Not a valid URL path"); + return NULL; + } + + int domainlength = path - url - strlen("http://"); + + if(domainlength == 0) + { + gprintf("Not a valid domain"); + return NULL; + } + + char domain[domainlength + 1]; + strncpy(domain, url + strlen("http://"), domainlength); + domain[domainlength] = '\0'; + + connection = GetConnection(domain); + if(connection < 0) + { + gprintf("Could not connect to the server."); + return NULL; + } + + char header[strlen(path)+strlen(domain)*2+150]; + sprintf(header, "HEAD %s HTTP/1.1\r\nHost: %s\r\nReferer: %s\r\nUser-Agent: USB Loader GX\r\nConnection: close\r\n\r\n", path, domain, domain); + + /* Send request */ + s32 ret = net_send(connection, header, strlen(header), 0); + if (ret < 0) + { + CloseConnection(); + return NULL; + } + + u32 cnt = 0; + char * buf = (char *) malloc(1024); + memset(buf, 0, 1024); + + for (cnt = 0; !strstr(buf, "\r\n\r\n") && cnt < 1024; cnt++) + { + if(net_recv(connection, buf + cnt, 1, 0) <= 0) + { + CloseConnection(); + free(buf); + return NULL; + } + } + + CloseConnection(); + + return buf; +} + void CloseConnection() { diff --git a/source/network/networkops.h b/source/network/networkops.h index 7d36e8a7..a3eea3de 100644 --- a/source/network/networkops.h +++ b/source/network/networkops.h @@ -14,12 +14,12 @@ bool IsNetworkInit(void); char * GetNetworkIP(void); char * GetIncommingIP(void); bool ShutdownWC24(); -s32 network_request(const char * request, char * filename); -s32 network_read(u8 *buf, u32 len); +s32 network_request(s32 connection, const char * request, char * filename); +s32 network_read(s32 connection, u8 *buf, u32 len); s32 download_request(const char * url, char * filename = NULL); void CloseConnection(); int CheckUpdate(); - +char * HEAD_Request(const char * url); void HaltNetworkThread(); void ResumeNetworkWait(); void ResumeNetworkThread(); diff --git a/source/network/update.cpp b/source/network/update.cpp index 9ddb23d3..35a4869b 100644 --- a/source/network/update.cpp +++ b/source/network/update.cpp @@ -29,10 +29,19 @@ #include #include #include +#include +#include "gecko.h" +#include "ZipFile.h" #include "http.h" #include "networkops.h" #include "HTML_Stream.h" +#include "FileDownloader.h" +#include "settings/CSettings.h" +#include "settings/GameTitles.h" +#include "xml/WiiTDB.hpp" + +static const char * WiiTDB_URL = "http://wiitdb.com/wiitdb.zip"; /**************************************************************************** * Checking if an Update is available @@ -76,3 +85,72 @@ int CheckForBetaUpdate() return revnumber; } + +static bool CheckNewWiiTDBVersion(const char *url) +{ + u64 Version = 0; + + char * HEAD_Responde = HEAD_Request(url); + if(!HEAD_Responde) + return false; + + char * version_ptr = strstr(HEAD_Responde, "X-WiiTDB-Timestamp: "); + if(version_ptr) + { + version_ptr += strlen("X-WiiTDB-Timestamp: "); + Version = strtoull(version_ptr, NULL, 10); + } + + free(HEAD_Responde); + + std::string Title; + std::string Filepath = Settings.titlestxt_path; + if(Settings.titlestxt_path[Filepath.size()-1] != '/') + Filepath += '/'; + Filepath += "wiitdb.xml"; + + WiiTDB XML_DB; + + if(!XML_DB.OpenFile((Filepath.c_str()))) + return true; //! If no file exists we need the file + + u64 ExistingVersion = XML_DB.GetWiiTDBVersion(); + + gprintf("Existing WiiTDB Version: %llu Online WiiTDB Version: %llu\n", ExistingVersion, Version); + + return (ExistingVersion != Version); +} + +int UpdateWiiTDB() +{ + if(CheckNewWiiTDBVersion(WiiTDB_URL) == false) + { + gprintf("Not updating WiiTDB: Version is the same\n"); + return -1; + } + + gprintf("Updating WiiTDB...\n"); + + string ZipPath = Settings.titlestxt_path; + if(Settings.titlestxt_path[ZipPath.size()-1] != '/') + ZipPath += '/'; + + ZipPath += "wiitdb.zip"; + + int filesize = DownloadFileToPath(WiiTDB_URL, ZipPath.c_str(), false); + + if(filesize <= 0) + return -1; + + ZipFile zFile(ZipPath.c_str()); + + bool result = zFile.ExtractAll(Settings.titlestxt_path); + + //! The zip file is not needed anymore so we can remove it + remove(ZipPath.c_str()); + + //! Reload all titles because the file changed now. + GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); + + return (result ? filesize : -1); +} diff --git a/source/network/update.h b/source/network/update.h index 68c67c01..482f4e79 100644 --- a/source/network/update.h +++ b/source/network/update.h @@ -1,34 +1,35 @@ -/*************************************************************************** - * Copyright (C) 2009 - * 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. - * - * update.h - * - * Update operations - * for Wii-Xplorer 2009 - ***************************************************************************/ -#ifndef _UPDATEOPS_H_ -#define _UPDATEOPS_H_ - -int CheckForBetaUpdate(); - -#endif +/*************************************************************************** + * Copyright (C) 2009 + * 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. + * + * update.h + * + * Update operations + * for Wii-Xplorer 2009 + ***************************************************************************/ +#ifndef _UPDATEOPS_H_ +#define _UPDATEOPS_H_ + +int CheckForBetaUpdate(); +int UpdateWiiTDB(); + +#endif diff --git a/source/prompts/PromptWindows.cpp b/source/prompts/PromptWindows.cpp index 104b0b2b..7c6e6b38 100644 --- a/source/prompts/PromptWindows.cpp +++ b/source/prompts/PromptWindows.cpp @@ -20,6 +20,7 @@ #include "settings/CGameStatistics.h" #include "settings/GameTitles.h" #include "network/networkops.h" +#include "network/update.h" #include "network/http.h" #include "prompts/PromptWindows.h" #include "prompts/gameinfo.h" @@ -58,6 +59,7 @@ extern u8 reset; extern u8 mountMethod; extern struct discHdr *dvdheader; extern char game_partition[6]; +extern int connection; /**************************************************************************** * OnScreenNumpad @@ -2663,60 +2665,6 @@ int ProgressDownloadWindow(int choice2) } } - /**Temporary redownloading 1st image because of a fucking corruption bug **/ -#if 0 // is no longer necessary, since libfat is fixed - char URLFile[100]; - struct block file = downloadfile( URLFile ); - if ( choice2 == 2 ) - { - while ( tries < serverCnt3d ) - { - sprintf( URLFile, "%s%s", server3d, missingFiles[0] ); - sprintf( imgPath, "%s%s", Settings.covers_path, missingFiles[0] ); - file = downloadfile( URLFile ); - if ( !( file.size == 36864 || file.size <= 1024 || file.size <= 1174 || file.size == 7386 || file.size == 4446 || file.data == NULL ) )break; - tries++; - } - - } - if ( choice2 == 3 ) - { - while ( tries < serverCntDisc ) - { - sprintf( URLFile, "%s%s", serverDisc, missingFiles[0] ); - sprintf( imgPath, "%s%s", Settings.disc_path, missingFiles[0] ); - file = downloadfile( URLFile ); - if ( !( file.size == 36864 || file.size <= 1024 || file.size <= 1174 || file.size == 7386 || file.size == 4446 || file.data == NULL ) )break; - tries++; - } - } - if ( choice2 == 1 ) - { - while ( tries < serverCnt2d ) - { - sprintf( URLFile, "%s%s", server2d, missingFiles[0] ); - sprintf( imgPath, "%s%s", Settings.covers2d_path, missingFiles[0] ); - file = downloadfile( URLFile ); - if ( !( file.size == 36864 || file.size <= 1024 || file.size <= 1174 || file.size == 7386 || file.size == 4446 || file.data == NULL ) )break; - tries++; - } - } - if ( file.size == 36864 || file.size <= 1024 || file.size == 7386 || file.size <= 1174 || file.size == 4446 || file.data == NULL ) - { - } - else - { - if ( file.data != NULL ) - { - // save png to sd card - FILE *pfile; - pfile = fopen( imgPath, "wb" ); - fwrite( file.data, 1, file.size, pfile ); - fclose ( pfile ); - free( file.data ); - } - } -#endif HaltGui(); mainWindow->Remove(&promptWindow); mainWindow->SetState(STATE_DEFAULT); @@ -2886,12 +2834,6 @@ int ProgressUpdateWindow() } } - //make the URL to get XML based on our games - //std::string allocates the memory and does not depend on stack - std::string XMLurl; - XMLurl.resize(4096); - build_XML_URL(&XMLurl[0], XMLurl.size()); - char dolpath[150]; // char dolpathsuccess[150];//use coverspath as a folder for the update wad so we dont make a new folder and have to delete it snprintf( dolpath, sizeof( dolpath ), "%sULNR.wad", Settings.covers_path ); @@ -2937,33 +2879,7 @@ int ProgressUpdateWindow() titleTxt.SetTextf( "%s USB Loader GX", tr( "Updating" ) ); msgTxt.SetPosition( 0, 100 ); msgTxt.SetTextf( "%s", tr( "Updating WiiTDB.zip" ) ); - - char wiitdbpath[200]; - char wiitdbpathtmp[200]; - struct block file = downloadfile( XMLurl.c_str() ); - if ( file.data != NULL ) - { - 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 ); - fclose( pfile ); - free( file.data ); - CloseXMLDatabase(); - if ( OpenXMLDatabase( Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride == 1 ? true : false, true ) ) // open file, reload titles, keep in memory - - { - remove( wiitdbpathtmp ); - } - else - { - remove( wiitdbpath ); - rename( wiitdbpathtmp, wiitdbpath ); - OpenXMLDatabase( Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride == 1 ? true : false, true ); // open file, reload titles, keep in memory - } - } - + UpdateWiiTDB(); msgTxt.SetTextf( "%s", tr( "Updating Language Files:" ) ); updateLanguageFiles(); promptWindow.Append( &progressbarEmptyImg ); @@ -3271,8 +3187,7 @@ int ProgressUpdateWindow() if (IsNetworkInit() && ret >= 0) { - updatemode = WindowPrompt(tr( "What do you want to update?" ), 0, "USB Loader GX", tr( "WiiTDB Files" ), - tr( "Language File" ), tr( "Cancel" )); + updatemode = WindowPrompt(tr( "What do you want to update?" ), 0, "USB Loader GX", tr( "WiiTDB Files" ), tr( "Language File" ), tr( "Cancel" )); mainWindow->SetState(STATE_DISABLED); promptWindow.SetState(STATE_DEFAULT); mainWindow->ChangeFocus(&promptWindow); @@ -3344,7 +3259,7 @@ int ProgressUpdateWindow() blksize = (u32) (filesize - i); if (blksize > BLOCKSIZE) blksize = BLOCKSIZE; - ret = network_read(blockbuffer, blksize); + ret = network_read(connection, blockbuffer, blksize); if (ret != (s32) blksize) { failed = -1; @@ -3390,36 +3305,7 @@ int ProgressUpdateWindow() free(file.data); } msgTxt.SetTextf("%s", tr( "Updating WiiTDB.zip" )); - char wiitdbpath[200]; - char wiitdbpathtmp[200]; - file = downloadfile(XMLurl.c_str()); - if (file.data != NULL) - { - CreateSubfolder(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); - fclose(pfile); - free(file.data); - CloseXMLDatabase(); - if (OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, - Settings.db_JPtoEN, true, Settings.titlesOverride == 1 ? true : false, true)) // open file, reload titles, keep in memory - { - remove(wiitdbpathtmp); - } - else - { - remove(wiitdbpath); - rename(wiitdbpathtmp, wiitdbpath); - OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, - Settings.db_JPtoEN, true, Settings.titlesOverride == 1 ? true : false, - true); // open file, reload titles, keep in memory - } - } + UpdateWiiTDB(); msgTxt.SetTextf("%s", tr( "Updating Language Files:" )); updateLanguageFiles(); } @@ -3445,33 +3331,10 @@ int ProgressUpdateWindow() else if (updatemode == 2) { msgTxt.SetTextf("%s", tr( "Updating WiiTDB.zip" )); - char wiitdbpath[200]; - char wiitdbpathtmp[200]; - struct block file = downloadfile(XMLurl.c_str()); - if (file.data != NULL) + if(UpdateWiiTDB() < 0) { - CreateSubfolder(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); - fclose(pfile); - free(file.data); - CloseXMLDatabase(); - if (OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, - Settings.titlesOverride == 1 ? true : false, true)) // open file, reload titles, keep in memory - { - remove(wiitdbpathtmp); - } - else - { - remove(wiitdbpath); - rename(wiitdbpathtmp, wiitdbpath); - OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, - Settings.titlesOverride == 1 ? true : false, true); // open file, reload titles, keep in memory - } + msgTxt.SetTextf("%s", tr( "WiiTDB is up to date." )); + sleep(3); } ret = 1; } diff --git a/source/prompts/gameinfo.cpp b/source/prompts/gameinfo.cpp index 06bcb3a3..3228914d 100644 --- a/source/prompts/gameinfo.cpp +++ b/source/prompts/gameinfo.cpp @@ -23,16 +23,7 @@ #include "gameinfo.h" #include "usbloader/GameList.h" #include "../gecko.h" - -/*** Extern variables ***/ -extern u8 shutdown; -extern u8 reset; -extern struct gameXMLinfo gameinfo; -extern struct gameXMLinfo gameinfo_reset; - -/*** Extern functions ***/ -extern void ResumeGui(); -extern void HaltGui(); +#include "xml/WiiTDB.hpp" /**************************************************************************** * gameinfo @@ -43,1024 +34,995 @@ int showGameInfo(char *ID) mainWindow->SetState(STATE_DISABLED); ResumeGui(); - bool databaseopened = true; - if (databaseopened) + char xmlpath[300]; + snprintf(xmlpath, sizeof(xmlpath), "%swiitdb.xml", Settings.titlestxt_path); + + WiiTDB XML_DB; + + if(!XML_DB.OpenFile(xmlpath)) + return -1; + + XML_DB.SetLanguageCode(Settings.db_language); + + GameXMLInfo GameInfo; + + if(!XML_DB.GetGameXMLInfo(ID, &GameInfo)) + return -1; + + XML_DB.CloseFile(); + + bool showmeminfo = false; + + int choice = -1; + int titley = 10; + int marginY = titley + 40; + int indexy = marginY; + int wifiY = 0; + int intputX = 200, inputY = -30, txtXOffset = 90; + u8 nunchuk = 0, classiccontroller = 0, balanceboard = 0, dancepad = 0, guitar = 0, gamecube = 0, wheel = 0, + motionplus = 0, drums = 0, microphone = 0, zapper = 0, nintendods = 0, + //vitalitysensor=0, + wiispeak = 0; + int newline = 1; + u8 page = 1; + + GuiImageData * playersImgData = NULL; + GuiImage * playersImg = NULL; + + GuiImageData * wifiplayersImgData = NULL; + GuiImage * wifiplayersImg = NULL; + GuiImage * ratingImg = NULL; + + GuiImage * classiccontrollerImg = NULL; + GuiImage * nunchukImg = NULL; + GuiImage * guitarImg = NULL; + GuiImage * drumsImg = NULL; + GuiImage * dancepadImg = NULL; + GuiImage * motionplusImg = NULL; + GuiImage * wheelImg = NULL; + GuiImage * balanceboardImg = NULL; + GuiImage * microphoneImg = NULL; + GuiImage * zapperImg = NULL; + GuiImage * nintendodsImg = NULL; + GuiImage * wiispeakImg = NULL; + //GuiImage * vitalitysensorImg = NULL; + GuiImage * gcImg = NULL; + GuiImage * dialogBoxImg1 = NULL; + GuiImage * dialogBoxImg2 = NULL; + GuiImage * dialogBoxImg3 = NULL; + GuiImage * dialogBoxImg4 = NULL; + GuiImage * dialogBoxImg11 = NULL; + GuiImage * dialogBoxImg22 = NULL; + GuiImage * dialogBoxImg33 = NULL; + GuiImage * dialogBoxImg44 = NULL; + GuiImage * coverImg = NULL; + GuiImage * coverImg2 = NULL; + + GuiImageData * classiccontrollerImgData = NULL; + GuiImageData * nunchukImgData = NULL; + GuiImageData * guitarImgData = NULL; + GuiImageData * drumsImgData = NULL; + GuiImageData * motionplusImgData = NULL; + GuiImageData * wheelImgData = NULL; + GuiImageData * balanceboardImgData = NULL; + GuiImageData * dancepadImgData = NULL; + GuiImageData * microphoneImgData = NULL; + GuiImageData * zapperImgData = NULL; + GuiImageData * nintendodsImgData = NULL; + GuiImageData * wiispeakImgData = NULL; + //GuiImageData * vitalitysensorImgData = NULL; + GuiImageData * gamecubeImgData = NULL; + GuiImageData * ratingImgData = NULL; + GuiImageData * cover = NULL; + + GuiText * releasedTxt = NULL; + GuiText * publisherTxt = NULL; + GuiText * developerTxt = NULL; + GuiText * titleTxt = NULL; + Text * synopsisTxt = NULL; + GuiText * genreTitleTxt = NULL; + GuiText ** genreTxt = NULL; + GuiText ** wifiTxt = NULL; + GuiText * wiitdb1Txt = NULL; + GuiText * wiitdb2Txt = NULL; + GuiText * wiitdb3Txt = NULL; + GuiText * memTxt = NULL; + + GuiWindow gameinfoWindow(600, 308); + gameinfoWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); + gameinfoWindow.SetPosition(0, -50); + + GuiWindow gameinfoWindow2(600, 308); + gameinfoWindow2.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); + gameinfoWindow2.SetPosition(0, -50); + + GuiWindow txtWindow(350, 270); + txtWindow.SetAlignment(ALIGN_CENTRE, ALIGN_RIGHT); + txtWindow.SetPosition(95, 55); + + GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); + GuiImageData dialogBox1(Resources::GetFile("gameinfo1.png"), Resources::GetFileSize("gameinfo1.png")); + GuiImageData dialogBox2(Resources::GetFile("gameinfo1a.png"), Resources::GetFileSize("gameinfo1a.png")); + GuiImageData dialogBox3(Resources::GetFile("gameinfo2.png"), Resources::GetFileSize("gameinfo2.png")); + GuiImageData dialogBox4(Resources::GetFile("gameinfo2a.png"), Resources::GetFileSize("gameinfo2a.png")); + + GuiTrigger trig1; + trig1.SetButtonOnlyTrigger(-1, WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_X, 0); + GuiTrigger trigA; + trigA.SetButtonOnlyTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); + GuiTrigger trigB; + trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); + GuiTrigger trigU; + trigU.SetButtonOnlyTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP); + GuiTrigger trigD; + trigD.SetButtonOnlyTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN); + GuiTrigger trigH; + trigH.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + + //buttons for changing between synopsis and other info + GuiButton backBtn(0, 0); + backBtn.SetPosition(-20, -20); + backBtn.SetTrigger(&trigB); + gameinfoWindow.Append(&backBtn); + + GuiButton nextBtn(0, 0); + nextBtn.SetPosition(20, 20); + nextBtn.SetTrigger(&trigA); + gameinfoWindow.Append(&nextBtn); + + //buttons for scrolling the synopsis + GuiButton upBtn(0, 0); + upBtn.SetPosition(0, 0); + upBtn.SetTrigger(&trigU); + + GuiButton dnBtn(0, 0); + dnBtn.SetPosition(0, 0); + dnBtn.SetTrigger(&trigD); + + GuiButton homeBtn(0, 0); + homeBtn.SetPosition(0, 0); + homeBtn.SetTrigger(&trigH); + + // button to save the url for the zip file for poor people without wifi + GuiButton urlBtn(0, 0); + urlBtn.SetPosition(0, 0); + urlBtn.SetTrigger(&trig1); + gameinfoWindow.Append(&urlBtn); + + char linebuf2[100] = ""; + + // enable icons for required accessories + for (u32 i = 0; i < GameInfo.AccessoirList.size(); ++i) { + if(!GameInfo.AccessoirList[i].Required) + continue; - LoadGameInfoFromXML(ID, Settings.db_language); + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "guitar") == 0) guitar = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "drums") == 0) drums = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "dancepad") == 0) dancepad = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "motionplus") == 0) motionplus = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wheel") == 0) wheel = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "microphone") == 0) microphone = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "zapper") == 0) zapper = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nintendods") == 0) nintendods = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1; + //if (strcmp(GameInfo.AccessoirList[i].Name.c_str(),"vitalitysensor")==0) + // vitalitysensor=1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "gamecube") == 0) gamecube = 1; + } - bool showmeminfo = false; + // switch icons + if (nunchuk) + nunchukImgData = Resources::GetImageData("nunchukR.png"); + else nunchukImgData = Resources::GetImageData("nunchuk.png"); - int choice = -1; - int titley = 10; - int marginY = titley + 40; - int indexy = marginY; - int wifiY = 0; - int intputX = 200, inputY = -30, txtXOffset = 90; - u8 nunchuk = 0, classiccontroller = 0, balanceboard = 0, dancepad = 0, guitar = 0, gamecube = 0, wheel = 0, - motionplus = 0, drums = 0, microphone = 0, zapper = 0, nintendods = 0, - //vitalitysensor=0, - wiispeak = 0; - int newline = 1; - u8 page = 1; + if (classiccontroller) + classiccontrollerImgData = Resources::GetImageData("classiccontrollerR.png"); + else classiccontrollerImgData = Resources::GetImageData("classiccontroller.png"); - GuiImageData * playersImgData = NULL; - GuiImage * playersImg = NULL; + if (guitar) + guitarImgData = Resources::GetImageData("guitarR.png"); + else guitarImgData = Resources::GetImageData("guitar.png"); - GuiImageData * wifiplayersImgData = NULL; - GuiImage * wifiplayersImg = NULL; - GuiImage * ratingImg = NULL; + if (gamecube) + gamecubeImgData = Resources::GetImageData("gcncontrollerR.png"); + else gamecubeImgData = Resources::GetImageData("gcncontroller.png"); - GuiImage * classiccontrollerImg = NULL; - GuiImage * nunchukImg = NULL; - GuiImage * guitarImg = NULL; - GuiImage * drumsImg = NULL; - GuiImage * dancepadImg = NULL; - GuiImage * motionplusImg = NULL; - GuiImage * wheelImg = NULL; - GuiImage * balanceboardImg = NULL; - GuiImage * microphoneImg = NULL; - GuiImage * zapperImg = NULL; - GuiImage * nintendodsImg = NULL; - GuiImage * wiispeakImg = NULL; - //GuiImage * vitalitysensorImg = NULL; - GuiImage * gcImg = NULL; - GuiImage * dialogBoxImg1 = NULL; - GuiImage * dialogBoxImg2 = NULL; - GuiImage * dialogBoxImg3 = NULL; - GuiImage * dialogBoxImg4 = NULL; - GuiImage * dialogBoxImg11 = NULL; - GuiImage * dialogBoxImg22 = NULL; - GuiImage * dialogBoxImg33 = NULL; - GuiImage * dialogBoxImg44 = NULL; - GuiImage * coverImg = NULL; - GuiImage * coverImg2 = NULL; + if (wheel) + wheelImgData = Resources::GetImageData("wheelR.png"); + else wheelImgData = Resources::GetImageData("wheel.png"); - GuiImageData * classiccontrollerImgData = NULL; - GuiImageData * nunchukImgData = NULL; - GuiImageData * guitarImgData = NULL; - GuiImageData * drumsImgData = NULL; - GuiImageData * motionplusImgData = NULL; - GuiImageData * wheelImgData = NULL; - GuiImageData * balanceboardImgData = NULL; - GuiImageData * dancepadImgData = NULL; - GuiImageData * microphoneImgData = NULL; - GuiImageData * zapperImgData = NULL; - GuiImageData * nintendodsImgData = NULL; - GuiImageData * wiispeakImgData = NULL; - //GuiImageData * vitalitysensorImgData = NULL; - GuiImageData * gamecubeImgData = NULL; - GuiImageData * ratingImgData = NULL; - GuiImageData * cover = NULL; + if (motionplus) + motionplusImgData = Resources::GetImageData("motionplusR.png"); + else motionplusImgData = Resources::GetImageData("motionplus.png"); - GuiText * releasedTxt = NULL; - GuiText * publisherTxt = NULL; - GuiText * developerTxt = NULL; - GuiText * titleTxt = NULL; - Text * synopsisTxt = NULL; - GuiText ** genreTxt = NULL; - GuiText ** wifiTxt = NULL; - GuiText * wiitdb1Txt = NULL; - GuiText * wiitdb2Txt = NULL; - GuiText * wiitdb3Txt = NULL; - GuiText * memTxt = NULL; + if (drums) + drumsImgData = Resources::GetImageData("drumsR.png"); + else drumsImgData = Resources::GetImageData("drums.png"); - GuiWindow gameinfoWindow(600, 308); - gameinfoWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - gameinfoWindow.SetPosition(0, -50); + if (microphone) + microphoneImgData = Resources::GetImageData("microphoneR.png"); + else microphoneImgData = Resources::GetImageData("microphone.png"); - GuiWindow gameinfoWindow2(600, 308); - gameinfoWindow2.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - gameinfoWindow2.SetPosition(0, -50); + if (zapper) + zapperImgData = Resources::GetImageData("zapperR.png"); + else zapperImgData = Resources::GetImageData("zapper.png"); - GuiWindow txtWindow(350, 270); - txtWindow.SetAlignment(ALIGN_CENTRE, ALIGN_RIGHT); - txtWindow.SetPosition(95, 55); + if (wiispeak) + wiispeakImgData = Resources::GetImageData("wiispeakR.png"); + else wiispeakImgData = Resources::GetImageData("wiispeak.png"); - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox1(Resources::GetFile("gameinfo1.png"), Resources::GetFileSize("gameinfo1.png")); - GuiImageData dialogBox2(Resources::GetFile("gameinfo1a.png"), Resources::GetFileSize("gameinfo1a.png")); - GuiImageData dialogBox3(Resources::GetFile("gameinfo2.png"), Resources::GetFileSize("gameinfo2.png")); - GuiImageData dialogBox4(Resources::GetFile("gameinfo2a.png"), Resources::GetFileSize("gameinfo2a.png")); + if (nintendods) + nintendodsImgData = Resources::GetImageData("nintendodsR.png"); + else nintendodsImgData = Resources::GetImageData("nintendods.png"); - GuiTrigger trig1; - trig1.SetButtonOnlyTrigger(-1, WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_X, 0); - GuiTrigger trigA; - trigA.SetButtonOnlyTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - GuiTrigger trigU; - trigU.SetButtonOnlyTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP); - GuiTrigger trigD; - trigD.SetButtonOnlyTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN); - GuiTrigger trigH; - trigH.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + if (balanceboard) + balanceboardImgData = Resources::GetImageData("balanceboardR.png"); + else balanceboardImgData = Resources::GetImageData("balanceboard.png"); - //buttons for changing between synopsis and other info - GuiButton backBtn(0, 0); - backBtn.SetPosition(-20, -20); - backBtn.SetTrigger(&trigB); - gameinfoWindow.Append(&backBtn); + if (dancepad) + dancepadImgData = Resources::GetImageData("dancepadR.png"); + else dancepadImgData = Resources::GetImageData("dancepad.png"); - GuiButton nextBtn(0, 0); - nextBtn.SetPosition(20, 20); - nextBtn.SetTrigger(&trigA); - gameinfoWindow.Append(&nextBtn); + // look for optional accessories + for (u32 i = 0; i < GameInfo.AccessoirList.size(); ++i) + { + if(GameInfo.AccessoirList[i].Required) + continue; - //buttons for scrolling the synopsis - GuiButton upBtn(0, 0); - upBtn.SetPosition(0, 0); - upBtn.SetTrigger(&trigU); + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "guitar") == 0) guitar = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "drums") == 0) drums = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "dancepad") == 0) dancepad = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "motionplus") == 0) motionplus = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wheel") == 0) wheel = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "microphone") == 0) microphone = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "zapper") == 0) zapper = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nintendods") == 0) nintendods = 1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1; + //if (strcmp(GameInfo.AccessoirList[i].Name.c_str(),"vitalitysensor")==0) + // vitalitysensor=1; + if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "gamecube") == 0) gamecube = 1; + } - GuiButton dnBtn(0, 0); - dnBtn.SetPosition(0, 0); - dnBtn.SetTrigger(&trigD); + dialogBoxImg1 = new GuiImage(&dialogBox1); + dialogBoxImg1->SetAlignment(0, 3); + dialogBoxImg1->SetPosition(-9, 0); - GuiButton homeBtn(0, 0); - homeBtn.SetPosition(0, 0); - homeBtn.SetTrigger(&trigH); + dialogBoxImg2 = new GuiImage(&dialogBox2); + dialogBoxImg2->SetAlignment(0, 3); + dialogBoxImg2->SetPosition(145, 0); - // button to save the url for the zip file for poor people without wifi - GuiButton urlBtn(0, 0); - urlBtn.SetPosition(0, 0); - urlBtn.SetTrigger(&trig1); - gameinfoWindow.Append(&urlBtn); + dialogBoxImg3 = new GuiImage(&dialogBox3); + dialogBoxImg3->SetAlignment(0, 3); + dialogBoxImg3->SetPosition(301, 0); - char linebuf[XML_SYNOPSISLEN] = ""; - char linebuf2[100] = ""; + dialogBoxImg4 = new GuiImage(&dialogBox4); + dialogBoxImg4->SetAlignment(0, 3); + dialogBoxImg4->SetPosition(457, 0); - // enable icons for required accessories - for (int i = 1; i <= XML_ELEMMAX; i++) - { - if (strcmp(gameinfo.accessoriesReq[i], "classiccontroller") == 0) classiccontroller = 1; - if (strcmp(gameinfo.accessoriesReq[i], "nunchuk") == 0) nunchuk = 1; - if (strcmp(gameinfo.accessoriesReq[i], "guitar") == 0) guitar = 1; - if (strcmp(gameinfo.accessoriesReq[i], "drums") == 0) drums = 1; - if (strcmp(gameinfo.accessoriesReq[i], "dancepad") == 0) dancepad = 1; - if (strcmp(gameinfo.accessoriesReq[i], "motionplus") == 0) motionplus = 1; - if (strcmp(gameinfo.accessoriesReq[i], "wheel") == 0) wheel = 1; - if (strcmp(gameinfo.accessoriesReq[i], "balanceboard") == 0) balanceboard = 1; - if (strcmp(gameinfo.accessoriesReq[i], "microphone") == 0) microphone = 1; - if (strcmp(gameinfo.accessoriesReq[i], "zapper") == 0) zapper = 1; - if (strcmp(gameinfo.accessoriesReq[i], "nintendods") == 0) nintendods = 1; - if (strcmp(gameinfo.accessoriesReq[i], "wiispeak") == 0) wiispeak = 1; - //if (strcmp(gameinfo.accessoriesReq[i],"vitalitysensor")==0) - // vitalitysensor=1; - if (strcmp(gameinfo.accessoriesReq[i], "gamecube") == 0) gamecube = 1; - } + gameinfoWindow.Append(dialogBoxImg1); + gameinfoWindow.Append(dialogBoxImg2); + gameinfoWindow.Append(dialogBoxImg3); + gameinfoWindow.Append(dialogBoxImg4); - // switch icons - if (nunchuk) - nunchukImgData = Resources::GetImageData("nunchukR.png"); - else nunchukImgData = Resources::GetImageData("nunchuk.png"); + char imgPath[150]; + snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.covers_path, ID); + cover = new GuiImageData(imgPath); //load full id image + if (!cover->GetImage()) + { + delete cover; + cover = Resources::GetImageData("nocover.png"); + } + delete coverImg; + coverImg = NULL; - if (classiccontroller) - classiccontrollerImgData = Resources::GetImageData("classiccontrollerR.png"); - else classiccontrollerImgData = Resources::GetImageData("classiccontroller.png"); + coverImg = new GuiImage(cover); + coverImg->SetWidescreen(Settings.widescreen); + coverImg->SetPosition(15, 30); + gameinfoWindow.Append(coverImg); - if (guitar) - guitarImgData = Resources::GetImageData("guitarR.png"); - else guitarImgData = Resources::GetImageData("guitar.png"); - - if (gamecube) - gamecubeImgData = Resources::GetImageData("gcncontrollerR.png"); - else gamecubeImgData = Resources::GetImageData("gcncontroller.png"); - - if (wheel) - wheelImgData = Resources::GetImageData("wheelR.png"); - else wheelImgData = Resources::GetImageData("wheel.png"); - - if (motionplus) - motionplusImgData = Resources::GetImageData("motionplusR.png"); - else motionplusImgData = Resources::GetImageData("motionplus.png"); - - if (drums) - drumsImgData = Resources::GetImageData("drumsR.png"); - else drumsImgData = Resources::GetImageData("drums.png"); - - if (microphone) - microphoneImgData = Resources::GetImageData("microphoneR.png"); - else microphoneImgData = Resources::GetImageData("microphone.png"); - - if (zapper) - zapperImgData = Resources::GetImageData("zapperR.png"); - else zapperImgData = Resources::GetImageData("zapper.png"); - - if (wiispeak) - wiispeakImgData = Resources::GetImageData("wiispeakR.png"); - else wiispeakImgData = Resources::GetImageData("wiispeak.png"); - - if (nintendods) - nintendodsImgData = Resources::GetImageData("nintendodsR.png"); - else nintendodsImgData = Resources::GetImageData("nintendods.png"); - - if (balanceboard) - balanceboardImgData = Resources::GetImageData("balanceboardR.png"); - else balanceboardImgData = Resources::GetImageData("balanceboard.png"); - - if (dancepad) - dancepadImgData = Resources::GetImageData("dancepadR.png"); - else dancepadImgData = Resources::GetImageData("dancepad.png"); - - // look for optional accessories - for (int i = 1; i <= XML_ELEMMAX; i++) - { - if (strcmp(gameinfo.accessories[i], "classiccontroller") == 0) classiccontroller = 1; - if (strcmp(gameinfo.accessories[i], "nunchuk") == 0) nunchuk = 1; - if (strcmp(gameinfo.accessories[i], "guitar") == 0) guitar = 1; - if (strcmp(gameinfo.accessories[i], "drums") == 0) drums = 1; - if (strcmp(gameinfo.accessories[i], "dancepad") == 0) dancepad = 1; - if (strcmp(gameinfo.accessories[i], "motionplus") == 0) motionplus = 1; - if (strcmp(gameinfo.accessories[i], "wheel") == 0) wheel = 1; - if (strcmp(gameinfo.accessories[i], "balanceboard") == 0) balanceboard = 1; - if (strcmp(gameinfo.accessories[i], "microphone") == 0) microphone = 1; - if (strcmp(gameinfo.accessories[i], "zapper") == 0) zapper = 1; - if (strcmp(gameinfo.accessories[i], "nintendods") == 0) nintendods = 1; - if (strcmp(gameinfo.accessories[i], "wiispeak") == 0) wiispeak = 1; - //if (strcmp(gameinfo.accessories[i],"vitalitysensor")==0) - // vitalitysensor=1; - if (strcmp(gameinfo.accessories[i], "gamecube") == 0) gamecube = 1; - } - - dialogBoxImg1 = new GuiImage(&dialogBox1); - dialogBoxImg1->SetAlignment(0, 3); - dialogBoxImg1->SetPosition(-9, 0); - - dialogBoxImg2 = new GuiImage(&dialogBox2); - dialogBoxImg2->SetAlignment(0, 3); - dialogBoxImg2->SetPosition(145, 0); - - dialogBoxImg3 = new GuiImage(&dialogBox3); - dialogBoxImg3->SetAlignment(0, 3); - dialogBoxImg3->SetPosition(301, 0); - - dialogBoxImg4 = new GuiImage(&dialogBox4); - dialogBoxImg4->SetAlignment(0, 3); - dialogBoxImg4->SetPosition(457, 0); - - gameinfoWindow.Append(dialogBoxImg1); - gameinfoWindow.Append(dialogBoxImg2); - gameinfoWindow.Append(dialogBoxImg3); - gameinfoWindow.Append(dialogBoxImg4); - - char imgPath[150]; - snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.covers_path, ID); - cover = new GuiImageData(imgPath); //load full id image - if (!cover->GetImage()) - { - delete cover; - cover = Resources::GetImageData("nocover.png"); - } - delete coverImg; - coverImg = NULL; - - coverImg = new GuiImage(cover); - coverImg->SetWidescreen(Settings.widescreen); - coverImg->SetPosition(15, 30); - gameinfoWindow.Append(coverImg); - - // # of players - if (strcmp(gameinfo.players, "") != 0) - { + // # of players + if (GameInfo.Players > 0) + { + if (GameInfo.Players == 1) playersImgData = Resources::GetImageData("wiimote1.png"); - if (atoi(gameinfo.players) > 1) - { - playersImgData = Resources::GetImageData("wiimote2.png"); - } - if (atoi(gameinfo.players) > 2) - { - playersImgData = Resources::GetImageData("wiimote4.png"); - } - playersImg = new GuiImage(playersImgData); - playersImg->SetWidescreen(Settings.widescreen); - playersImg->SetPosition(intputX, inputY); - playersImg->SetAlignment(0, 4); - gameinfoWindow.Append(playersImg); - intputX += (Settings.widescreen ? playersImg->GetWidth() * .8 : playersImg->GetWidth()) + 5; - } + else if (GameInfo.Players == 2) + playersImgData = Resources::GetImageData("wiimote2.png"); - //draw the input types for this game - if (motionplus == 1) - { - motionplusImg = new GuiImage(motionplusImgData); - motionplusImg->SetWidescreen(Settings.widescreen); - motionplusImg->SetPosition(intputX, inputY); - motionplusImg->SetAlignment(0, 4); - gameinfoWindow.Append(motionplusImg); - intputX += (Settings.widescreen ? motionplusImg->GetWidth() * .8 : motionplusImg->GetWidth()) + 5; - } - if (nunchuk == 1) - { - nunchukImg = new GuiImage(nunchukImgData); - nunchukImg->SetWidescreen(Settings.widescreen); - nunchukImg->SetPosition(intputX, inputY); - nunchukImg->SetAlignment(0, 4); - gameinfoWindow.Append(nunchukImg); - intputX += (Settings.widescreen ? nunchukImg->GetWidth() * .8 : nunchukImg->GetWidth()) + 5; - } - if (classiccontroller == 1) - { - classiccontrollerImg = new GuiImage(classiccontrollerImgData); - classiccontrollerImg->SetWidescreen(Settings.widescreen); - classiccontrollerImg->SetPosition(intputX, inputY); - classiccontrollerImg->SetAlignment(0, 4); - gameinfoWindow.Append(classiccontrollerImg); - intputX += (Settings.widescreen ? classiccontrollerImg->GetWidth() * .8 : classiccontrollerImg->GetWidth()) - + 5; - } - if (gamecube == 1) - { - gcImg = new GuiImage(gamecubeImgData); - gcImg->SetWidescreen(Settings.widescreen); - gcImg->SetPosition(intputX, inputY); - gcImg->SetAlignment(0, 4); - gameinfoWindow.Append(gcImg); - intputX += (Settings.widescreen ? gcImg->GetWidth() * .8 : gcImg->GetWidth()) + 5; - } - if (wheel == 1) - { - wheelImg = new GuiImage(wheelImgData); - wheelImg->SetWidescreen(Settings.widescreen); - wheelImg->SetPosition(intputX, inputY); - wheelImg->SetAlignment(0, 4); - gameinfoWindow.Append(wheelImg); - intputX += (Settings.widescreen ? wheelImg->GetWidth() * .8 : wheelImg->GetWidth()) + 5; - } - if (guitar == 1) - { - guitarImg = new GuiImage(guitarImgData); - guitarImg->SetWidescreen(Settings.widescreen); - guitarImg->SetPosition(intputX, inputY); - guitarImg->SetAlignment(0, 4); - gameinfoWindow.Append(guitarImg); - intputX += (Settings.widescreen ? guitarImg->GetWidth() * .8 : guitarImg->GetWidth()) + 5; - } - if (drums == 1) - { - drumsImg = new GuiImage(drumsImgData); - drumsImg->SetWidescreen(Settings.widescreen); - drumsImg->SetPosition(intputX, inputY); - drumsImg->SetAlignment(0, 4); - gameinfoWindow.Append(drumsImg); - intputX += (Settings.widescreen ? drumsImg->GetWidth() * .8 : drumsImg->GetWidth()) + 5; - } - if (microphone == 1) - { - microphoneImg = new GuiImage(microphoneImgData); - microphoneImg->SetWidescreen(Settings.widescreen); - microphoneImg->SetPosition(intputX, inputY); - microphoneImg->SetAlignment(0, 4); - gameinfoWindow.Append(microphoneImg); - intputX += (Settings.widescreen ? microphoneImg->GetWidth() * .8 : microphoneImg->GetWidth()) + 5; - } - if (zapper == 1) - { - zapperImg = new GuiImage(zapperImgData); - zapperImg->SetWidescreen(Settings.widescreen); - zapperImg->SetPosition(intputX, inputY); - zapperImg->SetAlignment(0, 4); - gameinfoWindow.Append(zapperImg); - intputX += (Settings.widescreen ? zapperImg->GetWidth() * .8 : zapperImg->GetWidth()) + 5; - } - if (wiispeak == 1) - { - wiispeakImg = new GuiImage(wiispeakImgData); - wiispeakImg->SetWidescreen(Settings.widescreen); - wiispeakImg->SetPosition(intputX, inputY); - wiispeakImg->SetAlignment(0, 4); - gameinfoWindow.Append(wiispeakImg); - intputX += (Settings.widescreen ? wiispeakImg->GetWidth() * .8 : wiispeakImg->GetWidth()) + 5; - } - if (nintendods == 1) - { - nintendodsImg = new GuiImage(nintendodsImgData); - nintendodsImg->SetWidescreen(Settings.widescreen); - nintendodsImg->SetPosition(intputX, inputY); - nintendodsImg->SetAlignment(0, 4); - gameinfoWindow.Append(nintendodsImg); - intputX += (Settings.widescreen ? nintendodsImg->GetWidth() * .8 : nintendodsImg->GetWidth()) + 5; - } - if (dancepad == 1) - { - dancepadImg = new GuiImage(dancepadImgData); - dancepadImg->SetWidescreen(Settings.widescreen); - dancepadImg->SetPosition(intputX, inputY); - dancepadImg->SetAlignment(0, 4); - gameinfoWindow.Append(dancepadImg); - intputX += (Settings.widescreen ? dancepadImg->GetWidth() * .8 : dancepadImg->GetWidth()) + 5; - } - if (balanceboard == 1) - { - balanceboardImg = new GuiImage(balanceboardImgData); - balanceboardImg->SetWidescreen(Settings.widescreen); - balanceboardImg->SetPosition(intputX, inputY); - balanceboardImg->SetAlignment(0, 4); - gameinfoWindow.Append(balanceboardImg); - intputX += (Settings.widescreen ? balanceboardImg->GetWidth() * .8 : balanceboardImg->GetWidth()) + 5; - } + else if (GameInfo.Players == 4) + playersImgData = Resources::GetImageData("wiimote4.png"); - // # online players - if ((strcmp(gameinfo.wifiplayers, "") != 0) && (strcmp(gameinfo.wifiplayers, "0") != 0)) - { + playersImg = new GuiImage(playersImgData); + playersImg->SetWidescreen(Settings.widescreen); + playersImg->SetPosition(intputX, inputY); + playersImg->SetAlignment(0, 4); + gameinfoWindow.Append(playersImg); + intputX += (Settings.widescreen ? playersImg->GetWidth() * .8 : playersImg->GetWidth()) + 5; + } + + //draw the input types for this game + if (motionplus == 1) + { + motionplusImg = new GuiImage(motionplusImgData); + motionplusImg->SetWidescreen(Settings.widescreen); + motionplusImg->SetPosition(intputX, inputY); + motionplusImg->SetAlignment(0, 4); + gameinfoWindow.Append(motionplusImg); + intputX += (Settings.widescreen ? motionplusImg->GetWidth() * .8 : motionplusImg->GetWidth()) + 5; + } + if (nunchuk == 1) + { + nunchukImg = new GuiImage(nunchukImgData); + nunchukImg->SetWidescreen(Settings.widescreen); + nunchukImg->SetPosition(intputX, inputY); + nunchukImg->SetAlignment(0, 4); + gameinfoWindow.Append(nunchukImg); + intputX += (Settings.widescreen ? nunchukImg->GetWidth() * .8 : nunchukImg->GetWidth()) + 5; + } + if (classiccontroller == 1) + { + classiccontrollerImg = new GuiImage(classiccontrollerImgData); + classiccontrollerImg->SetWidescreen(Settings.widescreen); + classiccontrollerImg->SetPosition(intputX, inputY); + classiccontrollerImg->SetAlignment(0, 4); + gameinfoWindow.Append(classiccontrollerImg); + intputX += (Settings.widescreen ? classiccontrollerImg->GetWidth() * .8 : classiccontrollerImg->GetWidth()) + + 5; + } + if (gamecube == 1) + { + gcImg = new GuiImage(gamecubeImgData); + gcImg->SetWidescreen(Settings.widescreen); + gcImg->SetPosition(intputX, inputY); + gcImg->SetAlignment(0, 4); + gameinfoWindow.Append(gcImg); + intputX += (Settings.widescreen ? gcImg->GetWidth() * .8 : gcImg->GetWidth()) + 5; + } + if (wheel == 1) + { + wheelImg = new GuiImage(wheelImgData); + wheelImg->SetWidescreen(Settings.widescreen); + wheelImg->SetPosition(intputX, inputY); + wheelImg->SetAlignment(0, 4); + gameinfoWindow.Append(wheelImg); + intputX += (Settings.widescreen ? wheelImg->GetWidth() * .8 : wheelImg->GetWidth()) + 5; + } + if (guitar == 1) + { + guitarImg = new GuiImage(guitarImgData); + guitarImg->SetWidescreen(Settings.widescreen); + guitarImg->SetPosition(intputX, inputY); + guitarImg->SetAlignment(0, 4); + gameinfoWindow.Append(guitarImg); + intputX += (Settings.widescreen ? guitarImg->GetWidth() * .8 : guitarImg->GetWidth()) + 5; + } + if (drums == 1) + { + drumsImg = new GuiImage(drumsImgData); + drumsImg->SetWidescreen(Settings.widescreen); + drumsImg->SetPosition(intputX, inputY); + drumsImg->SetAlignment(0, 4); + gameinfoWindow.Append(drumsImg); + intputX += (Settings.widescreen ? drumsImg->GetWidth() * .8 : drumsImg->GetWidth()) + 5; + } + if (microphone == 1) + { + microphoneImg = new GuiImage(microphoneImgData); + microphoneImg->SetWidescreen(Settings.widescreen); + microphoneImg->SetPosition(intputX, inputY); + microphoneImg->SetAlignment(0, 4); + gameinfoWindow.Append(microphoneImg); + intputX += (Settings.widescreen ? microphoneImg->GetWidth() * .8 : microphoneImg->GetWidth()) + 5; + } + if (zapper == 1) + { + zapperImg = new GuiImage(zapperImgData); + zapperImg->SetWidescreen(Settings.widescreen); + zapperImg->SetPosition(intputX, inputY); + zapperImg->SetAlignment(0, 4); + gameinfoWindow.Append(zapperImg); + intputX += (Settings.widescreen ? zapperImg->GetWidth() * .8 : zapperImg->GetWidth()) + 5; + } + if (wiispeak == 1) + { + wiispeakImg = new GuiImage(wiispeakImgData); + wiispeakImg->SetWidescreen(Settings.widescreen); + wiispeakImg->SetPosition(intputX, inputY); + wiispeakImg->SetAlignment(0, 4); + gameinfoWindow.Append(wiispeakImg); + intputX += (Settings.widescreen ? wiispeakImg->GetWidth() * .8 : wiispeakImg->GetWidth()) + 5; + } + if (nintendods == 1) + { + nintendodsImg = new GuiImage(nintendodsImgData); + nintendodsImg->SetWidescreen(Settings.widescreen); + nintendodsImg->SetPosition(intputX, inputY); + nintendodsImg->SetAlignment(0, 4); + gameinfoWindow.Append(nintendodsImg); + intputX += (Settings.widescreen ? nintendodsImg->GetWidth() * .8 : nintendodsImg->GetWidth()) + 5; + } + if (dancepad == 1) + { + dancepadImg = new GuiImage(dancepadImgData); + dancepadImg->SetWidescreen(Settings.widescreen); + dancepadImg->SetPosition(intputX, inputY); + dancepadImg->SetAlignment(0, 4); + gameinfoWindow.Append(dancepadImg); + intputX += (Settings.widescreen ? dancepadImg->GetWidth() * .8 : dancepadImg->GetWidth()) + 5; + } + if (balanceboard == 1) + { + balanceboardImg = new GuiImage(balanceboardImgData); + balanceboardImg->SetWidescreen(Settings.widescreen); + balanceboardImg->SetPosition(intputX, inputY); + balanceboardImg->SetAlignment(0, 4); + gameinfoWindow.Append(balanceboardImg); + intputX += (Settings.widescreen ? balanceboardImg->GetWidth() * .8 : balanceboardImg->GetWidth()) + 5; + } + + // # online players + if (GameInfo.WifiPlayers > 0) + { + if(GameInfo.WifiPlayers == 1) wifiplayersImgData = Resources::GetImageData("wifi1.png"); - if (atoi(gameinfo.wifiplayers) > 1) - { - wifiplayersImgData = Resources::GetImageData("wifi2.png"); - } - if (atoi(gameinfo.wifiplayers) > 2) - { - wifiplayersImgData = Resources::GetImageData("wifi4.png"); - } - if (atoi(gameinfo.wifiplayers) > 4) - { - wifiplayersImgData =Resources::GetImageData("wifi8.png"); - } - if (atoi(gameinfo.wifiplayers) > 8) - { - wifiplayersImgData = Resources::GetImageData("wifi12.png"); - } - if (atoi(gameinfo.wifiplayers) > 12) - { - wifiplayersImgData = Resources::GetImageData("wifi16.png"); - } - if (atoi(gameinfo.wifiplayers) > 16) - { - wifiplayersImgData = Resources::GetImageData("wifi32.png"); - } - wifiplayersImg = new GuiImage(wifiplayersImgData); - wifiplayersImg->SetWidescreen(Settings.widescreen); - wifiplayersImg->SetPosition(intputX, inputY); - wifiplayersImg->SetAlignment(0, 4); - gameinfoWindow.Append(wifiplayersImg); - intputX += (Settings.widescreen ? wifiplayersImg->GetWidth() * .8 : wifiplayersImg->GetWidth()) + 5; - } - // ratings - if (strcmp(gameinfo.ratingtype, "") != 0) + else if(GameInfo.WifiPlayers == 2) + wifiplayersImgData = Resources::GetImageData("wifi2.png"); + + else if(GameInfo.WifiPlayers == 4) + wifiplayersImgData = Resources::GetImageData("wifi4.png"); + + else if(GameInfo.WifiPlayers == 8) + wifiplayersImgData =Resources::GetImageData("wifi8.png"); + + else if(GameInfo.WifiPlayers == 12) + wifiplayersImgData = Resources::GetImageData("wifi12.png"); + + else if(GameInfo.WifiPlayers == 16) + wifiplayersImgData = Resources::GetImageData("wifi16.png"); + + else if(GameInfo.WifiPlayers == 32) + wifiplayersImgData = Resources::GetImageData("wifi32.png"); + + wifiplayersImg = new GuiImage(wifiplayersImgData); + wifiplayersImg->SetWidescreen(Settings.widescreen); + wifiplayersImg->SetPosition(intputX, inputY); + wifiplayersImg->SetAlignment(0, 4); + gameinfoWindow.Append(wifiplayersImg); + intputX += (Settings.widescreen ? wifiplayersImg->GetWidth() * .8 : wifiplayersImg->GetWidth()) + 5; + } + + // ratings + if (GameInfo.RatingType >= 0) + { + if (GameInfo.RatingType == 1) { - if (strcmp(gameinfo.ratingtype, "ESRB") == 0) - { - if (strcmp(gameinfo.ratingvalueESRB, "EC") == 0) - ratingImgData = Resources::GetImageData("esrb_ec.png"); - else if (strcmp(gameinfo.ratingvalueESRB, "E") == 0) - ratingImgData = Resources::GetImageData("esrb_e.png"); - else if (strcmp(gameinfo.ratingvalueESRB, "E10+") == 0) - ratingImgData = Resources::GetImageData("esrb_eten.png"); - else if (strcmp(gameinfo.ratingvalueESRB, "T") == 0) - ratingImgData = Resources::GetImageData("esrb_t.png"); - else if (strcmp(gameinfo.ratingvalueESRB, "M") == 0) - ratingImgData = Resources::GetImageData("esrb_m.png"); - else if (strcmp(gameinfo.ratingvalueESRB, "AO") == 0) - ratingImgData = Resources::GetImageData("esrb_ao.png"); - else - { - ratingImgData = Resources::GetImageData("norating.png"); - } - } //there are 2 values here cause some countries are stupid and - else if (strcmp(gameinfo.ratingtype, "PEGI") == 0) //can't use the same as everybody else - { - if ((strcmp(gameinfo.ratingvaluePEGI, "3") == 0) || (strcmp(gameinfo.ratingvaluePEGI, "4") == 0)) - ratingImgData = Resources::GetImageData("pegi_3.png"); - else if ((strcmp(gameinfo.ratingvaluePEGI, "7") == 0) || (strcmp(gameinfo.ratingvaluePEGI, "7") == 0)) - ratingImgData = Resources::GetImageData("pegi_7.png"); - else if (strcmp(gameinfo.ratingvaluePEGI, "12") == 0) - ratingImgData = Resources::GetImageData("pegi_12.png"); - else if ((strcmp(gameinfo.ratingvaluePEGI, "16") == 0) || (strcmp(gameinfo.ratingvaluePEGI, "15") == 0)) - ratingImgData = Resources::GetImageData("pegi_16.png"); - else if (strcmp(gameinfo.ratingvaluePEGI, "18") == 0) - ratingImgData = Resources::GetImageData("pegi_18.png"); - else - { - ratingImgData = Resources::GetImageData("norating.png"); - } - } - else if (strcmp(gameinfo.ratingtype, "CERO") == 0) - { - if (strcmp(gameinfo.ratingvalueCERO, "A") == 0) - ratingImgData = Resources::GetImageData("cero_a.png"); - else if (strcmp(gameinfo.ratingvalueCERO, "B") == 0) - ratingImgData = Resources::GetImageData("cero_b.png"); - else if (strcmp(gameinfo.ratingvalueCERO, "C") == 0) - ratingImgData = Resources::GetImageData("cero_c.png"); - else if (strcmp(gameinfo.ratingvalueCERO, "D") == 0) - ratingImgData = Resources::GetImageData("cero_d.png"); - else if (strcmp(gameinfo.ratingvalueCERO, "Z") == 0) - ratingImgData = Resources::GetImageData("cero_z.png"); - else - { - ratingImgData = Resources::GetImageData("norating.png"); - } - } - + if (strcmp(GameInfo.RatingValue.c_str(), "EC") == 0) + ratingImgData = Resources::GetImageData("esrb_ec.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "E") == 0) + ratingImgData = Resources::GetImageData("esrb_e.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "E10+") == 0) + ratingImgData = Resources::GetImageData("esrb_eten.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "T") == 0) + ratingImgData = Resources::GetImageData("esrb_t.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "M") == 0) + ratingImgData = Resources::GetImageData("esrb_m.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "AO") == 0) + ratingImgData = Resources::GetImageData("esrb_ao.png"); + else + ratingImgData = Resources::GetImageData("norating.png"); + } //there are 2 values here cause some countries are stupid and + else if (GameInfo.RatingType == 2) //can't use the same as everybody else + { + if ((strcmp(GameInfo.RatingValue.c_str(), "3") == 0) || (strcmp(GameInfo.RatingValue.c_str(), "4") == 0)) + ratingImgData = Resources::GetImageData("pegi_3.png"); + else if ((strcmp(GameInfo.RatingValue.c_str(), "7") == 0) || (strcmp(GameInfo.RatingValue.c_str(), "7") == 0)) + ratingImgData = Resources::GetImageData("pegi_7.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "12") == 0) + ratingImgData = Resources::GetImageData("pegi_12.png"); + else if ((strcmp(GameInfo.RatingValue.c_str(), "16") == 0) || (strcmp(GameInfo.RatingValue.c_str(), "15") == 0)) + ratingImgData = Resources::GetImageData("pegi_16.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "18") == 0) + ratingImgData = Resources::GetImageData("pegi_18.png"); else { ratingImgData = Resources::GetImageData("norating.png"); } - ratingImg = new GuiImage(ratingImgData); - ratingImg->SetWidescreen(Settings.widescreen); - ratingImg->SetPosition(-25, inputY); - ratingImg->SetAlignment(1, 4); - gameinfoWindow.Append(ratingImg); - intputX += (Settings.widescreen ? ratingImg->GetWidth() * .8 : ratingImg->GetWidth()) + 5; } - - // memory info - if (showmeminfo) + else if (GameInfo.RatingType == 0) { - char meminfotxt[200]; - strlcpy(meminfotxt, MemInfo(), sizeof(meminfotxt)); - snprintf(linebuf, sizeof(linebuf), "%s", meminfotxt); - memTxt = new GuiText(linebuf, 18, ( GXColor ) - { 0, 0, 0, 255}); - memTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - memTxt->SetPosition(0, 0); - gameinfoWindow.Append(memTxt); - } - - // title - int titlefontsize = 25; - if (strcmp(gameinfo.title, "") != 0) - { - snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.title); - titleTxt = new GuiText(linebuf, titlefontsize, ( GXColor ) - { 0, 0, 0, 255}); - titleTxt->SetMaxWidth(350, SCROLL_HORIZONTAL); - //while (titleTxt->GetWidth()>250) { titleTxt->SetFontSize(titlefontsize-=2); } - titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt->SetPosition(txtXOffset, 12 + titley); - gameinfoWindow.Append(titleTxt); - } - - //date - snprintf(linebuf2, sizeof(linebuf2), " "); - if (strcmp(gameinfo.day, "") != 0) - { - snprintf(linebuf2, sizeof(linebuf2), "%s ", gameinfo.day); - } - if (strcmp(gameinfo.month, "") != 0) - { - switch (atoi(gameinfo.month)) - { - case 1: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Jan" )); - break; - case 2: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Feb" )); - break; - case 3: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Mar" )); - break; - case 4: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Apr" )); - break; - case 5: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "May" )); - break; - case 6: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "June" )); - break; - case 7: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "July" )); - break; - case 8: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Aug" )); - break; - case 9: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Sept" )); - break; - case 10: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Oct" )); - break; - case 11: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Nov" )); - break; - case 12: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Dec" )); - break; - } - } - if (strcmp(gameinfo.year, "") != 0) - { - snprintf(linebuf, sizeof(linebuf), "%s : %s%s", tr( "Released" ), linebuf2, gameinfo.year); - releasedTxt = new GuiText(linebuf, 16, ( GXColor ) - { 0, 0, 0, 255}); - if (releasedTxt->GetWidth() > 300) newline = 2; - releasedTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - releasedTxt->SetPosition(-17, 12 + indexy); - indexy += (20 * newline); - newline = 1; - gameinfoWindow.Append(releasedTxt); - } - - //publisher - if (strcmp(gameinfo.publisher, "") != 0) - { - snprintf(linebuf, sizeof(linebuf), "%s %s", tr( "Published by" ), gameinfo.publisher); - publisherTxt = new GuiText(linebuf, 16, ( GXColor ) - { 0, 0, 0, 255}); - if (publisherTxt->GetWidth() > 250) newline = 2; - publisherTxt->SetMaxWidth(250, WRAP); - publisherTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - publisherTxt->SetPosition(-17, 12 + indexy); - indexy += (20 * newline); - newline = 1; - gameinfoWindow.Append(publisherTxt); - } - - //developer - if (strcmp(gameinfo.developer, "") != 0 && strcasecmp(gameinfo.developer, gameinfo.publisher) != 0) - { - snprintf(linebuf, sizeof(linebuf), "%s %s", tr( "Developed by" ), gameinfo.developer); - developerTxt = new GuiText(linebuf, 16, ( GXColor ) - { 0, 0, 0, 255}); - if (developerTxt->GetWidth() > 250) newline = 2; - developerTxt->SetMaxWidth(250, WRAP); - developerTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - developerTxt->SetPosition(-17, 12 + indexy); - indexy += (20 * newline); - newline = 1; - gameinfoWindow.Append(developerTxt); - } - - //genre - int genreY = marginY; - genreTxt = new GuiText *[gameinfo.genreCnt + 1]; - for (int i = 1; i <= gameinfo.genreCnt; i++) - { - snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.genresplit[i]); - genreTxt[i] = new GuiText(linebuf, 16, ( GXColor ) - { 0, 0, 0, 255}); - genreTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - genreTxt[i]->SetPosition(205, 12 + genreY); - genreY += 20; - gameinfoWindow.Append(genreTxt[i]); - } - - //online - wifiTxt = new GuiText *[gameinfo.wifiCnt + 1]; - for (int i = gameinfo.wifiCnt; i >= 1; i--) - { - if (strcmp(gameinfo.wififeatures[i], "Nintendods") == 0) - { - snprintf(linebuf, sizeof(linebuf), "Nintendo DS"); - } + if (strcmp(GameInfo.RatingValue.c_str(), "A") == 0) + ratingImgData = Resources::GetImageData("cero_a.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "B") == 0) + ratingImgData = Resources::GetImageData("cero_b.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "C") == 0) + ratingImgData = Resources::GetImageData("cero_c.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "D") == 0) + ratingImgData = Resources::GetImageData("cero_d.png"); + else if (strcmp(GameInfo.RatingValue.c_str(), "Z") == 0) + ratingImgData = Resources::GetImageData("cero_z.png"); else { - snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.wififeatures[i]); + ratingImgData = Resources::GetImageData("norating.png"); } - 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; - gameinfoWindow.Append(wifiTxt[i]); } - if (strcmp(gameinfo.wififeatures[1], "") != 0) + + else { - snprintf(linebuf, sizeof(linebuf), "%s:", tr( "WiFi Features" )); + ratingImgData = Resources::GetImageData("norating.png"); + } + ratingImg = new GuiImage(ratingImgData); + ratingImg->SetWidescreen(Settings.widescreen); + ratingImg->SetPosition(-25, inputY); + ratingImg->SetAlignment(1, 4); + gameinfoWindow.Append(ratingImg); + intputX += (Settings.widescreen ? ratingImg->GetWidth() * .8 : ratingImg->GetWidth()) + 5; + } + + // memory info + if (showmeminfo) + { + char meminfotxt[200]; + strlcpy(meminfotxt, MemInfo(), sizeof(meminfotxt)); + memTxt = new GuiText(meminfotxt, 18, ( GXColor ) {0, 0, 0, 255}); + memTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); + memTxt->SetPosition(0, 0); + gameinfoWindow.Append(memTxt); + } + + // title + int titlefontsize = 25; + if (GameInfo.Title.size() > 0) + { + titleTxt = new GuiText(GameInfo.Title.c_str(), titlefontsize, ( GXColor ) {0, 0, 0, 255}); + titleTxt->SetMaxWidth(350, SCROLL_HORIZONTAL); + titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); + titleTxt->SetPosition(txtXOffset, 12 + titley); + gameinfoWindow.Append(titleTxt); + } + + //date + snprintf(linebuf2, sizeof(linebuf2), " "); + if (GameInfo.PublishDate != 0) + { + int year = GameInfo.PublishDate >> 16; + int day = GameInfo.PublishDate & 0xFF; + int month = (GameInfo.PublishDate >> 8) & 0xFF; + snprintf(linebuf2, sizeof(linebuf2), "%02i ", day); + + switch (month) + { + case 1: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Jan" )); + break; + case 2: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Feb" )); + break; + case 3: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Mar" )); + break; + case 4: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Apr" )); + break; + case 5: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "May" )); + break; + case 6: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "June" )); + break; + case 7: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "July" )); + break; + case 8: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Aug" )); + break; + case 9: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Sept" )); + break; + case 10: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Oct" )); + break; + case 11: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Nov" )); + break; + case 12: + snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Dec" )); + break; + } + + char linebuf[300]; + snprintf(linebuf, sizeof(linebuf), "%s : %s%i", tr( "Released" ), linebuf2, year); + releasedTxt = new GuiText(linebuf, 16, ( GXColor ) {0, 0, 0, 255}); + if (releasedTxt->GetWidth() > 300) newline = 2; + releasedTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); + releasedTxt->SetPosition(-17, 12 + indexy); + indexy += (20 * newline); + newline = 1; + gameinfoWindow.Append(releasedTxt); + } + + //publisher + if (GameInfo.Publisher.size() != 0) + { + snprintf(linebuf2, sizeof(linebuf2), "%s %s", tr( "Published by" ), GameInfo.Publisher.c_str()); + publisherTxt = new GuiText(linebuf2, 16, ( GXColor ) {0, 0, 0, 255}); + if (publisherTxt->GetWidth() > 250) newline = 2; + publisherTxt->SetMaxWidth(250, WRAP); + publisherTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); + publisherTxt->SetPosition(-17, 12 + indexy); + indexy += (20 * newline); + newline = 1; + gameinfoWindow.Append(publisherTxt); + } + + //developer + if (GameInfo.Developer.size() != 0 && strcasecmp(GameInfo.Developer.c_str(), GameInfo.Publisher.c_str()) != 0) + { + snprintf(linebuf2, sizeof(linebuf2), "%s %s", tr( "Developed by" ), GameInfo.Developer.c_str()); + developerTxt = new GuiText(linebuf2, 16, ( GXColor ) {0, 0, 0, 255}); + if (developerTxt->GetWidth() > 250) newline = 2; + developerTxt->SetMaxWidth(250, WRAP); + developerTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); + developerTxt->SetPosition(-17, 12 + indexy); + indexy += (20 * newline); + newline = 1; + gameinfoWindow.Append(developerTxt); + } + + //genre + int genreY = marginY; + if(GameInfo.GenreList.size() > 0) + { + genreTitleTxt = new GuiText(tr("Gerne:"), 16, ( GXColor ) {0, 0, 0, 255}); + genreTitleTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); + genreTitleTxt->SetPosition(205, 12 + genreY); + genreY += 20; + gameinfoWindow.Append(genreTitleTxt); + } + + genreTxt = new GuiText *[GameInfo.GenreList.size()+1]; //to not alloc a 0 vector + for (u32 i = 0; i < GameInfo.GenreList.size(); ++i) + { + genreTxt[i] = new GuiText(GameInfo.GenreList[i].c_str(), 16, ( GXColor ) {0, 0, 0, 255}); + genreTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); + genreTxt[i]->SetPosition(215, 12 + genreY); + genreY += 20; + gameinfoWindow.Append(genreTxt[i]); + } + + //online + wifiTxt = new GuiText *[GameInfo.WifiFeatureList.size()+1]; //to not alloc a 0 vector + for (int i = GameInfo.WifiFeatureList.size()-1; i >= 0 && GameInfo.WifiFeatureList.size() > 0; --i) + { + if (strcmp(GameInfo.WifiFeatureList[i].c_str(), "Nintendods") == 0) + { + snprintf(linebuf2, sizeof(linebuf2), "Nintendo DS"); } else { - strcpy(linebuf, ""); + snprintf(linebuf2, sizeof(linebuf2), "%s", GameInfo.WifiFeatureList[i].c_str()); } - 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) - { - snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis); - synopsisTxt = new Text(linebuf, 16, ( GXColor ) - { 0, 0, 0, 255}); - synopsisTxt->SetMaxWidth(350); - synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - synopsisTxt->SetPosition(0, 0); - synopsisTxt->SetLinesToDraw(pagesize); - synopsisTxt->Refresh(); - - dialogBoxImg11 = new GuiImage(&dialogBox1); - dialogBoxImg11->SetAlignment(0, 3); - dialogBoxImg11->SetPosition(-9, 0); - - dialogBoxImg22 = new GuiImage(&dialogBox2); - dialogBoxImg22->SetAlignment(0, 3); - dialogBoxImg22->SetPosition(145, 0); - - dialogBoxImg33 = new GuiImage(&dialogBox3); - dialogBoxImg33->SetAlignment(0, 3); - dialogBoxImg33->SetPosition(301, 0); - - dialogBoxImg44 = new GuiImage(&dialogBox4); - dialogBoxImg44->SetAlignment(0, 3); - dialogBoxImg44->SetPosition(457, 0); - - gameinfoWindow2.Append(dialogBoxImg11); - gameinfoWindow2.Append(dialogBoxImg22); - gameinfoWindow2.Append(dialogBoxImg33); - gameinfoWindow2.Append(dialogBoxImg44); - - txtWindow.Append(synopsisTxt); - txtWindow.Append(&upBtn); - txtWindow.Append(&dnBtn); - coverImg2 = new GuiImage(cover); - coverImg2->SetWidescreen(Settings.widescreen); - coverImg2->SetPosition(15, 30); - gameinfoWindow2.Append(coverImg2); - gameinfoWindow2.Append(&txtWindow); - } - - snprintf(linebuf, sizeof(linebuf), "http://wiitdb.com"); - //snprintf(linebuf, sizeof(linebuf), tr("Don't bother the USB Loader GX Team about errors in this file.")); - wiitdb1Txt = new GuiText(linebuf, 16, ( GXColor ) - { 0, 0, 0, 255}); - wiitdb1Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - wiitdb1Txt->SetPosition(40, -15); - gameinfoWindow.Append(wiitdb1Txt); - snprintf(linebuf, sizeof(linebuf), tr( "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" )); - wiitdb2Txt = new GuiText(linebuf, 14, ( GXColor ) - { 0, 0, 0, 255}); - wiitdb2Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - wiitdb2Txt->SetPosition(202, -15); - gameinfoWindow.Append(wiitdb2Txt); - snprintf(linebuf, sizeof(linebuf), " "); - wiitdb3Txt = new GuiText(linebuf, 14, ( GXColor ) - { 0, 0, 0, 255}); - wiitdb3Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - wiitdb3Txt->SetPosition(202, -4); - gameinfoWindow.Append(wiitdb3Txt); - - gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 100); - - GuiTrigger trigZ; - trigZ.SetButtonOnlyTrigger(-1, WPAD_NUNCHUK_BUTTON_Z | WPAD_CLASSIC_BUTTON_ZL, PAD_TRIGGER_Z); - - GuiButton screenShotBtn(0, 0); - screenShotBtn.SetPosition(0, 0); - screenShotBtn.SetTrigger(&trigZ); - gameinfoWindow.Append(&screenShotBtn); - HaltGui(); - //mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&gameinfoWindow); - mainWindow->ChangeFocus(&gameinfoWindow); - ResumeGui(); - - bool savedURL = false; - - while (choice == -1) - { - - VIDEO_WaitVSync(); - if (shutdown == 1) - { - wiilight(0); - Sys_Shutdown(); - } - else if (reset == 1) - Sys_Reboot(); - - else if ((backBtn.GetState() == STATE_CLICKED) || (backBtn.GetState() == STATE_HELD)) - { - backBtn.ResetState(); - if (page == 1) - { - choice = 1; - if (synopsisTxt) delete synopsisTxt; - synopsisTxt = NULL; - break; - } - else if (page == 2) - { - HaltGui(); - gameinfoWindow2.Remove(&nextBtn); - gameinfoWindow2.Remove(&backBtn); - gameinfoWindow2.Remove(&homeBtn); - gameinfoWindow2.Remove(&screenShotBtn); - gameinfoWindow2.SetVisible(false); - gameinfoWindow.SetVisible(true); - gameinfoWindow.Append(&backBtn); - gameinfoWindow.Append(&nextBtn); - gameinfoWindow.Append(&homeBtn); - gameinfoWindow.Append(&screenShotBtn); - mainWindow->Remove(&gameinfoWindow2); - ResumeGui(); - page = 1; - } - } - else if (((nextBtn.GetState() == STATE_CLICKED) || (nextBtn.GetState() == STATE_HELD)) && (strcmp( - gameinfo.synopsis, "") != 0)) - { - nextBtn.ResetState(); - - if (page == 1) - { - HaltGui(); - gameinfoWindow.Remove(&nextBtn); - gameinfoWindow.Remove(&backBtn); - gameinfoWindow.Remove(&homeBtn); - gameinfoWindow.Remove(&screenShotBtn); - gameinfoWindow.SetVisible(false); - gameinfoWindow2.SetVisible(true); - coverImg->SetPosition(15, 30); - gameinfoWindow2.Append(&nextBtn); - gameinfoWindow2.Append(&backBtn); - gameinfoWindow2.Append(&homeBtn); - gameinfoWindow2.Append(&screenShotBtn); - mainWindow->Append(&gameinfoWindow2); - ResumeGui(); - page = 2; - } - else - { - HaltGui(); - gameinfoWindow2.Remove(&nextBtn); - gameinfoWindow2.Remove(&backBtn); - gameinfoWindow2.Remove(&homeBtn); - gameinfoWindow2.Remove(&screenShotBtn); - gameinfoWindow2.SetVisible(false); - gameinfoWindow.SetVisible(true); - gameinfoWindow.Append(&backBtn); - gameinfoWindow.Append(&nextBtn); - gameinfoWindow.Append(&homeBtn); - gameinfoWindow.Append(&screenShotBtn); - mainWindow->Remove(&gameinfoWindow2); - ResumeGui(); - page = 1; - } - - } - else if ((upBtn.GetState() == STATE_CLICKED || upBtn.GetState() == STATE_HELD) && page == 2) - { - synopsisTxt->PreviousLine(); - - usleep(60000); - if (!((ButtonsHold() & WPAD_BUTTON_UP) || (ButtonsHold() & PAD_BUTTON_UP))) upBtn.ResetState(); - - } - else if ((dnBtn.GetState() == STATE_CLICKED || dnBtn.GetState() == STATE_HELD) && page == 2) - { - synopsisTxt->NextLine(); - - usleep(60000); - if (!((ButtonsHold() & WPAD_BUTTON_DOWN) || (ButtonsHold() & PAD_BUTTON_DOWN))) dnBtn.ResetState(); - } - else if (homeBtn.GetState() == STATE_CLICKED) - { - if (page == 1) - { - choice = 2; - if (synopsisTxt) delete synopsisTxt; - synopsisTxt = NULL; - break; - } - else if (page == 2) - { - HaltGui(); - gameinfoWindow2.SetVisible(false); - gameinfoWindow.SetVisible(true); - mainWindow->Remove(&gameinfoWindow2); - ResumeGui(); - page = 1; - } - } - else if (urlBtn.GetState() == STATE_CLICKED && !savedURL) - { - snprintf(linebuf, sizeof(linebuf), tr( "Please wait..." )); - wiitdb2Txt->SetText(linebuf); - gameinfoWindow.Append(wiitdb2Txt); - if (save_XML_URL()) - { - snprintf(linebuf, sizeof(linebuf), tr( "Your URL has been saved in %sWiiTDB_URL.txt." ), - Settings.update_path); - wiitdb2Txt->SetText(linebuf); - gameinfoWindow.Append(wiitdb2Txt); - snprintf(linebuf, sizeof(linebuf), tr( "Paste it into your browser to get your WiiTDB.zip." )); - wiitdb3Txt->SetText(linebuf); - gameinfoWindow.Append(wiitdb3Txt); - savedURL = true; - } - else - { - snprintf(linebuf, sizeof(linebuf), tr( "Could not save." )); - wiitdb2Txt->SetText(linebuf); - gameinfoWindow.Append(wiitdb2Txt); - } - urlBtn.ResetState(); - } - else if (screenShotBtn.GetState() == STATE_CLICKED) - { - gprintf("\n\tscreenShotBtn clicked"); - screenShotBtn.ResetState(); - ScreenShot(); - gprintf("...It's easy, mmmmmmKay"); - } - } - if (page == 1) - { - gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 100); - while (gameinfoWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&gameinfoWindow); - mainWindow->SetState(STATE_DEFAULT); - - delete playersImgData; - delete playersImg; - - delete wifiplayersImgData; - delete wifiplayersImg; - delete ratingImg; - - delete classiccontrollerImg; - delete nunchukImg; - delete guitarImg; - delete drumsImg; - delete dancepadImg; - delete motionplusImg; - delete wheelImg; - delete balanceboardImg; - delete microphoneImg; - delete zapperImg; - delete wiispeakImg; - delete nintendodsImg; - //delete vitalitysensorImg; - delete gcImg; - delete dialogBoxImg1; - delete dialogBoxImg2; - delete dialogBoxImg3; - delete dialogBoxImg4; - delete dialogBoxImg11; - delete dialogBoxImg22; - delete dialogBoxImg33; - delete dialogBoxImg44; - delete coverImg; - delete coverImg2; - - delete classiccontrollerImgData; - delete nunchukImgData; - delete guitarImgData; - delete drumsImgData; - delete motionplusImgData; - delete wheelImgData; - delete balanceboardImgData; - delete dancepadImgData; - delete microphoneImgData; - delete zapperImgData; - delete wiispeakImgData; - delete nintendodsImgData; - //delete vitalitysensorImgData; - delete gamecubeImgData; - delete ratingImgData; - delete cover; - delete releasedTxt; - delete publisherTxt; - delete developerTxt; - delete titleTxt; - delete synopsisTxt; - delete wiitdb1Txt; - delete wiitdb2Txt; - delete wiitdb3Txt; - delete memTxt; - if (gameinfo.genreCnt > 0) - { - for (int i = 1; i <= gameinfo.genreCnt; i++) - { - delete genreTxt[i]; - } - } - if (gameinfo.wifiCnt > 0) - { - for (int i = 0; i <= gameinfo.wifiCnt; i++) - { - delete wifiTxt[i]; - } - } - ResumeGui(); - } - else - { - gameinfoWindow2.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 100); - while (gameinfoWindow2.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&gameinfoWindow2); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - } - - if (savedURL) return 3; - return choice; - - /* File not found */ + wifiTxt[i] = new GuiText(linebuf2, 16, ( GXColor ) {0, 0, 0, 255}); + wifiTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); + wifiTxt[i]->SetPosition(215, 200 + wifiY); + wifiY -= 20; + gameinfoWindow.Append(wifiTxt[i]); + } + if (GameInfo.WifiFeatureList.size() > 0) + { + snprintf(linebuf2, sizeof(linebuf2), "%s:", tr( "WiFi Features" )); } else { - return -1; + strcpy(linebuf2, ""); } + wifiTxt[0] = new GuiText(linebuf2, 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 (GameInfo.Synopsis.size() != 0) + { + synopsisTxt = new Text(GameInfo.Synopsis.c_str(), 16, ( GXColor ) {0, 0, 0, 255}); + synopsisTxt->SetMaxWidth(350); + synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); + synopsisTxt->SetPosition(0, 0); + synopsisTxt->SetLinesToDraw(pagesize); + synopsisTxt->Refresh(); + + dialogBoxImg11 = new GuiImage(&dialogBox1); + dialogBoxImg11->SetAlignment(0, 3); + dialogBoxImg11->SetPosition(-9, 0); + + dialogBoxImg22 = new GuiImage(&dialogBox2); + dialogBoxImg22->SetAlignment(0, 3); + dialogBoxImg22->SetPosition(145, 0); + + dialogBoxImg33 = new GuiImage(&dialogBox3); + dialogBoxImg33->SetAlignment(0, 3); + dialogBoxImg33->SetPosition(301, 0); + + dialogBoxImg44 = new GuiImage(&dialogBox4); + dialogBoxImg44->SetAlignment(0, 3); + dialogBoxImg44->SetPosition(457, 0); + + gameinfoWindow2.Append(dialogBoxImg11); + gameinfoWindow2.Append(dialogBoxImg22); + gameinfoWindow2.Append(dialogBoxImg33); + gameinfoWindow2.Append(dialogBoxImg44); + + txtWindow.Append(synopsisTxt); + txtWindow.Append(&upBtn); + txtWindow.Append(&dnBtn); + coverImg2 = new GuiImage(cover); + coverImg2->SetWidescreen(Settings.widescreen); + coverImg2->SetPosition(15, 30); + gameinfoWindow2.Append(coverImg2); + gameinfoWindow2.Append(&txtWindow); + } + + wiitdb1Txt = new GuiText("http://wiitdb.com", 16, ( GXColor ) {0, 0, 0, 255}); + wiitdb1Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); + wiitdb1Txt->SetPosition(40, -15); + gameinfoWindow.Append(wiitdb1Txt); + + wiitdb2Txt = new GuiText(tr( "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" ), 14, ( GXColor ) {0, 0, 0, 255}); + wiitdb2Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); + wiitdb2Txt->SetPosition(202, -15); + gameinfoWindow.Append(wiitdb2Txt); + + wiitdb3Txt = new GuiText(" ", 14, ( GXColor ) {0, 0, 0, 255}); + wiitdb3Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); + wiitdb3Txt->SetPosition(202, -4); + gameinfoWindow.Append(wiitdb3Txt); + + gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 100); + + GuiTrigger trigZ; + trigZ.SetButtonOnlyTrigger(-1, WPAD_NUNCHUK_BUTTON_Z | WPAD_CLASSIC_BUTTON_ZL, PAD_TRIGGER_Z); + + GuiButton screenShotBtn(0, 0); + screenShotBtn.SetPosition(0, 0); + screenShotBtn.SetTrigger(&trigZ); + gameinfoWindow.Append(&screenShotBtn); + HaltGui(); + //mainWindow->SetState(STATE_DISABLED); + mainWindow->Append(&gameinfoWindow); + mainWindow->ChangeFocus(&gameinfoWindow); + ResumeGui(); + + bool savedURL = false; + + while (choice == -1) + { + + VIDEO_WaitVSync(); + if (shutdown == 1) + { + wiilight(0); + Sys_Shutdown(); + } + else if (reset == 1) + Sys_Reboot(); + + else if ((backBtn.GetState() == STATE_CLICKED) || (backBtn.GetState() == STATE_HELD)) + { + backBtn.ResetState(); + if (page == 1) + { + choice = 1; + if (synopsisTxt) delete synopsisTxt; + synopsisTxt = NULL; + break; + } + else if (page == 2) + { + HaltGui(); + gameinfoWindow2.Remove(&nextBtn); + gameinfoWindow2.Remove(&backBtn); + gameinfoWindow2.Remove(&homeBtn); + gameinfoWindow2.Remove(&screenShotBtn); + gameinfoWindow2.SetVisible(false); + gameinfoWindow.SetVisible(true); + gameinfoWindow.Append(&backBtn); + gameinfoWindow.Append(&nextBtn); + gameinfoWindow.Append(&homeBtn); + gameinfoWindow.Append(&screenShotBtn); + mainWindow->Remove(&gameinfoWindow2); + ResumeGui(); + page = 1; + } + } + else if (((nextBtn.GetState() == STATE_CLICKED) || (nextBtn.GetState() == STATE_HELD)) && GameInfo.Synopsis.size() > 0) + { + nextBtn.ResetState(); + + if (page == 1) + { + HaltGui(); + gameinfoWindow.Remove(&nextBtn); + gameinfoWindow.Remove(&backBtn); + gameinfoWindow.Remove(&homeBtn); + gameinfoWindow.Remove(&screenShotBtn); + gameinfoWindow.SetVisible(false); + gameinfoWindow2.SetVisible(true); + coverImg->SetPosition(15, 30); + gameinfoWindow2.Append(&nextBtn); + gameinfoWindow2.Append(&backBtn); + gameinfoWindow2.Append(&homeBtn); + gameinfoWindow2.Append(&screenShotBtn); + mainWindow->Append(&gameinfoWindow2); + ResumeGui(); + page = 2; + } + else + { + HaltGui(); + gameinfoWindow2.Remove(&nextBtn); + gameinfoWindow2.Remove(&backBtn); + gameinfoWindow2.Remove(&homeBtn); + gameinfoWindow2.Remove(&screenShotBtn); + gameinfoWindow2.SetVisible(false); + gameinfoWindow.SetVisible(true); + gameinfoWindow.Append(&backBtn); + gameinfoWindow.Append(&nextBtn); + gameinfoWindow.Append(&homeBtn); + gameinfoWindow.Append(&screenShotBtn); + mainWindow->Remove(&gameinfoWindow2); + ResumeGui(); + page = 1; + } + + } + else if ((upBtn.GetState() == STATE_CLICKED || upBtn.GetState() == STATE_HELD) && page == 2) + { + synopsisTxt->PreviousLine(); + + usleep(60000); + if (!((ButtonsHold() & WPAD_BUTTON_UP) || (ButtonsHold() & PAD_BUTTON_UP))) upBtn.ResetState(); + + } + else if ((dnBtn.GetState() == STATE_CLICKED || dnBtn.GetState() == STATE_HELD) && page == 2) + { + synopsisTxt->NextLine(); + + usleep(60000); + if (!((ButtonsHold() & WPAD_BUTTON_DOWN) || (ButtonsHold() & PAD_BUTTON_DOWN))) dnBtn.ResetState(); + } + else if (homeBtn.GetState() == STATE_CLICKED) + { + if (page == 1) + { + choice = 2; + if (synopsisTxt) delete synopsisTxt; + synopsisTxt = NULL; + break; + } + else if (page == 2) + { + HaltGui(); + gameinfoWindow2.SetVisible(false); + gameinfoWindow.SetVisible(true); + mainWindow->Remove(&gameinfoWindow2); + ResumeGui(); + page = 1; + } + } + else if (urlBtn.GetState() == STATE_CLICKED && !savedURL) + { + wiitdb2Txt->SetText(tr( "Please wait..." )); + gameinfoWindow.Append(wiitdb2Txt); + if (save_XML_URL()) + { + snprintf(linebuf2, sizeof(linebuf2), tr( "Your URL has been saved in %sWiiTDB_URL.txt." ), Settings.update_path); + wiitdb2Txt->SetText(linebuf2); + gameinfoWindow.Append(wiitdb2Txt); + + wiitdb3Txt->SetText(tr( "Paste it into your browser to get your WiiTDB.zip." )); + gameinfoWindow.Append(wiitdb3Txt); + savedURL = true; + } + else + { + wiitdb2Txt->SetText(tr( "Could not save." )); + gameinfoWindow.Append(wiitdb2Txt); + } + urlBtn.ResetState(); + } + else if (screenShotBtn.GetState() == STATE_CLICKED) + { + gprintf("\n\tscreenShotBtn clicked"); + screenShotBtn.ResetState(); + ScreenShot(); + gprintf("...It's easy, mmmmmmKay"); + } + } + + gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 100); + while (gameinfoWindow.GetEffect() > 0) + usleep(100); + HaltGui(); + mainWindow->Remove(&gameinfoWindow); + mainWindow->SetState(STATE_DEFAULT); + + delete playersImgData; + delete playersImg; + + delete wifiplayersImgData; + delete wifiplayersImg; + delete ratingImg; + + delete classiccontrollerImg; + delete nunchukImg; + delete guitarImg; + delete drumsImg; + delete dancepadImg; + delete motionplusImg; + delete wheelImg; + delete balanceboardImg; + delete microphoneImg; + delete zapperImg; + delete wiispeakImg; + delete nintendodsImg; + delete gcImg; + delete dialogBoxImg1; + delete dialogBoxImg2; + delete dialogBoxImg3; + delete dialogBoxImg4; + delete dialogBoxImg11; + delete dialogBoxImg22; + delete dialogBoxImg33; + delete dialogBoxImg44; + delete coverImg; + delete coverImg2; + delete classiccontrollerImgData; + delete nunchukImgData; + delete guitarImgData; + delete drumsImgData; + delete motionplusImgData; + delete wheelImgData; + delete balanceboardImgData; + delete dancepadImgData; + delete microphoneImgData; + delete zapperImgData; + delete wiispeakImgData; + delete nintendodsImgData; + delete gamecubeImgData; + delete ratingImgData; + delete cover; + delete releasedTxt; + delete publisherTxt; + delete developerTxt; + delete titleTxt; + delete synopsisTxt; + delete genreTitleTxt; + delete wiitdb1Txt; + delete wiitdb2Txt; + delete wiitdb3Txt; + delete memTxt; + for (u32 i = 0; i < GameInfo.GenreList.size(); ++i) + delete genreTxt[i]; + + for (u32 i = 0; i < GameInfo.WifiFeatureList.size(); ++i) + delete wifiTxt[i]; + + delete [] genreTxt; + delete [] wifiTxt; + + ResumeGui(); + + if (savedURL) return 3; + + return choice; } bool save_gamelist(int txt) // save gamelist diff --git a/source/settings/GameTitles.cpp b/source/settings/GameTitles.cpp index 934e2fdc..6c6d9b1b 100644 --- a/source/settings/GameTitles.cpp +++ b/source/settings/GameTitles.cpp @@ -1,5 +1,8 @@ #include #include "GameTitles.h" +#include "CSettings.h" +#include "usbloader/GameList.h" +#include "xml/WiiTDB.hpp" CGameTitles GameTitles; @@ -64,3 +67,28 @@ void CGameTitles::SetDefault() //! Free vector memory std::vector().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); + + for(int i = 0; i < gameList.GameCount(); ++i) + { + if(XML_DB.GetTitle((const char *) gameList[i]->id, Title)) + this->SetGameTitle(gameList[i]->id, Title.c_str()); + } +} diff --git a/source/settings/GameTitles.h b/source/settings/GameTitles.h index 5c5b1adb..f27ed95d 100644 --- a/source/settings/GameTitles.h +++ b/source/settings/GameTitles.h @@ -28,6 +28,8 @@ class CGameTitles //! Overload const char * GetTitle(const struct discHdr *header); + //! Load Game Titles from WiiTDB + void LoadTitlesFromWiiTDB(const char * path); //! Set default game titles void SetDefault(); protected: diff --git a/source/settings/menus/GUISettingsMenu.cpp b/source/settings/menus/GUISettingsMenu.cpp index 3d58dd35..e5798f4f 100644 --- a/source/settings/menus/GUISettingsMenu.cpp +++ b/source/settings/menus/GUISettingsMenu.cpp @@ -123,13 +123,7 @@ GuiSettingsMenu::GuiSettingsMenu() GuiSettingsMenu::~GuiSettingsMenu() { if (Settings.titlesOverride != OldTitlesOverride) - { - CloseXMLDatabase(); - GameTitles.SetDefault(); - if(Settings.titlesOverride) - OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride, true); - } - + GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); } void GuiSettingsMenu::SetOptionValues() diff --git a/source/settings/menus/GameLoadSM.cpp b/source/settings/menus/GameLoadSM.cpp index 571cbc86..3570f4af 100644 --- a/source/settings/menus/GameLoadSM.cpp +++ b/source/settings/menus/GameLoadSM.cpp @@ -131,17 +131,17 @@ GameLoadSM::GameLoadSM() GameLoadSM::~GameLoadSM() { - // if partition has changed, Reinitialize it + //! if partition has changed, Reinitialize it if (Settings.partition != OldSettingsPartition) { PartInfo pinfo = partitions.pinfo[Settings.partition]; partitionEntry pentry = partitions.pentry[Settings.partition]; WBFS_OpenPart(pinfo.part_fs, pinfo.index, pentry.sector, pentry.size, (char *) &game_partition); load_from_fs = pinfo.part_fs; - CloseXMLDatabase(); - GameTitles.SetDefault(); - OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride, true); + + //! Reload the new game titles gameList.ReadGameList(); + GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); } } diff --git a/source/themes/Theme_Downloader.cpp b/source/themes/Theme_Downloader.cpp index 11d02c44..ad1a0030 100644 --- a/source/themes/Theme_Downloader.cpp +++ b/source/themes/Theme_Downloader.cpp @@ -28,6 +28,7 @@ /*** Extern variables ***/ extern u8 shutdown; extern u8 reset; +extern int connection; int DownloadTheme(const char *url, const char *title) { @@ -72,7 +73,7 @@ int DownloadTheme(const char *url, const char *title) ShowProgress(tr( "Downloading file" ), 0, (char*) filename, done, filesize, true); - int ret = network_read(buffer, blocksize); + int ret = network_read(connection, buffer, blocksize); if (ret < 0) { free(buffer); diff --git a/source/utils/ShowError.cpp b/source/utils/ShowError.cpp new file mode 100644 index 00000000..ad9c8e09 --- /dev/null +++ b/source/utils/ShowError.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +#include "language/gettext.h" +#include "prompts/PromptWindows.h" + +extern "C" void ShowError(const char * format, ...) +{ + char *tmp=0; + va_list va; + va_start(va, format); + if((vasprintf(&tmp, format, va)>=0) && tmp) + { + WindowPrompt(tr("Error:"), tmp, tr("OK")); + } + va_end(va); + + if(tmp) + free(tmp); +} diff --git a/source/utils/ShowError.h b/source/utils/ShowError.h new file mode 100644 index 00000000..20f64aed --- /dev/null +++ b/source/utils/ShowError.h @@ -0,0 +1,14 @@ +#ifndef SHOWERROR_H_ +#define SHOWERROR_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void ShowError(const char * format, ...); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/xml/WiiTDB.cpp b/source/xml/WiiTDB.cpp new file mode 100644 index 00000000..aa806835 --- /dev/null +++ b/source/xml/WiiTDB.cpp @@ -0,0 +1,998 @@ +/**************************************************************************** + * 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. + ***************************************************************************/ +#include +#include +#include +#include +#include "WiiTDB.hpp" + +#define NAME_OFFSET_DB "wiitdb_offsets.bin" +#define MAXREADSIZE 1024*1024 // Cache size only for parsing the offsets: 1MB + +typedef struct _ReplaceStruct +{ + const char * orig; + char replace; + short size; +} ReplaceStruct; + +//! More replacements can be added if needed +static const ReplaceStruct Replacements[] = +{ + { ">", '>', 4 }, + { "<", '<', 4 }, + { """, '\"', 6 }, + { "'", '\'', 6 }, + { "&", '&', 5 }, + { NULL, '\0', 0 } +}; + +WiiTDB::WiiTDB() + : file(0), LangCode("EN"), GameNodeCache(0) +{ +} + +WiiTDB::WiiTDB(const char * filepath) + : file(0), LangCode("EN"), GameNodeCache(0) +{ + OpenFile(filepath); +} + +WiiTDB::~WiiTDB() +{ + CloseFile(); +} + +bool WiiTDB::OpenFile(const char * filepath) +{ + if(!filepath) + return false; + + file = fopen(filepath, "rb"); + if(file) + { + int pos; + string OffsetsPath = filepath; + if((pos = OffsetsPath.find_last_of('/')) != (int) string::npos) + OffsetsPath[pos] = '\0'; + else + OffsetsPath.clear(); //! Relative path + + LoadGameOffsets(OffsetsPath.c_str()); + } + + return (file != NULL); +} + +void WiiTDB::CloseFile() +{ + OffsetMap.clear(); + vector().swap(OffsetMap); + + if(GameNodeCache) + delete [] GameNodeCache; + GameNodeCache = NULL; + + if(file) + fclose(file); + file = NULL; +} + +bool WiiTDB::LoadGameOffsets(const char * path) +{ + if(!path) + return false; + + string OffsetDBPath = path; + if(strlen(path) > 0 && path[strlen(path)-1] != '/') + OffsetDBPath += '/'; + OffsetDBPath += NAME_OFFSET_DB; + + FILE * fp = fopen(OffsetDBPath.c_str(), "rb"); + if(!fp) + { + bool result = ParseFile(); + if(result) + SaveGameOffsets(OffsetDBPath.c_str()); + + return result; + } + + unsigned long long ExistingVersion = GetWiiTDBVersion(); + unsigned long long Version = 0; + unsigned int NodeCount = 0; + + fread(&Version, 1, sizeof(Version), fp); + + if(ExistingVersion != Version) + { + fclose(fp); + bool result = ParseFile(); + if(result) + SaveGameOffsets(OffsetDBPath.c_str()); + + return result; + } + + fread(&NodeCount, 1, sizeof(NodeCount), fp); + + if(NodeCount == 0) + { + fclose(fp); + bool result = ParseFile(); + if(result) + SaveGameOffsets(OffsetDBPath.c_str()); + + return result; + } + + OffsetMap.resize(NodeCount); + + if(fread(&OffsetMap[0], 1, NodeCount*sizeof(GameOffsets), fp) != NodeCount*sizeof(GameOffsets)) + { + fclose(fp); + bool result = ParseFile(); + if(result) + SaveGameOffsets(OffsetDBPath.c_str()); + + return result; + } + + fclose(fp); + + return true; +} + +bool WiiTDB::SaveGameOffsets(const char * path) +{ + if(OffsetMap.size() == 0 || !path) + return false; + + FILE * fp = fopen(path, "wb"); + if(!fp) + return false; + + unsigned long long ExistingVersion = GetWiiTDBVersion(); + unsigned int NodeCount = OffsetMap.size(); + + if(fwrite(&ExistingVersion, 1, sizeof(ExistingVersion), fp) < 0) + { + fclose(fp); + return false; + } + + if(fwrite(&NodeCount, 1, sizeof(NodeCount), fp) < 0) + { + fclose(fp); + return false; + } + + if(fwrite(&OffsetMap[0], 1, NodeCount*sizeof(GameOffsets), fp) < 0) + { + fclose(fp); + return false; + } + + fclose(fp); + + return true; +} + +unsigned long long WiiTDB::GetWiiTDBVersion() +{ + if(!file) + return 0; + + char TmpText[1024]; + + if(GetData(TmpText, 0, sizeof(TmpText)) < 0) + return 0; + + char * VersionText = GetNodeText(TmpText, ""); + if(!VersionText) + return 0; + + return strtoull(VersionText, NULL, 10); +} + +size_t WiiTDB::GetData(char * data, int offset, int size) +{ + if(!file || !data) + return -1; + + fseek(file, offset, SEEK_SET); + + return fread(data, 1, size, file); +} + +char * WiiTDB::LoadGameNode(const char * id) +{ + unsigned int read = 0; + + GameOffsets * offset = this->GetGameOffset(id); + if(!offset) + return NULL; + + char * data = new (std::nothrow) char[offset->nodesize+1]; + if(!data) + return NULL; + + if((read = GetData(data, offset->gamenode, offset->nodesize)) != offset->nodesize) + { + delete [] data; + return NULL; + } + + data[read] = '\0'; + + return data; +} + +char * WiiTDB::GetGameNode(const char * id) +{ + char * data = NULL; + + if(GameNodeCache != 0 && strncmp(id, GameIDCache, strlen(GameIDCache)) == 0) + { + data = new (std::nothrow) char[strlen(GameNodeCache)+1]; + if(data) + strcpy(data, GameNodeCache); + } + else + { + if(GameNodeCache) + delete [] GameNodeCache; + + GameNodeCache = LoadGameNode(id); + + if(GameNodeCache) + { + snprintf(GameIDCache, sizeof(GameIDCache), id); + data = new (std::nothrow) char[strlen(GameNodeCache)+1]; + if(data) + strcpy(data, GameNodeCache); + } + } + + return data; +} + +GameOffsets * WiiTDB::GetGameOffset(const char * gameID) +{ + for(unsigned int i = 0; i < OffsetMap.size(); ++i) + { + if(strncmp(gameID, OffsetMap[i].gameID, strlen(OffsetMap[i].gameID)) == 0) + return &OffsetMap[i]; + } + + return 0; +} + +static inline char * CleanText(char * in_text) +{ + if(!in_text) + return NULL; + + const char * ptr = in_text; + char * text = in_text; + + while(*ptr != '\0') + { + for(int i = 0; Replacements[i].orig != 0; ++i) + { + if(strncmp(ptr, Replacements[i].orig, Replacements[i].size) == 0) + { + ptr += Replacements[i].size; + *text = Replacements[i].replace; + ++text; + i = 0; + continue; + } + } + + if(*ptr == '\r') + { + ++ptr; + continue; + } + + *text = *ptr; + ++ptr; + ++text; + } + + *text = '\0'; + + return in_text; +} + +char * WiiTDB::GetNodeText(char * data, const char * nodestart, const char * nodeend) +{ + if(!data || !nodestart || !nodeend) + return NULL; + + char * position = strstr(data, nodestart); + if(!position) + return NULL; + + position += strlen(nodestart); + + char * end = strstr(position, nodeend); + if(!end) + return NULL; + + *end = '\0'; + + return CleanText(position); +} + +char * WiiTDB::SeekLang(char * text, const char * langcode) +{ + if(!text || !langcode) return NULL; + + char * ptr = text; + while((ptr = strstr(ptr, ""); + if(!end) + return NULL; + + end += strlen(""); + *end = '\0'; + + return ptr; + } + } + + return NULL; +} + +bool WiiTDB::ParseFile() +{ + OffsetMap.clear(); + + if(!file) + return false; + + char * Line = new (std::nothrow) char[MAXREADSIZE+1]; + if(!Line) + return false; + + bool readnew = false; + int i, currentPos = 0; + int read = 0; + const char * gameNode = NULL; + const char * idNode = NULL; + const char * gameEndNode = NULL; + + while((read = GetData(Line, currentPos, MAXREADSIZE)) > 0) + { + gameNode = Line; + readnew = false; + + //! Ensure the null termination at the end + Line[read] = '\0'; + + while((gameNode = strstr(gameNode, ""); + gameEndNode = strstr(gameNode, ""); + if(!idNode || !gameEndNode) + { + //! We are in the middle of the game node, reread complete node and more + currentPos += (gameNode-Line); + fseek(file, currentPos, SEEK_SET); + readnew = true; + break; + } + + idNode += strlen(""); + gameEndNode += strlen(""); + + int size = OffsetMap.size(); + OffsetMap.resize(size+1); + + for(i = 0; i < 7 && *idNode != '<'; ++i, ++idNode) + OffsetMap[size].gameID[i] = *idNode; + OffsetMap[size].gameID[i] = '\0'; + OffsetMap[size].gamenode = currentPos+(gameNode-Line); + OffsetMap[size].nodesize = (gameEndNode-gameNode); + gameNode = gameEndNode; + } + + if(readnew) + continue; + + currentPos += read; + } + + delete [] Line; + + return true; +} + +bool WiiTDB::GetTitle(const char * id, string & title) +{ + if(!id) + return false; + + char * data = GetGameNode(id); + if(!data) + return false; + + char * language = SeekLang(data, LangCode.c_str()); + if(!language) + { + language = SeekLang(data, "EN"); + if(!language) + { + delete [] data; + return false; + } + } + + char * the_title = GetNodeText(language, "", ""); + if(!the_title) + { + delete [] data; + return false; + } + + title = the_title; + + delete [] data; + + return true; +} + +bool WiiTDB::GetSynopsis(const char * id, string & synopsis) +{ + if(!id) + return false; + + char * data = GetGameNode(id); + if(!data) + return false; + + char * language = SeekLang(data, LangCode.c_str()); + if(!language) + { + language = SeekLang(data, "EN"); + if(!language) + { + delete [] data; + return false; + } + } + + char * the_synopsis = GetNodeText(language, "", ""); + if(!the_synopsis) + { + delete [] data; + return false; + } + + synopsis = the_synopsis; + + delete [] data; + + return true; +} + +bool WiiTDB::GetRegion(const char * id, string & region) +{ + if(!id) + return false; + + char * data = GetGameNode(id); + if(!data) + return false; + + char * the_region = GetNodeText(data, "", ""); + if(!the_region) + { + delete [] data; + return false; + } + + region = the_region; + + delete [] data; + + return true; +} + +bool WiiTDB::GetDeveloper(const char * id, string & dev) +{ + if(!id) + return false; + + char * data = GetGameNode(id); + if(!data) + return false; + + char * the_dev = GetNodeText(data, "", ""); + if(!the_dev) + { + delete [] data; + return false; + } + + dev = the_dev; + + delete [] data; + + return true; +} + +bool WiiTDB::GetPublisher(const char * id, string & pub) +{ + if(!id) + return false; + + char * data = GetGameNode(id); + if(!data) + return false; + + char * the_pub = GetNodeText(data, "", ""); + if(!the_pub) + { + delete [] data; + return false; + } + + pub = the_pub; + + delete [] data; + + return true; +} + +unsigned int WiiTDB::GetPublishDate(const char * id) +{ + if(!id) + return 0; + + char * data = GetGameNode(id); + if(!data) + return 0; + + char * year_string = GetNodeText(data, ""); + if(!year_string) + { + delete [] data; + return 0; + } + + unsigned int year, day, month; + + year = atoi(year_string); + + char * month_string = strstr(year_string, "month=\""); + if(!month_string) + { + delete [] data; + return 0; + } + + month_string += strlen("month=\""); + + month = atoi(month_string); + + char * day_string = strstr(month_string, "day=\""); + if(!day_string) + { + delete [] data; + return 0; + } + + day_string += strlen("day=\""); + + day = atoi(day_string); + + delete [] data; + + return ((year & 0xFFFF) << 16 | (month & 0xFF) << 8 | (day & 0xFF)); +} + +bool WiiTDB::GetGenreList(const char * id, vector & genre) +{ + if(!id) + return false; + + char * data = GetGameNode(id); + if(!data) + return false; + + char * the_genre = GetNodeText(data, "", ""); + if(!the_genre) + { + delete [] data; + return false; + } + + unsigned int genre_num = 0; + const char * ptr = the_genre; + + while(*ptr != '\0') + { + if(genre_num >= genre.size()) + genre.resize(genre_num+1); + + if(*ptr == ',' || *ptr == '/' || *ptr == ';') + { + ptr++; + while(*ptr == ' ') ptr++; + genre[genre_num].push_back('\0'); + genre_num++; + continue; + } + + if(genre[genre_num].size() == 0) + genre[genre_num].push_back(toupper((int)*ptr)); + else + genre[genre_num].push_back(*ptr); + + ++ptr; + } + genre[genre_num].push_back('\0'); + + delete [] data; + + return true; +} + +const char * WiiTDB::RatingToString(int rating) +{ + switch(rating) + { + case 0: + return "CERO"; + case 1: + return "ESRB"; + case 2: + return "PEGI"; + default: + break; + } + + return NULL; +} + +int WiiTDB::GetRating(const char * id) +{ + int rating = -1; + + if(!id) + return rating; + + char * data = GetGameNode(id); + if(!data) + return rating; + + char * rating_text = GetNodeText(data, ""); + if(!rating_text) + { + delete [] data; + return rating; + } + + if(strncmp(rating_text, "CERO", 4) == 0) + rating = 0; + + else if(strncmp(rating_text, "ESRB", 4) == 0) + rating = 1; + + else if(strncmp(rating_text, "PEGI", 4) == 0) + rating = 2; + + delete [] data; + + return rating; +} + +bool WiiTDB::GetRatingValue(const char * id, string & rating_value) +{ + if(!id) + return false; + + char * data = GetGameNode(id); + if(!data) + return false; + + char * rating_text = GetNodeText(data, ""); + if(!rating_text) + { + delete [] data; + return false; + } + + char * value_text = GetNodeText(rating_text, "value=\"", "\""); + if(!value_text) + { + delete [] data; + return false; + } + + rating_value = value_text; + + delete [] data; + + return true; +} + +int WiiTDB::GetRatingDescriptorList(const char * id, vector & desc_list) +{ + if(!id) + return -1; + + char * data = GetGameNode(id); + if(!data) + return -1; + + char * descriptor_text = GetNodeText(data, "", ""); + if(!descriptor_text) + { + delete [] data; + return -1; + } + + unsigned int list_num = 0; + desc_list.clear(); + + while(*descriptor_text != '\0') + { + if(strncmp(descriptor_text, "", strlen("")) == 0) + { + desc_list[list_num].push_back('\0'); + descriptor_text = strstr(descriptor_text, ""); + if(!descriptor_text) + break; + + descriptor_text += strlen(""); + list_num++; + } + + if(list_num >= desc_list.size()) + desc_list.resize(list_num+1); + + desc_list[list_num].push_back(*descriptor_text); + ++descriptor_text; + } + + delete [] data; + + return desc_list.size(); +} + +int WiiTDB::GetWifiPlayers(const char * id) +{ + int players = -1; + + if(!id) + return players; + + char * data = GetGameNode(id); + if(!data) + return players; + + char * PlayersNode = GetNodeText(data, ""); + if(!PlayersNode) + { + delete [] data; + return players; + } + + players = atoi(PlayersNode); + + return players; +} + +int WiiTDB::GetWifiFeatureList(const char * id, vector & feat_list) +{ + if(!id) + return -1; + + char * data = GetGameNode(id); + if(!data) + return -1; + + char * feature_text = GetNodeText(data, "", ""); + if(!feature_text) + { + delete [] data; + return -1; + } + + unsigned int list_num = 0; + feat_list.clear(); + + while(*feature_text != '\0') + { + if(strncmp(feature_text, "", strlen("")) == 0) + { + feat_list[list_num].push_back('\0'); + feature_text = strstr(feature_text, ""); + if(!feature_text) + break; + + feature_text += strlen(""); + list_num++; + } + + if(list_num >= feat_list.size()) + feat_list.resize(list_num+1); + + + if(feat_list[list_num].size() == 0) + feat_list[list_num].push_back(toupper((int)*feature_text)); + else + feat_list[list_num].push_back(*feature_text); + + ++feature_text; + } + + delete [] data; + + return feat_list.size(); +} + +int WiiTDB::GetPlayers(const char * id) +{ + int players = -1; + + if(!id) + return players; + + char * data = GetGameNode(id); + if(!data) + return players; + + char * PlayersNode = GetNodeText(data, ""); + if(!PlayersNode) + { + delete [] data; + return players; + } + + players = atoi(PlayersNode); + + return players; +} + +int WiiTDB::GetAccessoirList(const char * id, vector & acc_list) +{ + if(!id) + return -1; + + char * data = GetGameNode(id); + if(!data) + return -1; + + char * ControlsNode = GetNodeText(data, ""); + if(!ControlsNode) + { + delete [] data; + return -1; + } + + unsigned int list_num = 0; + acc_list.clear(); + + while(ControlsNode && *ControlsNode != '\0') + { + if(list_num >= acc_list.size()) + acc_list.resize(list_num+1); + + for(const char * ptr = ControlsNode; *ptr != '"' && *ptr != '\0'; ptr++) + { + acc_list[list_num].Name.push_back(*ptr); + } + acc_list[list_num].Name.push_back('\0'); + + char * requiredField = strstr(ControlsNode, "required=\""); + if(!requiredField) + { + delete [] data; + return -1; + } + + requiredField += strlen("required=\""); + + if(strncmp(requiredField, "true", 4) == 0) + { + acc_list[list_num].Required = true; + } + else + { + acc_list[list_num].Required = false; + } + + ControlsNode = strstr(requiredField, ""); + if(!ColorNode) + { + delete [] data; + return color; + } + + color = strtoul(ColorNode, NULL, 16); + + return color; +} + +bool WiiTDB::GetGameXMLInfo(const char * id, GameXMLInfo * gameInfo) +{ + if(!id || !gameInfo) + return false; + + for(int i = 0; i < 6 && id[i] != 0; ++i) + gameInfo->GameID.push_back(id[i]); + gameInfo->GameID.push_back('\0'); + + GetTitle(id, gameInfo->Title); + GetSynopsis(id, gameInfo->Synopsis); + GetRegion(id, gameInfo->Region); + GetDeveloper(id, gameInfo->Developer); + GetPublisher(id, gameInfo->Publisher); + gameInfo->PublishDate = GetPublishDate(id); + GetGenreList(id, gameInfo->GenreList); + gameInfo->RatingType = GetRating(id); + GetRatingValue(id, gameInfo->RatingValue); + GetRatingDescriptorList(id, gameInfo->RatingDescriptorList); + gameInfo->WifiPlayers = GetWifiPlayers(id); + GetWifiFeatureList(id, gameInfo->WifiFeatureList); + gameInfo->Players = GetPlayers(id); + GetAccessoirList(id, gameInfo->AccessoirList); + gameInfo->CaseColor = GetCaseColor(id); + + return true; +} diff --git a/source/xml/WiiTDB.hpp b/source/xml/WiiTDB.hpp new file mode 100644 index 00000000..7b2a0f74 --- /dev/null +++ b/source/xml/WiiTDB.hpp @@ -0,0 +1,150 @@ +/**************************************************************************** + * 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. + ***************************************************************************/ +#ifndef WIITDB_HPP_ +#define WIITDB_HPP_ + +#include +#include + +using namespace std; + +typedef struct _Accessoir +{ + string Name; + bool Required; +} Accessoir; + +typedef struct _GameXMLInfo +{ + string GameID; + string Region; + string Title; + string Synopsis; + string Developer; + string Publisher; + unsigned int PublishDate; + vector GenreList; + int RatingType; + string RatingValue; + vector RatingDescriptorList; + int WifiPlayers; + vector WifiFeatureList; + int Players; + vector AccessoirList; + long CaseColor; + +} GameXMLInfo; + +typedef struct _GameOffsets +{ + char gameID[7]; + unsigned int gamenode; + unsigned int nodesize; +} __attribute__((__packed__)) GameOffsets; + +class WiiTDB +{ + public: + //! Constructor + WiiTDB(); + //! Constructor + //! If filepath is passed the xml file is opened and the node offsets are loaded + WiiTDB(const char * filepath); + //! Destructor + ~WiiTDB(); + //! If filepath is passed the xml file is opened and the node offsets are loaded + bool OpenFile(const char * filepath); + //! Closes the WiiTDB xml file + void CloseFile(); + //! Set the language code which should be use to find the appropriate language + //! If the language code is not found, the language code defaults to EN + void SetLanguageCode(const char * code) { if(code) LangCode = code; }; + //! Get the current set language code + const char * GetLanguageCode() { return LangCode.c_str(); }; + //! Get the title of a specific game id in the language defined in LangCode + bool GetTitle(const char * id, string & title); + //! Get the synopsis of a specific game id in the language defined in LangCode + bool GetSynopsis(const char * id, string & synopsis); + //! Get the region of a game for a specific game id + bool GetRegion(const char * id, string & region); + //! Get the developer of a game for a specific game id + bool GetDeveloper(const char * id, string & dev); + //! Get the publisher of a game for a specific game id + bool GetPublisher(const char * id, string & pub); + //! Get the publish date of a game for a specific game id + //! First 1 byte is the day, than 1 byte month and last 2 bytes is the year + //! year = (return >> 16), month = (return >> 8) & 0xFF, day = return & 0xFF + unsigned int GetPublishDate(const char * id); + //! Get the genre list of a game for a specific game id + bool GetGenreList(const char * id, vector & genre); + //! Get the rating type for a specific game id + //! The rating type can be converted to a string with WiiTDB::RatingToString(rating) + int GetRating(const char * id); + //! Get the rating value for a specific game id + bool GetRatingValue(const char * id, string & rating_value); + //! Get the rating descriptor list inside a vector for a specific game id + //! Returns the amount of descriptors found or -1 if failed + int GetRatingDescriptorList(const char * id, vector & desc_list); + //! Get the wifi player count for a specific game id + //! Returns the amount of wifi players or -1 if failed + int GetWifiPlayers(const char * id); + //! Get the wifi feature list inside a vector for a specific game id + //! Returns the amount of wifi features found or -1 if failed + int GetWifiFeatureList(const char * id, vector & feat_list); + //! Get the player count for a specific game id + //! Returns the amount of players or -1 if failed + int GetPlayers(const char * id); + //! Returns the amount of accessoirs found or -1 if failed + //! Get the accessoir (inputs) list inside a vector for a specific game id + int GetAccessoirList(const char * id, vector & acc_list); + //! Get the box (case) color for a specific game id + //! Returns the color in RGB (first 3 bytes) + int GetCaseColor(const char * id); + //! Get the complete game info in the GameXMLInfo struct + bool GetGameXMLInfo(const char * id, GameXMLInfo * gameInfo); + //! Convert a specific game rating to a string + static const char * RatingToString(int rating); + //! Get the version of the wiitdb xml database + unsigned long long GetWiiTDBVersion(); + //! Get the entry count in the xml database + inline size_t GetEntryCount() { return OffsetMap.size(); }; + private: + bool ParseFile(); + bool LoadGameOffsets(const char * path); + bool SaveGameOffsets(const char * path); + inline size_t GetData(char * data, int offset, int size); + inline char * LoadGameNode(const char * id); + inline char * GetGameNode(const char * id); + inline GameOffsets * GetGameOffset(const char * id); + inline char * SeekLang(char * text, const char * langcode); + inline char * GetNodeText(char * data, const char * nodestart, const char * nodeend); + + vector OffsetMap; + FILE * file; + string LangCode; + char * GameNodeCache; + char GameIDCache[7]; +}; + +#endif