mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-06 11:22:15 +02:00
Implement error applet
This commit is contained in:
parent
904deeec10
commit
320f17a94f
74
nx/include/switch/applets/error.h
Normal file
74
nx/include/switch/applets/error.h
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* @file error.h
|
||||||
|
* @brief Wrapper for using the error LibraryApplet.
|
||||||
|
* @author StuntHacks
|
||||||
|
* @copyright libnx Authors
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "../types.h"
|
||||||
|
#include "../services/applet.h"
|
||||||
|
|
||||||
|
/// 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".
|
||||||
|
} ErrorConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates an ErrorConfg struct.
|
||||||
|
* @param c ErrorConfg struct.
|
||||||
|
* @note Sets the following fields: majorCode = 2000, minorCode = 0, customText = false, shortDescription = "", detailedDescription = "".
|
||||||
|
*/
|
||||||
|
void errorCreate(ErrorConfig* c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Closes an ErrorConfg struct.
|
||||||
|
* @param c ErrorConfg struct.
|
||||||
|
*/
|
||||||
|
void errorClose(ErrorConfig* c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Launches with the specified config.
|
||||||
|
* @param c ErrorConfig struct
|
||||||
|
*/
|
||||||
|
void errorShow(ErrorConfig* c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the first part of the error code.
|
||||||
|
* @param c ErrorConfig struct
|
||||||
|
* @param code Code.
|
||||||
|
*/
|
||||||
|
void errorConfigSetMajorCode(ErrorConfig* c, u32 code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the second part of the error code.
|
||||||
|
* @param c ErrorConfig struct
|
||||||
|
* @param code Code.
|
||||||
|
*/
|
||||||
|
void errorConfigSetMinorCode(ErrorConfig* c, u32 code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets whether to use a custom error message.
|
||||||
|
* @param c ErrorConfig struct
|
||||||
|
* @param customText Whether to use a custom message.
|
||||||
|
*/
|
||||||
|
void errorConfigSetCustomText(ErrorConfig* c, bool customText);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the short description.
|
||||||
|
* @param c ErrorConfig struct
|
||||||
|
* @param str Description.
|
||||||
|
*/
|
||||||
|
void errorConfigSetShortDescription(ErrorConfig* c, const char* str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the detailed description.
|
||||||
|
* @param c ErrorConfig struct
|
||||||
|
* @param str Description.
|
||||||
|
*
|
||||||
|
* This gets displayed when the user clicks on "Details".
|
||||||
|
*/
|
||||||
|
void errorConfigSetDetailedDescription(ErrorConfig* c, const char* str);
|
76
nx/source/applets/error.cpp
Normal file
76
nx/source/applets/error.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "types.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "services/applet.h"
|
||||||
|
#include "applets/libapplet.h"
|
||||||
|
#include "applets/error.h"
|
||||||
|
|
||||||
|
void errorCreate(ErrorConfig* c) {
|
||||||
|
c->major_code = 2000;
|
||||||
|
c->minor_code = 0;
|
||||||
|
c->custom_text = false;
|
||||||
|
|
||||||
|
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, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void errorClose(ErrorConfig* c) {
|
||||||
|
free(c->short_description);
|
||||||
|
free(c->detailed_description);
|
||||||
|
memset(c, 0, sizeof(ErrorConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
void errorShow(ErrorConfig* c) {
|
||||||
|
AppletHolder err;
|
||||||
|
AppletStorage errStor;
|
||||||
|
LibAppletArgs errArgs;
|
||||||
|
|
||||||
|
appletCreateLibraryApplet(&err, AppletId_error, LibAppletMode_AllForeground);
|
||||||
|
libappletArgsCreate(&errArgs, 1);
|
||||||
|
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);
|
||||||
|
|
||||||
|
appletHolderPushInData(&err, &errStor);
|
||||||
|
|
||||||
|
appletHolderStart(&err);
|
||||||
|
appletHolderJoin(&err);
|
||||||
|
appletHolderClose(&err);
|
||||||
|
}
|
||||||
|
|
||||||
|
void errorConfigSetMajorCode(ErrorConfig* c, u32 code) {
|
||||||
|
c->major_code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void errorConfigSetMinorCode(ErrorConfig* c, u32 code) {
|
||||||
|
c->minor_code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void errorConfigSetCustomText(ErrorConfig* c, bool customText) {
|
||||||
|
c->custom_text = 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user