mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-16 00:15:08 +01:00
*Reverted giantpunes work on forwarder source and added mine (worked parallel didnt know he was doing it) | added mine because its bit more clean and got a check if the CFG file doesnt exist
This commit is contained in:
parent
b4ba424be0
commit
11e17e07ab
75
source/cfg.c
Normal file
75
source/cfg.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <ogcsys.h>
|
||||||
|
|
||||||
|
#include "cfg.h"
|
||||||
|
|
||||||
|
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));
|
||||||
|
//printf("CFG: %s = %s\n", name, val);
|
||||||
|
set_func(name, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool cfg_parsefile(char *fname, void (*set_func)(char*, char*))
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
char line[200];
|
||||||
|
|
||||||
|
//printf("opening(%s)\n", fname);
|
||||||
|
f = fopen(fname, "r");
|
||||||
|
if (!f) {
|
||||||
|
//printf("error opening(%s)\n", fname);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cfg_set(char *name, char *val)
|
||||||
|
{
|
||||||
|
cfg_name = name;
|
||||||
|
cfg_val = val;
|
||||||
|
if (strcmp(name, "update_path") == 0) {
|
||||||
|
strcopy(update_path, val, sizeof(update_path));
|
||||||
|
}
|
||||||
|
}
|
18
source/cfg.h
Normal file
18
source/cfg.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef _CFG_H_
|
||||||
|
#define _CFG_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char update_path[150];
|
||||||
|
|
||||||
|
void cfg_set(char *name, char *val);
|
||||||
|
bool cfg_parsefile(char * fname, void (*set_func)(char*, char*));
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
127
source/main.cpp
127
source/main.cpp
@ -5,6 +5,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2009 The Lemon Man
|
* Copyright 2009 The Lemon Man
|
||||||
* Thanks to luccax, Wiipower, Aurelio and crediar
|
* Thanks to luccax, Wiipower, Aurelio and crediar
|
||||||
|
* GX added by dimok (thanks to Tantric)
|
||||||
* usbGecko powered by Nuke
|
* usbGecko powered by Nuke
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -31,15 +32,13 @@
|
|||||||
#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"
|
||||||
#include "filelist.h"
|
#include "filelist.h"
|
||||||
#include "dolloader.h"
|
#include "dolloader.h"
|
||||||
#include "elfloader.h"
|
#include "elfloader.h"
|
||||||
|
#include "cfg.h"
|
||||||
|
|
||||||
|
|
||||||
PNGUPROP imgProp;
|
PNGUPROP imgProp;
|
||||||
@ -78,91 +77,17 @@ void Background_Show(int x, int y, int z, u8 * data, int angle, int scaleX, int
|
|||||||
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) {
|
||||||
|
|
||||||
u32 cookie;
|
u32 cookie;
|
||||||
FILE *exeFile;
|
FILE *exeFile = NULL;
|
||||||
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();
|
||||||
|
|
||||||
@ -179,27 +104,33 @@ 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);
|
||||||
|
|
||||||
/* write default path*/
|
char cfgpath[40];
|
||||||
snprintf(thePath, sizeof(thePath), "SD:/apps/usbloader_gx/");
|
sprintf(cfgpath, "SD:/config/GXGlobal.cfg");
|
||||||
|
|
||||||
// check to see if there is a path in the GXglobal file
|
if(!cfg_parsefile(cfgpath, &cfg_set)) {
|
||||||
snprintf(pathname, sizeof(pathname), "SD:/config/GXGlobal.cfg");
|
/* Open dol File and check exist */
|
||||||
cfg_parsefile(pathname, &cfg_set);
|
exeFile = fopen ("SD:/apps/usbloader_gx/boot.dol" ,"rb");
|
||||||
|
if (exeFile==NULL) {
|
||||||
//add boot.dol to our path
|
fclose(exeFile);
|
||||||
snprintf(pathname, sizeof(pathname), "%sboot.dol", thePath);
|
exeFile = fopen ("SD:/apps/usbloader_gx/boot.elf" ,"rb");
|
||||||
|
if (exeFile==NULL) {
|
||||||
/* Open dol File and check exist */
|
fclose(exeFile);
|
||||||
exeFile = fopen (pathname ,"rb");
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
||||||
|
}
|
||||||
//boot.dol wasn't found. Try for the elf.
|
}
|
||||||
if (exeFile==NULL) {
|
} else {
|
||||||
fclose(exeFile);
|
sprintf(cfgpath, "%sboot.dol", update_path);
|
||||||
snprintf(pathname, sizeof(pathname), "%sboot.elf", thePath);
|
/* Open dol File and check exist */
|
||||||
exeFile = fopen (pathname ,"rb");
|
exeFile = fopen (cfgpath, "rb");
|
||||||
if (exeFile==NULL) {
|
if (exeFile==NULL) {
|
||||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
fclose(exeFile);
|
||||||
}
|
sprintf(cfgpath, "%sboot.elf", update_path);
|
||||||
|
exeFile = fopen (cfgpath,"rb");
|
||||||
|
if (exeFile==NULL) {
|
||||||
|
fclose(exeFile);
|
||||||
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek (exeFile, 0, SEEK_END);
|
fseek (exeFile, 0, SEEK_END);
|
||||||
|
Loading…
Reference in New Issue
Block a user