Embed arguments directly in config-struct

This commit is contained in:
Liam Minopulos 2019-02-26 23:51:43 +01:00
parent bb93efbd17
commit dd184c2955
2 changed files with 15 additions and 35 deletions

View File

@ -10,11 +10,7 @@
/// Error configuration struct. /// Error configuration struct.
typedef struct { typedef struct {
u32 major_code; ///< First part of the error code. u8 args[0x1018];
u32 minor_code; ///< Second part of the error code.
bool custom_text; ///< Whether to display a custom error message.
char* short_description; ///< Short description of the error.
char* detailed_description; ///< More detailed description of the error. Shown when the user clicks on "Details".
} ErrorConfig; } ErrorConfig;
/** /**

View File

@ -7,20 +7,16 @@
#include "applets/error.h" #include "applets/error.h"
void errorCreate(ErrorConfig* c) { void errorCreate(ErrorConfig* c) {
c->major_code = 2000; memset(c->args, 0, 0x1018);
c->minor_code = 0;
c->custom_text = false;
c->detailed_description = (char*) malloc(sizeof(char) * (strlen("") + 1)); c->args[0x0] = 0;
strcpy(c->detailed_description, ""); *(u64*) &c->args[0x8] = 2000;
*(u64*) &c->args[0xC] = 0;
c->short_description = (char*) malloc(sizeof(char) * (strlen("") + 1)); strcpy((char*) &c->args[0x18], "");
strcpy(c->short_description, ""); strcpy((char*) &c->args[0x818], "");
} }
void errorClose(ErrorConfig* c) { void errorClose(ErrorConfig* c) {
free(c->short_description);
free(c->detailed_description);
memset(c, 0, sizeof(ErrorConfig)); memset(c, 0, sizeof(ErrorConfig));
} }
@ -34,15 +30,7 @@ void errorShow(ErrorConfig* c) {
libappletArgsPush(&errArgs, &err); libappletArgsPush(&errArgs, &err);
appletCreateStorage(&errStor, 4120); appletCreateStorage(&errStor, 4120);
appletStorageWrite(&errStor, 0, c->args, 0x1018);
u8 args[0x1018] = {0};
args[0] = (c->custom_text ? 1 : 0);
*(u64*) &args[8] = c->major_code;
*(u64*) &args[0xC] = c->minor_code;
strcpy((char*) &args[0x18], c->short_description);
strcpy((char*) &args[0x818], c->detailed_description);
appletStorageWrite(&errStor, 0, args, 0x1018);
appletHolderPushInData(&err, &errStor); appletHolderPushInData(&err, &errStor);
@ -51,26 +39,22 @@ void errorShow(ErrorConfig* c) {
appletHolderClose(&err); appletHolderClose(&err);
} }
void errorConfigSetMajorCode(ErrorConfig* c, u32 code) { void errorConfigSetMajorCode(ErrorConfig* c, u64 code) {
c->major_code = code; *(u64*) &c->args[0x8] = code;
} }
void errorConfigSetMinorCode(ErrorConfig* c, u32 code) { void errorConfigSetMinorCode(ErrorConfig* c, u64 code) {
c->minor_code = code; *(u64*) &c->args[0xC] = code;
} }
void errorConfigSetCustomText(ErrorConfig* c, bool customText) { void errorConfigSetCustomText(ErrorConfig* c, bool customText) {
c->custom_text = customText; c->args[0x0] = customText;
} }
void errorConfigSetShortDescription(ErrorConfig* c, const char* str) { void errorConfigSetShortDescription(ErrorConfig* c, const char* str) {
free(c->short_description); strcpy((char*) &c->args[0x18], str);
c->short_description = (char*) malloc(sizeof(char) * (strlen(str) + 1));
strcpy(c->short_description, str);
} }
void errorConfigSetDetailedDescription(ErrorConfig* c, const char* str) { void errorConfigSetDetailedDescription(ErrorConfig* c, const char* str) {
free(c->detailed_description); strcpy((char*) &c->args[0x818], str);
c->detailed_description = (char*) malloc(sizeof(char) * (strlen(str) + 1));
strcpy(c->detailed_description, str);
} }