Refactor error

This commit is contained in:
TuxSH 2017-05-23 17:13:43 +02:00
parent a9a8edeaf4
commit 68d9674ca3
3 changed files with 16 additions and 19 deletions

View File

@ -31,7 +31,6 @@
#include "buttons.h" #include "buttons.h"
#include "pin.h" #include "pin.h"
#include "crypto.h" #include "crypto.h"
#include "fmt.h"
#include "memory.h" #include "memory.h"
#include "screen.h" #include "screen.h"
@ -47,7 +46,6 @@ void main(int argc, char **argv, u32 magicWord)
{ {
bool isSafeMode = false, bool isSafeMode = false,
isNoForceFlagSet = false; isNoForceFlagSet = false;
char errbuf[46];
u32 emuHeader; u32 emuHeader;
FirmwareType firmType; FirmwareType firmType;
FirmwareSource nandType; FirmwareSource nandType;
@ -58,7 +56,6 @@ void main(int argc, char **argv, u32 magicWord)
for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16 for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16
launchedPath[i] = argv[0][i]; launchedPath[i] = argv[0][i];
launchedPath[i] = 0; launchedPath[i] = 0;
break;
} }
else if(magicWord == 0xBABE && argc == 2) //Firmlaunch else if(magicWord == 0xBABE && argc == 2) //Firmlaunch
{ {
@ -69,14 +66,9 @@ void main(int argc, char **argv, u32 magicWord)
launchedPath[i] = 0; launchedPath[i] = 0;
isFirmlaunch = true; isFirmlaunch = true;
break;
} }
else else
{ error("Unsupported launcher or entrypoint (magic = 0x%08x, argc = %d).", magicWord, argc);
sprintf(errbuf, "Unsupported launcher or entrypoint (magic = 0x%08x, argc = %d).", magicWord, argc);
error(errbuf);
break;
}
if(memcmp(launchedPath, u"sdmc", 8) == 0) if(memcmp(launchedPath, u"sdmc", 8) == 0)
{ {
@ -98,8 +90,7 @@ void main(int argc, char **argv, u32 magicWord)
mountPoint[i] = (char)launchedPath[i]; mountPoint[i] = (char)launchedPath[i];
mountPoint[i] = 0; mountPoint[i] = 0;
sprintf(errbuf, "Launched from an unsupported location: %s.", mountPoint); error("Launched from an unsupported location: %s.", mountPoint);
error(errbuf);
} }
//Attempt to read the configuration file //Attempt to read the configuration file
@ -303,11 +294,7 @@ boot:
break; break;
} }
if(res != 0) if(res != 0) error("Failed to apply %u FIRM patch(es).", res);
{
sprintf(errbuf, "Failed to apply %u FIRM patch(es).", res);
error(errbuf);
}
if(!isFirmlaunch) deinitScreens(); if(!isFirmlaunch) deinitScreens();
launchFirm(0, NULL); launchFirm(0, NULL);

View File

@ -30,6 +30,9 @@
#include "screen.h" #include "screen.h"
#include "draw.h" #include "draw.h"
#include "cache.h" #include "cache.h"
#include "fmt.h"
#include <stdarg.h>
static void startChrono(void) static void startChrono(void)
{ {
@ -104,14 +107,21 @@ void wait(u64 amount)
while(chrono() < amount); while(chrono() < amount);
} }
void error(const char *message) void error(const char *fmt, ...)
{ {
if(!isFirmlaunch) if(!isFirmlaunch)
{ {
char buf[DRAW_MAX_FORMATTED_STRING_SIZE + 1];
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
initScreens(); initScreens();
drawString(true, 10, 10, COLOR_RED, "An error has occurred:"); drawString(true, 10, 10, COLOR_RED, "An error has occurred:");
u32 posY = drawString(true, 10, 30, COLOR_WHITE, message); u32 posY = drawString(true, 10, 30, COLOR_WHITE, buf);
drawString(true, 10, posY + 2 * SPACING_Y, COLOR_WHITE, "Press any button to shutdown"); drawString(true, 10, posY + 2 * SPACING_Y, COLOR_WHITE, "Press any button to shutdown");
waitInput(false); waitInput(false);

View File

@ -35,4 +35,4 @@
u32 waitInput(bool isMenu); u32 waitInput(bool isMenu);
void mcuPowerOff(void); void mcuPowerOff(void);
void wait(u64 amount); void wait(u64 amount);
void error(const char *message); void error(const char *fmt, ...);