now the dol looks for the update path in the GXglobal file and uses it instead of the default path.

This commit is contained in:
giantpune 2009-05-30 20:21:49 +00:00
parent d27dcc314b
commit b4ba424be0

View File

@ -30,7 +30,10 @@
#include <malloc.h> #include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ogc/machine/processor.h> #include <ogc/machine/processor.h>
//shit i added
#include <string.h>
#include "pngu/pngu.h" #include "pngu/pngu.h"
#include "video.h" #include "video.h"
@ -73,7 +76,80 @@ void Background_Show(int x, int y, int z, u8 * data, int angle, int scaleX, int
{ {
/* Draw image */ /* Draw image */
Menu_DrawImg(x, y, z, imgProp.imgWidth, imgProp.imgHeight, data, angle, scaleX, scaleY, alpha); Menu_DrawImg(x, y, z, imgProp.imgWidth, imgProp.imgHeight, data, angle, scaleX, scaleY, alpha);
} }
char thePath[100];
static char *cfg_name, *cfg_val;
char* strcopy(char *dest, char *src, int size)
{
strncpy(dest,src,size);
dest[size-1] = 0;
return dest;
}
char* trimcopy(char *dest, char *src, int size)
{
int len;
while (*src == ' ') src++;
len = strlen(src);
// trim trailing " \r\n"
while (len > 0 && strchr(" \r\n", src[len-1])) len--;
if (len >= size) len = size-1;
strncpy(dest, src, len);
dest[len] = 0;
return dest;
}
void cfg_parseline(char *line, void (*set_func)(char*, char*))
{
// split name = value
char tmp[200], name[100], val[100];
strcopy(tmp, line, sizeof(tmp));
char *eq = strchr(tmp, '=');
if (!eq) return;
*eq = 0;
trimcopy(name, tmp, sizeof(name));
trimcopy(val, eq+1, sizeof(val));
set_func(name, val);
}
bool cfg_parsefile(char *fname, void (*set_func)(char*, char*))
{
FILE *f;
char line[200];
f = fopen(fname, "r");
if (!f) {
return false;
}
while (fgets(line, sizeof(line), f)) {
// lines starting with # are comments
if (line[0] == '#') continue;
cfg_parseline(line, set_func);
}
fclose(f);
return true;
}
char pathname[200];
void cfg_set(char *name, char *val)
{
cfg_name = name;
cfg_val = val;
if (strcmp(name, "update_path") == 0) {
strcopy(thePath, val, sizeof(thePath));
return;
}
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -83,9 +159,10 @@ int main(int argc, char **argv) {
void *exeBuffer = (void *)EXECUTABLE_MEM_ADDR; void *exeBuffer = (void *)EXECUTABLE_MEM_ADDR;
int exeSize = 0; int exeSize = 0;
u32 exeEntryPointAddress = 0; u32 exeEntryPointAddress = 0;
entrypoint exeEntryPoint; entrypoint exeEntryPoint;
/* int videomod */ /* int videomod */
InitVideo(); InitVideo();
@ -102,11 +179,24 @@ int main(int argc, char **argv) {
__io_wiisd.startup(); __io_wiisd.startup();
fatMount("SD", &__io_wiisd, 0, 32, 128); fatMount("SD", &__io_wiisd, 0, 32, 128);
/* Open dol File and check exist */ /* write default path*/
exeFile = fopen ("SD:/apps/usbloader_gx/boot.dol" ,"rb"); snprintf(thePath, sizeof(thePath), "SD:/apps/usbloader_gx/");
// check to see if there is a path in the GXglobal file
snprintf(pathname, sizeof(pathname), "SD:/config/GXGlobal.cfg");
cfg_parsefile(pathname, &cfg_set);
//add boot.dol to our path
snprintf(pathname, sizeof(pathname), "%sboot.dol", thePath);
/* Open dol File and check exist */
exeFile = fopen (pathname ,"rb");
//boot.dol wasn't found. Try for the elf.
if (exeFile==NULL) { if (exeFile==NULL) {
fclose(exeFile); fclose(exeFile);
exeFile = fopen ("SD:/apps/usbloader_gx/boot.elf" ,"rb"); snprintf(pathname, sizeof(pathname), "%sboot.elf", thePath);
exeFile = fopen (pathname ,"rb");
if (exeFile==NULL) { if (exeFile==NULL) {
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
} }