2009-10-01 01:10:58 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
|
|
|
|
#include "language/gettext.h"
|
2010-09-25 08:54:27 +02:00
|
|
|
#include "FileOperations/fileops.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "cfg.h"
|
2009-10-14 23:59:13 +02:00
|
|
|
#define isspace2(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
u8 ocarinaChoice = 0;
|
|
|
|
u8 videoChoice = 0;
|
|
|
|
u8 faveChoice = no;
|
|
|
|
u8 languageChoice = 0;
|
|
|
|
u8 viChoice = 0;
|
2009-11-17 23:57:41 +01:00
|
|
|
u8 iosChoice = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
u8 parentalcontrolChoice = 0;
|
|
|
|
u8 fix002 = 0;
|
|
|
|
u8 reloadblock = 0;
|
|
|
|
u8 countrystrings = 0;
|
|
|
|
u8 alternatedol = 0;
|
|
|
|
u32 alternatedoloffset = 0;
|
|
|
|
u8 xflip = 0;
|
|
|
|
u8 sort = 0;
|
|
|
|
u8 fave = 0;
|
|
|
|
u8 qboot = 0;
|
|
|
|
u8 wsprompt = 0;
|
|
|
|
u8 keyset = 0;
|
|
|
|
u8 favoritevar = 0;
|
|
|
|
u16 playcount = 0;
|
|
|
|
u8 listDisplay = 0;
|
2009-11-15 20:52:58 +01:00
|
|
|
u8 partition = -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
char alternatedname[40];
|
2010-09-19 12:53:24 +02:00
|
|
|
u8 returnToLoaderGV = 1; //global variable used for returnToLoaderShit. defaults to "yes, patch return to loader"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
struct ID_Title
|
|
|
|
{
|
2010-01-07 19:20:26 +01:00
|
|
|
char id[6];
|
2010-01-18 00:59:59 +01:00
|
|
|
char * title;
|
2009-10-01 01:10:58 +02:00
|
|
|
};
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
struct ID_Control
|
|
|
|
{
|
2010-01-07 19:20:26 +01:00
|
|
|
char id[6];
|
2009-10-01 01:10:58 +02:00
|
|
|
u8 block;
|
|
|
|
};
|
|
|
|
// renamed titles
|
|
|
|
int num_title = 0; //number of titles
|
|
|
|
struct ID_Title *cfg_title = NULL;
|
|
|
|
|
|
|
|
int num_control = 0;
|
|
|
|
struct ID_Control *cfg_control = NULL;
|
|
|
|
|
|
|
|
#define MAX_SAVED_GAME_NUM 1000
|
|
|
|
int num_saved_game_num = 0;
|
|
|
|
struct Game_NUM cfg_game_num[MAX_SAVED_GAME_NUM];
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char *cfg_get_title(u8 *id)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!id) return NULL;
|
2010-01-07 00:07:35 +01:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < num_title; i++)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strncmp((char*) id, cfg_title[i].id, 6) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
return cfg_title[i].title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char *get_title(struct discHdr *header)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!header) return NULL;
|
2010-01-07 19:20:26 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char *title = cfg_get_title(header->id);
|
|
|
|
if (title) return title;
|
2009-10-01 01:10:58 +02:00
|
|
|
return header->title;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void title_set(char *id, char *title)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!id || !title) return;
|
2010-01-18 00:59:59 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!cfg_title) cfg_title = (struct ID_Title *) malloc(sizeof(struct ID_Title));
|
2010-01-18 00:59:59 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char *idt = cfg_get_title((u8*) id);
|
|
|
|
if (idt)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
// replace
|
2010-09-24 02:48:03 +02:00
|
|
|
free(idt);
|
|
|
|
idt = strdup(title);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
struct ID_Title * tmpStruct = (struct ID_Title *) realloc(cfg_title, (num_title + 1) * sizeof(struct ID_Title));
|
|
|
|
if (!tmpStruct)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
// error
|
2010-01-18 00:59:59 +01:00
|
|
|
CFG_Cleanup();
|
2009-10-01 01:10:58 +02:00
|
|
|
num_title = 0;
|
|
|
|
return;
|
|
|
|
}
|
2010-01-18 00:59:59 +01:00
|
|
|
|
|
|
|
cfg_title = tmpStruct;
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
// add
|
2010-09-24 02:48:03 +02:00
|
|
|
strncpy(cfg_title[num_title].id, id, 6);
|
|
|
|
cfg_title[num_title].title = strdup(title);
|
2009-10-01 01:10:58 +02:00
|
|
|
num_title++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void titles_default()
|
|
|
|
{
|
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < num_title; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
memset(cfg_title[i].id, 0, 6);
|
|
|
|
free(cfg_title[i].title);
|
2010-01-18 00:59:59 +01:00
|
|
|
cfg_title[i].title = NULL;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
u8 cfg_get_block(u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < num_control; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (memcmp(id, cfg_control[i].id, 6) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
return cfg_control[i].block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
u8 get_block(struct discHdr *header)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return cfg_get_block(header->id);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s8 get_pegi_block(struct discHdr *header)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (get_block(header))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
case 1:
|
|
|
|
return 7;
|
|
|
|
case 2:
|
|
|
|
return 12;
|
|
|
|
case 3:
|
|
|
|
return 16;
|
|
|
|
case 4:
|
|
|
|
return 18;
|
|
|
|
default:
|
|
|
|
return -1;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-12-10 21:27:36 +01:00
|
|
|
}
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
// trim leading and trailing whitespace
|
|
|
|
// copy at max n or at max size-1
|
2010-09-24 02:48:03 +02:00
|
|
|
char* trim_n_copy(char *dest, char *src, int n, int size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
int len;
|
|
|
|
// trim leading white space
|
2010-09-24 02:48:03 +02:00
|
|
|
while (isspace2( *src ))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
src++;
|
|
|
|
n--;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
len = strlen(src);
|
|
|
|
if (len > n) len = n;
|
2009-10-01 01:10:58 +02:00
|
|
|
// trim trailing white space
|
2010-09-24 02:48:03 +02:00
|
|
|
while (len > 0 && isspace2( src[len-1] ))
|
|
|
|
len--;
|
|
|
|
if (len >= size) len = size - 1;
|
|
|
|
strlcpy(dest, src, len + 1);
|
2009-10-01 01:10:58 +02:00
|
|
|
//printf("trim_copy: '%s' %d\n", dest, len); //sleep(1);
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char* trimcopy(char *dest, char *src, int size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
int len;
|
2010-09-24 02:48:03 +02:00
|
|
|
while (*src == ' ')
|
|
|
|
src++;
|
|
|
|
len = strlen(src);
|
2009-10-01 01:10:58 +02:00
|
|
|
// trim trailing " \r\n"
|
2010-09-24 02:48:03 +02:00
|
|
|
while (len > 0 && strchr(" \r\n", src[len - 1]))
|
|
|
|
len--;
|
|
|
|
if (len >= size) len = size - 1;
|
|
|
|
strlcpy(dest, src, len + 1);
|
2009-10-01 01:10:58 +02:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// split line to part1 delimiter part2
|
2010-09-24 02:48:03 +02:00
|
|
|
bool trimsplit(char *line, char *part1, char *part2, char delim, int size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
char *eq = strchr(line, delim);
|
|
|
|
if (!eq) return false;
|
|
|
|
trim_n_copy(part1, line, eq - line, size);
|
|
|
|
trimcopy(part2, eq + 1, size);
|
2009-10-01 01:10:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
void cfg_parseline(char *line, void(*set_func)(char*, char*))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
// split name = value
|
|
|
|
char tmp[300], name[200], val[200];
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(tmp, line, sizeof(tmp));
|
|
|
|
char *eq = strchr(tmp, '=');
|
|
|
|
if (!eq) return;
|
2009-10-01 01:10:58 +02:00
|
|
|
*eq = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
trimcopy(name, tmp, sizeof(name));
|
|
|
|
trimcopy(val, eq + 1, sizeof(val));
|
2009-10-01 01:10:58 +02:00
|
|
|
//printf("CFG: %s = %s\n", name, val);
|
2010-09-24 02:48:03 +02:00
|
|
|
set_func(name, val);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void cfg_parsetitleline(char *line, void(*set_func)(char*, char*, u8))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
// split name = value
|
|
|
|
char tmp[200], name[200], val[200];
|
|
|
|
int block = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
strlcpy(tmp, line, sizeof(tmp));
|
|
|
|
char *eq = strchr(tmp, '=');
|
|
|
|
if (!eq) return;
|
2009-10-01 01:10:58 +02:00
|
|
|
*eq = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
trimcopy(name, tmp, sizeof(name));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char *blockpos = strrchr(eq + 1, '=');
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!blockpos)
|
|
|
|
trimcopy(val, eq + 1, sizeof(val));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
else
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
*blockpos = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
trimcopy(val, eq + 1, sizeof(val));
|
|
|
|
if (sscanf(blockpos + 1, "%d", &block) != 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
block = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
set_func(name, val, block);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool cfg_parsefile(char *fname, void(*set_func)(char*, char*))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
FILE *f;
|
|
|
|
char line[300];
|
|
|
|
|
|
|
|
//printf("opening(%s)\n", fname);
|
2010-09-24 02:48:03 +02:00
|
|
|
f = fopen(fname, "r");
|
|
|
|
if (!f)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
//printf("error opening(%s)\n", fname);
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
while (fgets(line, sizeof(line), f))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
// lines starting with # are comments
|
2010-09-24 02:48:03 +02:00
|
|
|
if (line[0] == '#') continue;
|
|
|
|
cfg_parseline(line, set_func);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
fclose(f);
|
2009-10-01 01:10:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool cfg_parsetitlefile(char *fname, void(*set_func)(char*, char*, u8))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
FILE *f;
|
|
|
|
char line[200];
|
|
|
|
|
|
|
|
//printf("opening(%s)\n", fname);
|
2010-09-24 02:48:03 +02:00
|
|
|
f = fopen(fname, "r");
|
|
|
|
if (!f)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
//printf("error opening(%s)\n", fname);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
while (fgets(line, sizeof(line), f))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
// lines starting with # are comments
|
2010-09-24 02:48:03 +02:00
|
|
|
if (line[0] == '#') continue;
|
|
|
|
cfg_parsetitleline(line, set_func);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
fclose(f);
|
2009-10-01 01:10:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
struct Game_NUM* cfg_get_game_num(u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
struct Game_NUM *game = CFG_get_game_num(id);
|
|
|
|
if (game) return game;
|
|
|
|
if (num_saved_game_num >= MAX_SAVED_GAME_NUM) return NULL;
|
2009-10-01 01:10:58 +02:00
|
|
|
game = &cfg_game_num[num_saved_game_num];
|
|
|
|
num_saved_game_num++;
|
|
|
|
return game;
|
|
|
|
}
|
|
|
|
|
|
|
|
// current options to game
|
2010-09-24 02:48:03 +02:00
|
|
|
void cfg_set_game_num(struct Game_NUM *game, u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
strncpy((char*) game->id, (char*) id, 6);
|
2009-10-01 01:10:58 +02:00
|
|
|
game->id[6] = 0;
|
|
|
|
game->favorite = favoritevar;
|
|
|
|
game->count = playcount;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void game_set_num(char *name, char *val)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
u8 id[8];
|
|
|
|
struct Game_NUM *game;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strncmp(name, "game:", 5) != 0) return;
|
|
|
|
trimcopy((char*) id, name + 5, sizeof(id));
|
|
|
|
game = cfg_get_game_num(id);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
cfg_set_game_num(game, id);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
// parse val
|
|
|
|
// first split options by ;
|
|
|
|
char opt[200], *p, *np;
|
|
|
|
p = val;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
while (p)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
np = strchr(p, ';');
|
|
|
|
if (np)
|
|
|
|
trim_n_copy(opt, p, np - p, sizeof(opt));
|
|
|
|
else trimcopy(opt, p, sizeof(opt));
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
char opt_name[200], opt_val[200];
|
2010-09-24 02:48:03 +02:00
|
|
|
if (trimsplit(opt, opt_name, opt_val, ':', sizeof(opt_name)))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
short opt_c;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strcmp("favorite", opt_name) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (sscanf(opt_val, "%hd", &opt_c) == 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
game->favorite = opt_c;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strcmp("count", opt_name) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (sscanf(opt_val, "%hd", &opt_c) == 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
game->count = opt_c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (np)
|
|
|
|
p = np + 1;
|
2009-10-01 01:10:58 +02:00
|
|
|
else p = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool cfg_load_game_num()
|
|
|
|
{
|
2010-09-25 08:54:27 +02:00
|
|
|
char GXGameFavorites_cfg[100];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(GXGameFavorites_cfg, "%s/config/GXGameFavorites.cfg", bootDevice);
|
|
|
|
return cfg_parsefile(GXGameFavorites_cfg, &game_set_num);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool cfg_save_game_num()
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
FILE *f;
|
|
|
|
int i;
|
2010-09-25 08:54:27 +02:00
|
|
|
char GXGameFavorites_cfg[100];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(GXGameFavorites_cfg, "%s/config", bootDevice);
|
2010-09-25 08:54:27 +02:00
|
|
|
CreateSubfolder(GXGameFavorites_cfg);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(GXGameFavorites_cfg, "%s/config/GXGameFavorites.cfg", bootDevice);
|
|
|
|
f = fopen(GXGameFavorites_cfg, "w");
|
|
|
|
if (!f)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
fprintf(f, "# USB Loader settings file\n");
|
|
|
|
fprintf(f, "# note: this file is automatically generated\n");
|
|
|
|
fprintf(f, "# Num Games: %d\n", num_saved_game_num);
|
|
|
|
for (i = 0; i < num_saved_game_num; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
fprintf(f, "game:%s = ", cfg_game_num[i].id);
|
|
|
|
fprintf(f, "favorite:%d; ", cfg_game_num[i].favorite);
|
|
|
|
fprintf(f, "count:%d;\n", cfg_game_num[i].count);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
fprintf(f, "# END\n");
|
|
|
|
fclose(f);
|
2009-10-01 01:10:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool CFG_reset_all_playcounters()
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
FILE *f;
|
|
|
|
int i;
|
2010-09-25 08:54:27 +02:00
|
|
|
char GXGameFavorites_cfg[100];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(GXGameFavorites_cfg, "%s/config/GXGameFavorites.cfg", bootDevice);
|
|
|
|
f = fopen(GXGameFavorites_cfg, "w");
|
|
|
|
if (!f)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
fprintf(f, "# USB Loader settings file\n");
|
|
|
|
fprintf(f, "# note: this file is automatically generated\n");
|
|
|
|
fprintf(f, "# Num Games: %d\n", num_saved_game_num);
|
|
|
|
for (i = 0; i < num_saved_game_num; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
fprintf(f, "game:%s = ", cfg_game_num[i].id);
|
|
|
|
fprintf(f, "favorite:%d; ", cfg_game_num[i].favorite);
|
|
|
|
fprintf(f, "count:0;\n");
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
fprintf(f, "# END\n");
|
|
|
|
fclose(f);
|
2009-10-01 01:10:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
struct Game_NUM* CFG_get_game_num(const u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < num_saved_game_num; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (memcmp(id, cfg_game_num[i].id, 6) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
return &cfg_game_num[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool CFG_save_game_num(u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
struct Game_NUM *game = cfg_get_game_num(id);
|
|
|
|
if (!game) return false;
|
|
|
|
cfg_set_game_num(game, id);
|
2009-10-01 01:10:58 +02:00
|
|
|
return cfg_save_game_num();
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool CFG_forget_game_num(u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
struct Game_NUM *game = CFG_get_game_num(id);
|
2009-10-01 01:10:58 +02:00
|
|
|
int i;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!game) return true;
|
2009-10-01 01:10:58 +02:00
|
|
|
// move entries down
|
|
|
|
num_saved_game_num--;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = game - cfg_game_num; i < num_saved_game_num; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 23:22:01 +02:00
|
|
|
cfg_game_num[i] = cfg_game_num[i + 1];
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 23:22:01 +02:00
|
|
|
memset(&cfg_game_num[num_saved_game_num], 0, sizeof(struct Game_NUM));
|
2009-10-01 01:10:58 +02:00
|
|
|
return cfg_save_game_num();
|
|
|
|
}
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
void CFG_LoadGameNum()
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
cfg_load_game_num();
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void CFG_Cleanup(void)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-01-18 00:59:59 +01:00
|
|
|
int i = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < num_title; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (cfg_title[i].title) free(cfg_title[i].title);
|
2010-09-19 01:16:05 +02:00
|
|
|
cfg_title[i].title = NULL;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (cfg_title)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
free(cfg_title);
|
2009-10-01 01:10:58 +02:00
|
|
|
cfg_title = NULL;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
num_title = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|