2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* USB Loader GX Team
|
|
|
|
*
|
|
|
|
* Main loadup of the application
|
|
|
|
*
|
|
|
|
* libwiigui
|
|
|
|
* Tantric 2009
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/dir.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
2009-10-15 16:13:13 +02:00
|
|
|
#include <locale.h>
|
2009-10-01 01:10:58 +02:00
|
|
|
#include <wiiuse/wpad.h>
|
2009-12-15 09:39:45 +01:00
|
|
|
//#include <debug.h>
|
2010-02-09 11:59:55 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
extern void __exception_setreload( int t );
|
2009-12-10 21:27:36 +01:00
|
|
|
}
|
2009-12-03 02:06:09 +01:00
|
|
|
|
2010-01-19 11:48:50 +01:00
|
|
|
|
2009-12-03 02:06:09 +01:00
|
|
|
#include <di/di.h>
|
|
|
|
#include <sys/iosupport.h>
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
#include "libwiigui/gui.h"
|
|
|
|
#include "usbloader/wbfs.h"
|
|
|
|
#include "settings/cfg.h"
|
|
|
|
#include "language/gettext.h"
|
|
|
|
#include "mload/mload.h"
|
2010-02-15 00:22:52 +01:00
|
|
|
#include "mload/mload_modules.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "FreeTypeGX.h"
|
2010-09-17 17:15:21 +02:00
|
|
|
#include "FontSystem.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "video.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "filelist.h"
|
|
|
|
#include "listfiles.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "fatmounter.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "wpad.h"
|
|
|
|
#include "fat.h"
|
2009-10-20 13:46:55 +02:00
|
|
|
#include "gecko.h"
|
2009-10-21 01:00:19 +02:00
|
|
|
#include "svnrev.h"
|
2009-11-15 22:30:44 +01:00
|
|
|
#include "usbloader/partition_usbloader.h"
|
2010-02-22 22:29:47 +01:00
|
|
|
#include "usbloader/usbstorage2.h"
|
2009-12-04 16:05:20 +01:00
|
|
|
#include "memory/mem2.h"
|
2009-12-10 21:27:36 +01:00
|
|
|
#include "lstub.h"
|
2010-09-16 21:59:41 +02:00
|
|
|
#include "usbloader/usbstorage2.h"
|
2010-09-19 01:04:39 +02:00
|
|
|
#include "wad/nandtitle.h"
|
2009-10-20 13:46:55 +02:00
|
|
|
|
|
|
|
extern bool geckoinit;
|
2009-12-03 02:06:09 +01:00
|
|
|
extern char headlessID[8];
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:04:39 +02:00
|
|
|
NandTitle titles;
|
2010-01-19 11:48:50 +01:00
|
|
|
PartList partitions;
|
|
|
|
|
2010-09-19 12:53:24 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int main( int argc, char *argv[] )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
MEM2_init( 48 );
|
|
|
|
setlocale( LC_ALL, "en.UTF-8" );
|
2010-01-19 11:48:50 +01:00
|
|
|
geckoinit = InitGecko();
|
2010-09-19 10:13:06 +02:00
|
|
|
InitVideo();
|
2010-09-19 01:16:05 +02:00
|
|
|
__exception_setreload( 20 );
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\tStarting up\n" );
|
2010-09-19 01:04:39 +02:00
|
|
|
titles.Get();
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool bootDevice_found = false;
|
|
|
|
if ( argc >= 1 )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !strncasecmp( argv[0], "usb:/", 5 ) )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
strcpy( bootDevice, "USB:" );
|
|
|
|
bootDevice_found = true;
|
|
|
|
}
|
|
|
|
else if ( !strncasecmp( argv[0], "sd:/", 4 ) )
|
2009-10-01 01:10:58 +02:00
|
|
|
bootDevice_found = true;
|
2010-01-19 11:48:50 +01:00
|
|
|
}
|
|
|
|
|
2010-09-16 21:59:41 +02:00
|
|
|
//Let's use libogc sd/usb for config loading
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\tInitialize sd card\n" );
|
2010-09-16 21:59:41 +02:00
|
|
|
SDCard_Init();
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\tInitialize usb device\n" );
|
2010-09-16 21:59:41 +02:00
|
|
|
USBDevice_Init();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !bootDevice_found )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\tSearch for configuration file\n" );
|
2009-10-01 01:10:58 +02:00
|
|
|
//try USB
|
|
|
|
//left in all the dol and elf files in this check in case this is the first time running the app and they dont have the config
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( checkfile( ( char* ) "USB:/config/GXglobal.cfg" ) || ( checkfile( ( char* ) "USB:/apps/usbloader_gx/boot.elf" ) )
|
|
|
|
|| checkfile( ( char* ) "USB:/apps/usbloadergx/boot.dol" ) || ( checkfile( ( char* ) "USB:/apps/usbloadergx/boot.elf" ) )
|
|
|
|
|| checkfile( ( char* ) "USB:/apps/usbloader_gx/boot.dol" ) )
|
|
|
|
strcpy( bootDevice, "USB:" );
|
2009-11-17 23:57:41 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\tConfiguration file is on %s\n", bootDevice );
|
2010-01-19 11:48:50 +01:00
|
|
|
}
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
gettextCleanUp();
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\tLoading configuration..." );
|
2009-10-01 01:10:58 +02:00
|
|
|
CFG_Load();
|
2010-09-19 10:13:06 +02:00
|
|
|
VIDEO_SetWidescreen(CFG.widescreen);
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "done\n" );
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2010-09-16 21:59:41 +02:00
|
|
|
SDCard_deInit();// unmount SD for reloading IOS
|
|
|
|
USBDevice_deInit();// unmount USB for reloading IOS
|
|
|
|
USBStorage2_Deinit();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\tCheck for an existing cIOS\n" );
|
2010-09-16 21:59:41 +02:00
|
|
|
CheckForCIOS();
|
2010-01-19 11:48:50 +01:00
|
|
|
|
2010-09-16 21:59:41 +02:00
|
|
|
// Let's load the cIOS now
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( LoadAppCIOS() < 0 )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 03:16:04 +02:00
|
|
|
printf( "\tERROR: No cIOS could be loaded. Exiting....\n" );
|
2010-09-19 01:16:05 +02:00
|
|
|
sleep( 5 );
|
2010-09-16 21:59:41 +02:00
|
|
|
Sys_BackToLoader();
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 03:16:04 +02:00
|
|
|
printf( "\tLoaded cIOS = %u (Rev %u)\n", IOS_GetVersion(), IOS_GetRevision() );
|
2010-09-17 19:48:16 +02:00
|
|
|
|
2010-09-19 03:16:04 +02:00
|
|
|
printf( "\tWaiting for USB:\n" );
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( MountWBFS() < 0 )
|
2010-05-29 09:38:54 +02:00
|
|
|
{
|
2010-09-19 10:13:06 +02:00
|
|
|
printf( "ERROR: No WBFS drive mounted.\n" );
|
2010-09-19 01:16:05 +02:00
|
|
|
sleep( 5 );
|
|
|
|
exit( 0 );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 11:48:50 +01:00
|
|
|
//if a ID was passed via args copy it and try to boot it after the partition is mounted
|
|
|
|
//its not really a headless mode. more like hairless.
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( argc > 1 && argv[1] )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( strlen( argv[1] ) == 6 )
|
|
|
|
strncpy( headlessID, argv[1], sizeof( headlessID ) );
|
2010-01-19 11:48:50 +01:00
|
|
|
}
|
2010-01-18 00:59:59 +01:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
//! Init the rest of the System
|
2010-09-19 03:16:04 +02:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
Sys_Init();
|
2010-09-17 19:48:16 +02:00
|
|
|
SetupPads();
|
2010-09-16 21:59:41 +02:00
|
|
|
InitAudio();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
char *fontPath = NULL;
|
2010-09-19 01:16:05 +02:00
|
|
|
asprintf( &fontPath, "%sfont.ttf", CFG.theme_path );
|
|
|
|
SetupDefaultFont( fontPath );
|
|
|
|
free( fontPath );
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
gprintf( "\n\tEnd of Main()" );
|
2009-10-01 01:10:58 +02:00
|
|
|
InitGUIThreads();
|
2010-09-19 01:16:05 +02:00
|
|
|
MainMenu( MENU_CHECK );
|
2009-10-01 01:10:58 +02:00
|
|
|
return 0;
|
|
|
|
}
|