Make ErrorConfig exactly represent expected input-data

This commit is contained in:
Liam Minopulos 2019-02-27 20:16:25 +01:00
parent dd184c2955
commit 7e42dfe3ca
2 changed files with 24 additions and 16 deletions

View File

@ -10,7 +10,13 @@
/// Error configuration struct. /// Error configuration struct.
typedef struct { typedef struct {
u8 args[0x1018]; bool custom_text; ///< Whether to show a custom error message. If this is false, a default message will be shown.
u8 pad[7];
u32 major_code; ///< First part of the error-code.
u32 minor_code; ///< Second part of the error-code.
u8 pad2[8];
char short_description[0x800]; ///< Short description.
char detailed_description[0x800]; ///< Detailed description (displayed when the user clicks, on "Details").
} ErrorConfig; } ErrorConfig;
/** /**

View File

@ -7,13 +7,12 @@
#include "applets/error.h" #include "applets/error.h"
void errorCreate(ErrorConfig* c) { void errorCreate(ErrorConfig* c) {
memset(c->args, 0, 0x1018); memset(c, 0, sizeof(ErrorConfig));
c->custom_text = false;
c->args[0x0] = 0; c->major_code = 2000;
*(u64*) &c->args[0x8] = 2000; c->minor_code = 0;
*(u64*) &c->args[0xC] = 0; strcpy((char*) &c->short_description, "");
strcpy((char*) &c->args[0x18], ""); strcpy((char*) &c->detailed_description, "");
strcpy((char*) &c->args[0x818], "");
} }
void errorClose(ErrorConfig* c) { void errorClose(ErrorConfig* c) {
@ -25,12 +24,15 @@ void errorShow(ErrorConfig* c) {
AppletStorage errStor; AppletStorage errStor;
LibAppletArgs errArgs; LibAppletArgs errArgs;
u8 args[0x1018] = {0};
memcpy(&args, c, 0x1018);
appletCreateLibraryApplet(&err, AppletId_error, LibAppletMode_AllForeground); appletCreateLibraryApplet(&err, AppletId_error, LibAppletMode_AllForeground);
libappletArgsCreate(&errArgs, 1); libappletArgsCreate(&errArgs, 1);
libappletArgsPush(&errArgs, &err); libappletArgsPush(&errArgs, &err);
appletCreateStorage(&errStor, 4120); appletCreateStorage(&errStor, 4120);
appletStorageWrite(&errStor, 0, c->args, 0x1018); appletStorageWrite(&errStor, 0, args, 0x1018);
appletHolderPushInData(&err, &errStor); appletHolderPushInData(&err, &errStor);
@ -39,22 +41,22 @@ void errorShow(ErrorConfig* c) {
appletHolderClose(&err); appletHolderClose(&err);
} }
void errorConfigSetMajorCode(ErrorConfig* c, u64 code) { void errorConfigSetMajorCode(ErrorConfig* c, u32 code) {
*(u64*) &c->args[0x8] = code; c->major_code = code;
} }
void errorConfigSetMinorCode(ErrorConfig* c, u64 code) { void errorConfigSetMinorCode(ErrorConfig* c, u32 code) {
*(u64*) &c->args[0xC] = code; c->minor_code = code;
} }
void errorConfigSetCustomText(ErrorConfig* c, bool customText) { void errorConfigSetCustomText(ErrorConfig* c, bool customText) {
c->args[0x0] = customText; c->custom_text = customText;
} }
void errorConfigSetShortDescription(ErrorConfig* c, const char* str) { void errorConfigSetShortDescription(ErrorConfig* c, const char* str) {
strcpy((char*) &c->args[0x18], str); strcpy((char*) &c->short_description, str);
} }
void errorConfigSetDetailedDescription(ErrorConfig* c, const char* str) { void errorConfigSetDetailedDescription(ErrorConfig* c, const char* str) {
strcpy((char*) &c->args[0x818], str); strcpy((char*) &c->detailed_description, str);
} }