Improved error-applet launching handling. Updated ErrorConfig and added ErrorContext.

This commit is contained in:
yellows8 2019-03-23 17:33:14 -04:00
parent ecfc8f8966
commit 9bf699f712
2 changed files with 69 additions and 17 deletions

View File

@ -1,24 +1,28 @@
/** /**
* @file error.h * @file error.h
* @brief Wrapper for using the error LibraryApplet. * @brief Wrapper for using the error LibraryApplet.
* @author StuntHacks * @author StuntHacks, yellows8
* @copyright libnx Authors * @copyright libnx Authors
*/ */
#pragma once #pragma once
#include "../types.h" #include "../types.h"
#include "../services/applet.h" #include "../services/applet.h"
/// Error configuration struct /// Error configuration struct (SystemErrorArg)
typedef struct { typedef struct {
u8 custom_text; ///< Whether to show a custom error message. If this is false, a default message will be shown. u8 custom_text; ///< Whether to show a custom error message. If this is false, a default message will be shown.
u8 unk[7]; u8 unk[7];
u32 module; ///< Module code. u32 module; ///< Module code.
u32 description; ///< Description code. u32 description; ///< Description code.
u8 unk2[8]; u64 languageCode;
char short_description[0x800]; ///< Short description. char short_description[0x800]; ///< Short description.
char detailed_description[0x800]; ///< Detailed description (displayed when the user clicks, on "Details"). char detailed_description[0x800]; ///< Detailed description (displayed when the user clicks, on "Details").
} ErrorConfig; } ErrorConfig;
typedef struct {
u8 unk_x0[0x200];
} ErrorContext;
/** /**
* @brief Creates an ErrorConfg struct. * @brief Creates an ErrorConfg struct.
* @param c ErrorConfg struct. * @param c ErrorConfg struct.
@ -37,7 +41,7 @@ void errorClose(ErrorConfig* c);
* @brief Launches with the specified config. * @brief Launches with the specified config.
* @param c ErrorConfig struct. * @param c ErrorConfig struct.
*/ */
void errorShow(ErrorConfig* c); Result errorShow(ErrorConfig* c);
/** /**
* @brief Sets the error module. * @brief Sets the error module.

View File

@ -6,6 +6,64 @@
#include "applets/libapplet.h" #include "applets/libapplet.h"
#include "applets/error.h" #include "applets/error.h"
static Result _errorAppletCreate(AppletHolder* holder, const void* indata, size_t insize, const void* indata2, size_t insize2) {
Result rc=0;
LibAppletArgs commonargs;
rc = appletCreateLibraryApplet(holder, AppletId_error, LibAppletMode_AllForeground);
if (R_FAILED(rc)) return rc;
libappletArgsCreate(&commonargs, 0);
if (R_SUCCEEDED(rc)) rc = libappletArgsPush(&commonargs, holder);
if (R_SUCCEEDED(rc)) rc = libappletPushInData(holder, indata, insize);
if (R_SUCCEEDED(rc) && indata2 && insize2) rc = libappletPushInData(holder, indata2, insize2);
return rc;
}
static Result _errorRun(AppletHolder* holder) {
Result rc=0;
u8 reply[2]={0};
size_t transfer_size = 0;
u8 status=0;//Official sw doesn't use the output status.
if (R_SUCCEEDED(rc)) rc = appletHolderStart(holder);
if (R_SUCCEEDED(rc)) {
appletHolderJoin(holder);
LibAppletExitReason reason = appletHolderGetExitReason(holder);
if (reason == LibAppletExitReason_Normal) {
if (R_SUCCEEDED(libappletPopOutData(holder, reply, sizeof(reply), &transfer_size))) {
if (transfer_size != sizeof(reply)) rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit);
if (R_SUCCEEDED(rc)) status = reply[1];
}
}
else if (reason == LibAppletExitReason_Canceled) {
status = 0;
}
else {
rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit);
}
if (R_SUCCEEDED(rc) && status!=0) rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit);
}
return rc;
}
static Result _errorShow(const void* indata, size_t insize, const void* indata2, size_t insize2) {
Result rc=0;
AppletHolder holder;
rc = _errorAppletCreate(&holder, indata, insize, indata2, insize2);
if (R_SUCCEEDED(rc)) rc = _errorRun(&holder);
appletHolderClose(&holder);
return rc;
}
void errorCreate(ErrorConfig* c) { void errorCreate(ErrorConfig* c) {
memset(c, 0, sizeof(ErrorConfig)); memset(c, 0, sizeof(ErrorConfig));
c->custom_text = false; c->custom_text = false;
@ -16,18 +74,8 @@ void errorClose(ErrorConfig* c) {
memset(c, 0, sizeof(ErrorConfig)); memset(c, 0, sizeof(ErrorConfig));
} }
void errorShow(ErrorConfig* c) { Result errorShow(ErrorConfig* c) {
AppletHolder err; return _errorShow(c, sizeof(ErrorConfig), NULL, 0);
LibAppletArgs errArgs;
appletCreateLibraryApplet(&err, AppletId_error, LibAppletMode_AllForeground);
libappletArgsCreate(&errArgs, 1);
libappletArgsPush(&errArgs, &err);
libappletPushInData(&err, c, sizeof(ErrorConfig));
appletHolderStart(&err);
appletHolderJoin(&err);
appletHolderClose(&err);
} }
void errorConfigSetModule(ErrorConfig* c, u32 code) { void errorConfigSetModule(ErrorConfig* c, u32 code) {