2012-01-21 21:57:41 +01:00
|
|
|
/****************************************************************************
|
2012-07-27 19:26:49 +02:00
|
|
|
* Copyright (C) 2010
|
|
|
|
* by Dimok
|
2012-01-21 21:57:41 +01:00
|
|
|
*
|
2012-07-27 19:26:49 +02:00
|
|
|
* 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.
|
2012-01-21 21:57:41 +01:00
|
|
|
*
|
2012-07-27 19:26:49 +02:00
|
|
|
* 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:
|
2012-01-21 21:57:41 +01:00
|
|
|
*
|
2012-07-27 19:26:49 +02:00
|
|
|
* 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.
|
2012-01-21 21:57:41 +01:00
|
|
|
*
|
2012-07-27 19:26:49 +02:00
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
2012-01-21 21:57:41 +01:00
|
|
|
*
|
2012-07-27 19:26:49 +02:00
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
2012-01-21 21:57:41 +01:00
|
|
|
***************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
|
|
|
#include <cstring>
|
|
|
|
#include "GameTDB.hpp"
|
|
|
|
#include "video.hpp"
|
2012-02-13 01:22:56 +01:00
|
|
|
#include "text.hpp"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "config/config.hpp"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-11-04 00:38:39 +01:00
|
|
|
#include "memory/mem2.hpp"
|
2018-12-30 23:00:51 +01:00
|
|
|
#include "types.h"
|
|
|
|
#include "gui/coverflow.hpp"
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
#define NAME_OFFSET_DB "gametdb_offsets.bin"
|
|
|
|
#define MAXREADSIZE 1024*1024 //Cache size only for parsing the offsets: 1MB
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
typedef struct _ReplaceStruct
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
const char *orig;
|
|
|
|
char replace;
|
|
|
|
short size;
|
2012-01-21 21:57:41 +01:00
|
|
|
} ReplaceStruct;
|
|
|
|
|
|
|
|
//! More replacements can be added if needed
|
|
|
|
static const ReplaceStruct Replacements[] =
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
{ ">", '>', 4 },
|
|
|
|
{ "<", '<', 4 },
|
|
|
|
{ """, '\"', 6 },
|
|
|
|
{ "'", '\'', 6 },
|
|
|
|
{ "&", '&', 5 },
|
|
|
|
{ NULL, '\0', 0 }
|
2012-01-21 21:57:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
GameTDB::GameTDB()
|
2012-11-04 00:38:39 +01:00
|
|
|
: isLoaded(false), isParsed(false), file(0), filepath(0), LangCode("EN"), GameNodeCache(NULL)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
GameTDB::GameTDB(const char *filepath)
|
2012-11-04 00:38:39 +01:00
|
|
|
: isLoaded(false), isParsed(false), file(0), filepath(0), LangCode("EN"), GameNodeCache(NULL)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
OpenFile(filepath);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GameTDB::~GameTDB()
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
CloseFile();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
bool GameTDB::OpenFile(const char *filepath)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!filepath)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-10-02 21:26:50 +02:00
|
|
|
//gprintf("Trying to open '%s'...", filepath);
|
2012-07-26 00:12:17 +02:00
|
|
|
file = fopen(filepath, "rb");
|
|
|
|
if(file)
|
|
|
|
{
|
2012-01-21 21:57:41 +01:00
|
|
|
this->filepath = filepath;
|
2012-07-26 00:12:17 +02:00
|
|
|
|
2012-10-02 21:26:50 +02:00
|
|
|
//gprintf("success\n");
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int pos;
|
|
|
|
string OffsetsPath = filepath;
|
|
|
|
if((pos = OffsetsPath.find_last_of('/')) != (int) string::npos)
|
|
|
|
OffsetsPath[pos] = '\0';
|
|
|
|
else
|
|
|
|
OffsetsPath.clear(); //! Relative path
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-10-02 21:26:50 +02:00
|
|
|
//gprintf("Checking game offsets\n");
|
2012-07-26 00:12:17 +02:00
|
|
|
LoadGameOffsets(OffsetsPath.c_str());
|
2012-01-21 21:57:41 +01:00
|
|
|
/*if (!isParsed)
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
gprintf("Checking titles.ini\n");
|
|
|
|
CheckTitlesIni(OffsetsPath.c_str());
|
2012-01-21 21:57:41 +01:00
|
|
|
}*/
|
2012-07-26 00:12:17 +02:00
|
|
|
}
|
2012-10-02 21:26:50 +02:00
|
|
|
//else gprintf("failed\n");
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
isLoaded = (file != NULL);
|
2012-01-21 21:57:41 +01:00
|
|
|
return isLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameTDB::CloseFile()
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
OffsetMap.clear();
|
-updating wiiflow lite to beta 4.3.0
-fixed using categories to hide GC disc 2's. Apparently this has never really worked right for some time or ever.
-fixed deleting the cached cover texture file for plugin games. Delete cover for plugins only deletes the cached texture file (.wfc)
-fixed favorites and adultonly (parental lock) for plugin games. Apparently I may have broke this a few revisions back.
-favorites and adultonly for plugin games now have their own domains in gamecfg1- [FAVORITES_PLUGINS] and [ADULTONLY_PLUGINS]. just makes it more organized.
-only wii, GC, channels are added to [PLAYCOUNT] and [LAST_PLAYED] in gamecfg1.
-now loading gamecfg1 at startup and leaving it loaded till exit. no more loading it and unloading all the time.
-fixed scrolling for game_info synopsis, credits, and help text.
-made source menu buttons wider for wiiflow default. old 80x80, now 100x80. looks better.
-display music info now defaults to off
-screensaver_disabled now defaults to yes
-show GC view button is now on by default no matter what. the only way it is disabled is if you edit wiiflow.ini manually. this is how all the view buttons work.
-removed hiding homebrew button but if wiiflow locked it won't work or in sourceflow it won't show.
-dump_list is now under [GENERAL] instead of each view. Also only works for Wii, GC, and channels.
-sorting only works for Wii, GC, and Channels now. disabled for sourceflow, plugins, homebrew, and combined view.
-now if no games are found a message is shown with the current path so you can see where wiiflow is looking. (except for plugins)
-removed auto create emuNAND for emuNAND view if gamelist is empty. just go to settings>NAND settings if you want to extract or disable it.
-now when no games are found all buttons at bottom are still accessible allowing you to change the view or go to settings and change current partition or path and even extract your NAND to create a EmuNAND. Or go to Home Menu and Install a Wii or GC game.
-removed auto extract NAND to emuNAND when launching a Wii game with EmuNAND save. Now a message is diplayed saying 'emuNAND for saves not found - using real NAND'.
-made the speed at which cover titles fade in/out almost instantly.
-removed update button from Home Menu. online update code is still there but not used and probably won't be used any more as there just isn't a need for it now.
-removed ftp button from Home Menu and all code for the FTP server. I just use WiiXplorer's FTP server. it seems to work better for me.
-disabled keep USB Alive thread for now. i think there's a possibilty it might be the cause of my SD/USB files getting corrupted.
-removed Btn B and - combo to switch partitions. didn't seem useful anymore.
-redid nand emulation settings menu. looks like this now:
pg1
Select EmuNAND
EmuNAND Enulation
Select SaveNAND
SaveNAND Emulation
pg2
Extract Saves All
Missing
Extract NAND
Select Saves Partition
-no longer blocking Select Plugin menu and View icons when using source menu combined view
-now Select Plugins Menu is like switching to plugin view but you get to choose the plugins first
-now [PLUGIN] partition= is the default partition for all plugins. to change individual plugins add 'romPartition=x' to the plugin ini. x is the partition number 0 thru 8 with SD being 0. this is how my usbloadergx plugin mod works.
2016-10-05 01:44:13 +02:00
|
|
|
vector<GameOffsets>().swap(OffsetMap);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(GameNodeCache)
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(GameNodeCache);
|
2012-07-26 00:12:17 +02:00
|
|
|
GameNodeCache = NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(file)
|
|
|
|
fclose(file);
|
|
|
|
file = NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameTDB::Refresh()
|
|
|
|
{
|
|
|
|
gprintf("Refreshing file '%s'\n", filepath);
|
|
|
|
CloseFile();
|
2012-07-26 00:12:17 +02:00
|
|
|
|
|
|
|
if(filepath == NULL)
|
2012-01-21 21:57:41 +01:00
|
|
|
return;
|
2012-07-26 00:12:17 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
OpenFile(filepath);
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
bool GameTDB::LoadGameOffsets(const char *path)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!path)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
string OffsetDBPath = path;
|
|
|
|
if(strlen(path) > 0 && path[strlen(path)-1] != '/')
|
|
|
|
OffsetDBPath += '/';
|
|
|
|
OffsetDBPath += NAME_OFFSET_DB;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
FILE *fp = fopen(OffsetDBPath.c_str(), "rb");
|
|
|
|
if(!fp)
|
|
|
|
{
|
|
|
|
bool result = ParseFile();
|
|
|
|
if(result)
|
|
|
|
SaveGameOffsets(OffsetDBPath.c_str());
|
|
|
|
return result;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
u64 ExistingVersion = GetGameTDBVersion();
|
|
|
|
u64 Version = 0;
|
|
|
|
u32 NodeCount = 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
fread(&Version, 1, sizeof(Version), fp);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(ExistingVersion != Version)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
fclose(fp);
|
|
|
|
bool result = ParseFile();
|
|
|
|
if(result)
|
|
|
|
SaveGameOffsets(OffsetDBPath.c_str());
|
|
|
|
return result;
|
2012-07-26 00:12:17 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
fread(&NodeCount, 1, sizeof(NodeCount), fp);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(NodeCount == 0)
|
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
bool result = ParseFile();
|
|
|
|
if(result)
|
|
|
|
SaveGameOffsets(OffsetDBPath.c_str());
|
|
|
|
return result;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
OffsetMap.resize(NodeCount);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
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;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
fclose(fp);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
bool GameTDB::SaveGameOffsets(const char *path)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(OffsetMap.size() == 0 || !path)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
FILE *fp = fopen(path, "wb");
|
|
|
|
if(!fp)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u64 ExistingVersion = GetGameTDBVersion();
|
|
|
|
u32 NodeCount = OffsetMap.size();
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(fwrite(&ExistingVersion, 1, sizeof(ExistingVersion), fp) != sizeof(ExistingVersion))
|
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(fwrite(&NodeCount, 1, sizeof(NodeCount), fp) != sizeof(NodeCount))
|
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(fwrite(&OffsetMap[0], 1, NodeCount*sizeof(GameOffsets), fp) != NodeCount*sizeof(GameOffsets))
|
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
fclose(fp);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u64 GameTDB::GetGameTDBVersion()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!file)
|
|
|
|
return 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char TmpText[1024];
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(GetData(TmpText, 0, sizeof(TmpText)) < 0)
|
|
|
|
return 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *VersionText = GetNodeText(TmpText, "<GameTDB version=\"", "/>");
|
|
|
|
if(!VersionText)
|
|
|
|
return 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return strtoull(VersionText, NULL, 10);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetData(char *data, int offset, int size)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!file || !data)
|
|
|
|
return -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
fseek(file, offset, SEEK_SET);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return fread(data, 1, size, file);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *GameTDB::LoadGameNode(const char *id)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 read = 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
GameOffsets *offset = this->GetGameOffset(id);
|
|
|
|
if(!offset)
|
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
char *data = (char*)MEM2_alloc(offset->nodesize+1);
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!data)
|
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if((read = GetData(data, offset->gamenode, offset->nodesize)) != offset->nodesize)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
data[read] = '\0';
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return data;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *GameTDB::GetGameNode(const char *id)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = NULL;
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(GameNodeCache != NULL && strncmp(id, GameIDCache, strlen(GameIDCache)) == 0)
|
2012-07-26 00:12:17 +02:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
data = (char*)MEM2_alloc(strlen(GameNodeCache)+1);
|
2012-07-26 00:12:17 +02:00
|
|
|
if(data)
|
|
|
|
strcpy(data, GameNodeCache);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(GameNodeCache)
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(GameNodeCache);
|
2012-07-26 00:12:17 +02:00
|
|
|
GameNodeCache = LoadGameNode(id);
|
|
|
|
if(GameNodeCache)
|
|
|
|
{
|
|
|
|
snprintf(GameIDCache, sizeof(GameIDCache), id);
|
2012-11-04 00:38:39 +01:00
|
|
|
data = (char*)MEM2_alloc(strlen(GameNodeCache)+1);
|
2012-07-26 00:12:17 +02:00
|
|
|
if(data)
|
|
|
|
strcpy(data, GameNodeCache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
GameOffsets *GameTDB::GetGameOffset(const char *gameID)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
for(u32 i = 0; i < OffsetMap.size(); ++i)
|
|
|
|
{
|
|
|
|
if(strncmp(gameID, OffsetMap[i].gameID, strlen(OffsetMap[i].gameID)) == 0)
|
|
|
|
return &OffsetMap[i];
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
static inline char *CleanText(char * &in_text)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
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;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *GameTDB::GetNodeText(char *data, const char *nodestart, const char *nodeend)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!data || !nodestart || !nodeend)
|
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *position = strstr(data, nodestart);
|
|
|
|
if(!position)
|
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
position += strlen(nodestart);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *end = strstr(position, nodeend);
|
|
|
|
if(!end)
|
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
*end = '\0';
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return CleanText(position);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *GameTDB::SeekLang(char *text, const char *langcode)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!text || !langcode)
|
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *ptr = text;
|
|
|
|
while((ptr = strstr(ptr, "<locale lang=")) != NULL)
|
|
|
|
{
|
|
|
|
ptr += strlen("<locale lang=\"");
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(strncmp(ptr, langcode, strlen(langcode)) == 0)
|
|
|
|
{
|
|
|
|
//! Cut off all the other languages
|
|
|
|
char *end = strstr(ptr, "</locale>");
|
|
|
|
if(!end)
|
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
end += strlen("</locale>");
|
|
|
|
*end = '\0';
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return NULL;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GameTDB::ParseFile()
|
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
OffsetMap.clear();
|
|
|
|
|
|
|
|
if(!file)
|
|
|
|
return false;
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
char *Line = (char*)MEM2_alloc(MAXREADSIZE+1);
|
2012-07-26 00:12:17 +02:00
|
|
|
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, "<game name=\"")) != NULL)
|
|
|
|
{
|
|
|
|
idNode = strstr(gameNode, "<id>");
|
|
|
|
gameEndNode = strstr(gameNode, "</game>");
|
|
|
|
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("<id>");
|
|
|
|
gameEndNode += strlen("</game>");
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(Line);
|
2012-07-26 00:12:17 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::FindTitle(char *data, const char * &title, const string &langCode)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2019-01-14 17:28:31 +01:00
|
|
|
// Coverflow.getHdr() will return NULL if coverflow list is empty or not made yet
|
|
|
|
// because list generator hasn't made the game list yet.
|
|
|
|
if(CoverFlow.getHdr() != NULL && CoverFlow.getHdr()->type == TYPE_PLUGIN)
|
2018-12-30 23:00:51 +01:00
|
|
|
{
|
|
|
|
title = GetNodeText(data, "<title>", "</title>");
|
|
|
|
|
|
|
|
if(title == NULL)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *language = SeekLang(data, langCode.c_str());
|
2012-11-04 00:38:39 +01:00
|
|
|
if(language == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
{
|
|
|
|
language = SeekLang(data, "EN");
|
2012-11-04 00:38:39 +01:00
|
|
|
if(language == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-12-30 23:00:51 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
title = GetNodeText(language, "<title>", "</title>");
|
2012-07-26 00:12:17 +02:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(title == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::GetTitle(const char *id, const char * &title)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
title = NULL;
|
|
|
|
if(id == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
2012-11-04 00:38:39 +01:00
|
|
|
if(data == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
bool retval = FindTitle(data, title, LangCode);
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return retval;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-30 23:00:51 +01:00
|
|
|
bool GameTDB::GetName(const char *id, const char * &name)
|
|
|
|
{
|
|
|
|
name = NULL;
|
|
|
|
if(!id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
name = GetNodeText(data, "<game name=\"", "\"");
|
|
|
|
MEM2_free(data);
|
|
|
|
|
|
|
|
if(name == NULL)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::GetSynopsis(const char *id, const char * &synopsis)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
synopsis = NULL;
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char *language = SeekLang(data, LangCode.c_str());
|
2012-11-04 00:38:39 +01:00
|
|
|
if(language == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
{
|
|
|
|
language = SeekLang(data, "EN");
|
2012-11-04 00:38:39 +01:00
|
|
|
if(language == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-11-04 00:38:39 +01:00
|
|
|
synopsis = GetNodeText(language, "<synopsis>", "</synopsis>");
|
2018-12-30 23:00:51 +01:00
|
|
|
|
|
|
|
if(CoverFlow.getHdr()->type == TYPE_PLUGIN)
|
|
|
|
{
|
|
|
|
// Default to English
|
|
|
|
if(synopsis == NULL)
|
|
|
|
{
|
|
|
|
language = SeekLang(data, "EN");
|
|
|
|
if(language == NULL)
|
|
|
|
{
|
|
|
|
MEM2_free(data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
synopsis = GetNodeText(language, "<synopsis>", "</synopsis>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(synopsis == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::GetRegion(const char *id, const char * ®ion)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
region = NULL;
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return false;
|
2012-11-04 00:38:39 +01:00
|
|
|
region = GetNodeText(data, "<region>", "</region>");
|
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(region == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::GetDeveloper(const char *id, const char * &dev)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
dev = NULL;
|
|
|
|
if(id == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
2012-11-04 00:38:39 +01:00
|
|
|
if(data == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
dev = GetNodeText(data, "<developer>", "</developer>");
|
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(dev == NULL)
|
|
|
|
return false;
|
2012-07-26 00:12:17 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::GetPublisher(const char *id, const char * &pub)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
pub = NULL;
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
2012-11-04 00:38:39 +01:00
|
|
|
if(data == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
pub = GetNodeText(data, "<publisher>", "</publisher>");
|
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(pub == NULL)
|
|
|
|
return false;
|
2012-07-26 00:12:17 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 GameTDB::GetPublishDate(const char *id)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *year_string = GetNodeText(data, "<date year=\"", "/>");
|
|
|
|
if(!year_string)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 year, day, month;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
year = atoi(year_string);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *month_string = strstr(year_string, "month=\"");
|
|
|
|
if(!month_string)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
month_string += strlen("month=\"");
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
month = atoi(month_string);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *day_string = strstr(month_string, "day=\"");
|
|
|
|
if(!day_string)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
day_string += strlen("day=\"");
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
day = atoi(day_string);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return ((year & 0xFFFF) << 16 | (month & 0xFF) << 8 | (day & 0xFF));
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::GetGenres(const char *id, const char * &gen)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
gen = NULL;
|
2012-02-13 01:22:56 +01:00
|
|
|
|
2018-12-30 23:00:51 +01:00
|
|
|
if(CoverFlow.getHdr()->type == TYPE_PLUGIN)
|
|
|
|
{
|
|
|
|
if(!id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char *language = SeekLang(data, LangCode.c_str());
|
|
|
|
if(language == NULL)
|
|
|
|
{
|
|
|
|
language = SeekLang(data, "EN");
|
|
|
|
if(language == NULL)
|
|
|
|
{
|
|
|
|
MEM2_free(data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gen = GetNodeText(language, "<genre>", "</genre>");
|
|
|
|
|
|
|
|
// If not found try in English
|
|
|
|
if(gen == NULL)
|
|
|
|
{
|
|
|
|
language = SeekLang(data, "EN");
|
|
|
|
if(language == NULL)
|
|
|
|
{
|
|
|
|
MEM2_free(data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gen = GetNodeText(language, "<genre>", "</genre>");
|
|
|
|
}
|
|
|
|
MEM2_free(data);
|
|
|
|
|
|
|
|
if(gen == NULL)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(id == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
2012-11-04 00:38:39 +01:00
|
|
|
if(data == NULL)
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
gen = GetNodeText(data, "<genre>", "</genre>");
|
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(gen == NULL)
|
|
|
|
return false;
|
2012-07-26 00:12:17 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
const char *GameTDB::RatingToString(int rating)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
switch(rating)
|
|
|
|
{
|
|
|
|
case GAMETDB_RATING_TYPE_CERO:
|
|
|
|
return "CERO";
|
|
|
|
case GAMETDB_RATING_TYPE_ESRB:
|
|
|
|
return "ESRB";
|
|
|
|
case GAMETDB_RATING_TYPE_PEGI:
|
|
|
|
return "PEGI";
|
|
|
|
case GAMETDB_RATING_TYPE_GRB:
|
|
|
|
return "GRB";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetRating(const char *id)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
int rating = -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return rating;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return rating;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *rating_text = GetNodeText(data, "<rating type=\"", "/>");
|
|
|
|
if(!rating_text)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return rating;
|
|
|
|
}
|
2012-05-13 17:36:43 +02:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(strncmp(rating_text, "CERO", 4) == 0)
|
|
|
|
rating = GAMETDB_RATING_TYPE_CERO;
|
|
|
|
else if(strncmp(rating_text, "ESRB", 4) == 0)
|
|
|
|
rating = GAMETDB_RATING_TYPE_ESRB;
|
|
|
|
else if(strncmp(rating_text, "PEGI", 4) == 0)
|
|
|
|
rating = GAMETDB_RATING_TYPE_PEGI;
|
|
|
|
else if(strncmp(rating_text, "GRB", 4) == 0)
|
|
|
|
rating = GAMETDB_RATING_TYPE_GRB;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return rating;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
bool GameTDB::GetRatingValue(const char *id, const char * &rating_value)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
rating_value = NULL;
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *rating_text = GetNodeText(data, "<rating type=\"", "/>");
|
|
|
|
if(!rating_text)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
rating_value = GetNodeText(rating_text, "value=\"", "\"");
|
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
if(rating_value == NULL)
|
|
|
|
return false;
|
2012-07-26 00:12:17 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetRatingDescriptors(const char *id, vector<string> & desc_list)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
desc_list.clear();
|
|
|
|
if(!id)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
char *descriptor_text = GetNodeText(data, "<descriptor>", "</rating>");
|
|
|
|
if(!descriptor_text)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 list_num = 0;
|
|
|
|
|
|
|
|
while(*descriptor_text != '\0')
|
|
|
|
{
|
|
|
|
if(strncmp(descriptor_text, "</descriptor>", strlen("</descriptor>")) == 0)
|
|
|
|
{
|
|
|
|
desc_list[list_num].push_back('\0');
|
|
|
|
descriptor_text = strstr(descriptor_text, "<descriptor>");
|
|
|
|
if(!descriptor_text)
|
|
|
|
break;
|
|
|
|
|
|
|
|
descriptor_text += strlen("<descriptor>");
|
|
|
|
list_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(list_num >= desc_list.size())
|
|
|
|
desc_list.resize(list_num+1);
|
|
|
|
|
|
|
|
desc_list[list_num].push_back(*descriptor_text);
|
|
|
|
++descriptor_text;
|
|
|
|
}
|
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
|
|
|
|
return desc_list.size();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetWifiPlayers(const char *id)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
int players = -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return players;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return players;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *PlayersNode = GetNodeText(data, "<wi-fi players=\"", "\">");
|
|
|
|
if(!PlayersNode)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return players;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
players = atoi(PlayersNode);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return players;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetWifiFeatures(const char *id, vector<string> & feat_list)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
feat_list.clear();
|
|
|
|
if(!id)
|
|
|
|
return -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *feature_text = GetNodeText(data, "<feature>", "</wi-fi>");
|
|
|
|
if(!feature_text)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 list_num = 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
while(*feature_text != '\0')
|
|
|
|
{
|
|
|
|
if(strncmp(feature_text, "</feature>", strlen("</feature>")) == 0)
|
|
|
|
{
|
|
|
|
feat_list[list_num].push_back('\0');
|
|
|
|
feature_text = strstr(feature_text, "<feature>");
|
|
|
|
if(!feature_text)
|
|
|
|
break;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
feature_text += strlen("<feature>");
|
|
|
|
list_num++;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(list_num >= feat_list.size())
|
|
|
|
feat_list.resize(list_num+1);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
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);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
++feature_text;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return feat_list.size();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetPlayers(const char *id)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
int players = -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return players;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return players;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *PlayersNode = GetNodeText(data, "<input players=\"", "\">");
|
|
|
|
if(!PlayersNode)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return players;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
players = atoi(PlayersNode);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return players;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetAccessories(const char *id, vector<Accessory> & acc_list)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
acc_list.clear();
|
|
|
|
if(!id)
|
|
|
|
return -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
|
|
|
return -1;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *ControlsNode = GetNodeText(data, "<control type=\"", "</input>");
|
|
|
|
if(!ControlsNode)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 list_num = 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
while(ControlsNode && *ControlsNode != '\0')
|
|
|
|
{
|
|
|
|
if(list_num >= acc_list.size())
|
|
|
|
acc_list.resize(list_num+1);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
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');
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *requiredField = strstr(ControlsNode, "required=\"");
|
|
|
|
if(!requiredField)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
requiredField += strlen("required=\"");
|
2012-01-25 01:11:28 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
acc_list[list_num].Required = strncmp(requiredField, "true", 4) == 0;
|
2012-01-25 01:11:28 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
ControlsNode = strstr(requiredField, "<control type=\"");
|
|
|
|
if(ControlsNode)
|
|
|
|
ControlsNode += strlen("<control type=\"");
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
list_num++;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return acc_list.size();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 GameTDB::FindCaseColor(char *data)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2018-05-08 15:49:43 +02:00
|
|
|
u32 color = -1;// -1 = ffffffff
|
2012-07-26 00:12:17 +02:00
|
|
|
|
|
|
|
char *ColorNode = GetNodeText(data, "<case color=\"", "\"");
|
|
|
|
if(!ColorNode || strlen(ColorNode) == 0)
|
2012-01-28 14:42:46 +01:00
|
|
|
return color;
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
char format[8];
|
|
|
|
sprintf(format, "0x%s", ColorNode);
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return strtoul(format, NULL, 16);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
u32 GameTDB::GetCaseColor(const char *id)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2018-05-08 15:49:43 +02:00
|
|
|
u32 color = -1;// -1 = ffffffff
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
2012-01-25 01:11:28 +01:00
|
|
|
return color;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
2012-01-25 01:11:28 +01:00
|
|
|
return color;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
color = FindCaseColor(data);
|
2012-02-12 02:43:31 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(color != 0xffffffff)
|
2012-01-25 01:11:28 +01:00
|
|
|
gprintf("GameTDB: Found alternate color(%x) for: %s\n", color, id);
|
2012-07-26 00:12:17 +02:00
|
|
|
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-01-21 21:57:41 +01:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
int GameTDB::GetCaseVersions(const char *id)
|
2012-02-12 02:43:31 +01:00
|
|
|
{
|
2012-07-26 00:12:17 +02:00
|
|
|
int altcase = -1;
|
2012-02-12 02:43:31 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
if(!id)
|
|
|
|
return altcase;
|
2012-02-12 02:43:31 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *data = GetGameNode(id);
|
|
|
|
if(!data)
|
2012-02-12 02:43:31 +01:00
|
|
|
{
|
2012-10-02 21:26:50 +02:00
|
|
|
//gprintf("GameTDB: GameNode for %s not found\n", id);
|
2012-02-12 02:43:31 +01:00
|
|
|
return altcase;
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
char *PlayersNode = GetNodeText(data, "case versions=\"", "\"");
|
|
|
|
if(!PlayersNode)
|
|
|
|
{
|
2012-11-04 00:38:39 +01:00
|
|
|
MEM2_free(data);
|
2012-07-26 00:12:17 +02:00
|
|
|
return altcase;
|
|
|
|
}
|
2012-02-12 02:43:31 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
altcase = atoi(PlayersNode);
|
2012-02-12 02:43:31 +01:00
|
|
|
|
2012-07-26 00:12:17 +02:00
|
|
|
return altcase;
|
2012-02-12 02:43:31 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
bool GameTDB::IsLoaded()
|
|
|
|
{
|
|
|
|
return isLoaded;
|
|
|
|
}
|