WiiFlow_Lite/source/main.cpp
fix94.1 26a7357e4e -updated spanish.ini again (thx ravmn)
-changed "About" to "Credits" (yea Abz that should be)
-slightly modified the IOS handling on wiiflow boot, the IOS 
gets reloaded to prevent a not working patching system and if 
the main IOS (default 249) is found wiiflow will reload into it
-in the startup settings, display AUTO instead of 0
-added some security wait before init/deinit ISFS
2012-12-25 13:42:53 +00:00

117 lines
3.1 KiB
C++

#include <ogc/system.h>
#include <unistd.h>
#include "const_str.hpp"
#include "booter/external_booter.hpp"
#include "channel/nand.hpp"
#include "devicemounter/DeviceHandler.hpp"
#include "gecko/gecko.hpp"
#include "gui/video.hpp"
#include "gui/text.hpp"
#include "homebrew/homebrew.h"
#include "loader/alt_ios_gen.h"
#include "loader/wdvd.h"
#include "loader/alt_ios.h"
#include "loader/sys.h"
#include "loader/wbfs.h"
#include "loader/cios.h"
#include "loader/nk.h"
#include "menu/menu.hpp"
#include "memory/memory.h"
CMenu mainMenu;
bool useMainIOS = false;
volatile bool NANDemuView = false;
volatile bool networkInit = false;
int main(int argc, char **argv)
{
mainIOS = DOL_MAIN_IOS;
__exception_setreload(10);
Gecko_Init(); //USB Gecko and SD/WiFi buffer
gprintf(" \nWelcome to %s!\nThis is the debug output.\n", VERSION_STRING.c_str());
m_vid.init(); // Init video
MEM_init(); //Inits both mem1lo and mem2
DeviceHandle.Init();
NandHandle.Init();
char *gameid = NULL;
bool Emulator_boot = false;
bool iosOK = false;
for(u8 i = 0; i < argc; i++)
{
if(argv[i] != NULL && strcasestr(argv[i], "ios=") != NULL && strlen(argv[i]) > 4)
{
while(argv[i][0] && !isdigit(argv[i][0]))
argv[i]++;
if (atoi(argv[i]) < 254 && atoi(argv[i]) > 0)
mainIOS = atoi(argv[i]);
}
else if(strlen(argv[i]) == 6)
{
gameid = argv[i];
for(u8 i = 0; i < 5; i++)
{
if(!isalnum(gameid[i]))
gameid = NULL;
}
}
else if(argv[i] != NULL && strcasestr(argv[i], "EMULATOR_MAGIC") != NULL)
Emulator_boot = true;
}
/* Init ISFS */
NandHandle.Init_ISFS();
/* Handle (c)IOS Loading */
if(neek2o() || Sys_DolphinMode()) /* wont reload anythin */
iosOK = loadIOS(IOS_GetVersion(), false);
else if(!CustomIOS(IOS_GetType(mainIOS))) /* safe reload */
iosOK = NandHandle.LoadDefaultIOS();
else /* cIOS found and on real nand, so just use it */
iosOK = loadIOS(mainIOS, false) && CustomIOS(CurrentIOS.Type);
// Init
Sys_Init();
Sys_ExitTo(EXIT_TO_HBC);
DeviceHandle.MountAll();
m_vid.waitMessage(0.15f);
Open_Inputs();
mainMenu.init();
if(CurrentIOS.Version != mainIOS && !neek2o() && !Sys_DolphinMode())
{
if(useMainIOS || !DeviceHandle.UsablePartitionMounted())
{
useMainIOS = false;
mainMenu.TempLoadIOS();
iosOK = CustomIOS(CurrentIOS.Type);
}
}
if(CurrentIOS.Version == mainIOS)
useMainIOS = true; //Needed for later checks
if(!iosOK)
mainMenu.terror("errboot1", L"No cIOS found!\ncIOS d2x 249 base 56 and 250 base 57 are enough for all your games.");
else if(!DeviceHandle.UsablePartitionMounted())
mainMenu.terror("errboot2", L"Could not find a device to save configuration files on!");
else if(WDVD_Init() < 0)
mainMenu.terror("errboot3", L"Could not initialize the DIP module!");
else
{
writeStub();
if(Emulator_boot)
mainMenu.m_Emulator_boot = true;
if(gameid != NULL && strlen(gameid) == 6)
mainMenu.directlaunch(gameid);
else
mainMenu.main();
}
//Exit WiiFlow, no game booted...
mainMenu.cleanup();
ShutdownBeforeExit();
Sys_Exit();
return 0;
}