mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-06 03:12:15 +02:00
Embed arguments directly in config-struct
This commit is contained in:
parent
bb93efbd17
commit
dd184c2955
@ -10,11 +10,7 @@
|
||||
|
||||
/// Error configuration struct.
|
||||
typedef struct {
|
||||
u32 major_code; ///< First part of the error code.
|
||||
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".
|
||||
u8 args[0x1018];
|
||||
} ErrorConfig;
|
||||
|
||||
/**
|
||||
|
@ -7,20 +7,16 @@
|
||||
#include "applets/error.h"
|
||||
|
||||
void errorCreate(ErrorConfig* c) {
|
||||
c->major_code = 2000;
|
||||
c->minor_code = 0;
|
||||
c->custom_text = false;
|
||||
memset(c->args, 0, 0x1018);
|
||||
|
||||
c->detailed_description = (char*) malloc(sizeof(char) * (strlen("") + 1));
|
||||
strcpy(c->detailed_description, "");
|
||||
|
||||
c->short_description = (char*) malloc(sizeof(char) * (strlen("") + 1));
|
||||
strcpy(c->short_description, "");
|
||||
c->args[0x0] = 0;
|
||||
*(u64*) &c->args[0x8] = 2000;
|
||||
*(u64*) &c->args[0xC] = 0;
|
||||
strcpy((char*) &c->args[0x18], "");
|
||||
strcpy((char*) &c->args[0x818], "");
|
||||
}
|
||||
|
||||
void errorClose(ErrorConfig* c) {
|
||||
free(c->short_description);
|
||||
free(c->detailed_description);
|
||||
memset(c, 0, sizeof(ErrorConfig));
|
||||
}
|
||||
|
||||
@ -34,15 +30,7 @@ void errorShow(ErrorConfig* c) {
|
||||
libappletArgsPush(&errArgs, &err);
|
||||
|
||||
appletCreateStorage(&errStor, 4120);
|
||||
|
||||
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);
|
||||
appletStorageWrite(&errStor, 0, c->args, 0x1018);
|
||||
|
||||
appletHolderPushInData(&err, &errStor);
|
||||
|
||||
@ -51,26 +39,22 @@ void errorShow(ErrorConfig* c) {
|
||||
appletHolderClose(&err);
|
||||
}
|
||||
|
||||
void errorConfigSetMajorCode(ErrorConfig* c, u32 code) {
|
||||
c->major_code = code;
|
||||
void errorConfigSetMajorCode(ErrorConfig* c, u64 code) {
|
||||
*(u64*) &c->args[0x8] = code;
|
||||
}
|
||||
|
||||
void errorConfigSetMinorCode(ErrorConfig* c, u32 code) {
|
||||
c->minor_code = code;
|
||||
void errorConfigSetMinorCode(ErrorConfig* c, u64 code) {
|
||||
*(u64*) &c->args[0xC] = code;
|
||||
}
|
||||
|
||||
void errorConfigSetCustomText(ErrorConfig* c, bool customText) {
|
||||
c->custom_text = customText;
|
||||
c->args[0x0] = customText;
|
||||
}
|
||||
|
||||
void errorConfigSetShortDescription(ErrorConfig* c, const char* str) {
|
||||
free(c->short_description);
|
||||
c->short_description = (char*) malloc(sizeof(char) * (strlen(str) + 1));
|
||||
strcpy(c->short_description, str);
|
||||
strcpy((char*) &c->args[0x18], str);
|
||||
}
|
||||
|
||||
void errorConfigSetDetailedDescription(ErrorConfig* c, const char* str) {
|
||||
free(c->detailed_description);
|
||||
c->detailed_description = (char*) malloc(sizeof(char) * (strlen(str) + 1));
|
||||
strcpy(c->detailed_description, str);
|
||||
strcpy((char*) &c->args[0x818], str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user