Skip to content

Commit

Permalink
Get ID6 from meta/meta.xml as fallback (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
drizzt authored and dimok789 committed May 21, 2016
1 parent 1c4b32c commit 195aaab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/game/GameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common/common.h"
#include "settings/CSettings.h"
#include "fs/DirList.h"
#include "utils/xml.h"

GameList *GameList::gameListInstance = NULL;

Expand Down Expand Up @@ -47,17 +48,28 @@ int GameList::readGameList()
for(int i = 0; i < dirList.GetFilecount(); i++)
{
const char *filename = dirList.GetFilename(i);
char id6[7];
int len = strlen(filename);
if (len <= 8)
continue;

if ((filename[len - 8] != '[' && filename[len - 6] != '[') || filename[len - 1] != ']')
discHeader newHeader;

if (len <= 8 ||
((filename[len - 8] != '[' && filename[len - 6] != '[') || filename[len - 1] != ']'))
{
if (GetId6FromMeta((gamePath + "/" + filename + META_PATH).c_str(), id6) == 0)
{
newHeader.id = id6;
newHeader.name = filename;
newHeader.gamepath = gamePath + "/" + filename;

fullGameList.push_back(newHeader);
}
continue;
}

bool id4Title = (filename[len - 8] != '[');

std::string gamePathName = filename;
discHeader newHeader;
if(id4Title)
{
newHeader.id = gamePathName.substr(gamePathName.size() - 5, 4);
Expand Down
42 changes: 42 additions & 0 deletions src/utils/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,45 @@ int LoadXmlParameters(ReducedCosAppXmlInfo * xmlInfo, const char *rpx_name, cons

return 0;
}

int GetId6FromMeta(const char *path, char *id6)
{
id6[0] = 0;
char* path_copy = (char*)malloc(FS_MAX_MOUNTPATH_SIZE);
if (!path_copy)
return -1;

char* xmlNodeData = (char*)malloc(XML_BUFFER_SIZE);
if(!xmlNodeData) {
free(path_copy);
return -3;
}

// create path
snprintf(path_copy, FS_MAX_MOUNTPATH_SIZE, "%s/meta.xml", path);

char* xmlData = NULL;
u32 xmlSize = 0;

if(LoadFileToMem(path_copy, (u8**) &xmlData, &xmlSize) > 0)
{
// ensure 0 termination
xmlData[XML_BUFFER_SIZE-1] = 0;

if(XML_GetNodeText(xmlData, "product_code", xmlNodeData, XML_BUFFER_SIZE) && strlen(xmlNodeData) == 10)
strncpy(id6, xmlNodeData + 6, 4);
if(XML_GetNodeText(xmlData, "company_code", xmlNodeData, XML_BUFFER_SIZE) && strlen(xmlNodeData) == 4)
strncpy(id6 + 4, xmlNodeData + 2, 2);

id6[6] = 0;
}

free(xmlData);
free(xmlNodeData);
free(path_copy);

if(strlen(id6) == 6)
return 0;
else
return -2;
}
1 change: 1 addition & 0 deletions src/utils/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {

char * XML_GetNodeText(const char *xml_part, const char * nodename, char * output, int output_size);
int LoadXmlParameters(ReducedCosAppXmlInfo * xmlInfo, const char *rpx_name, const char *path);
int GetId6FromMeta(const char *path, char *output);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 195aaab

Please sign in to comment.