Implement error applet (#343)

This commit is contained in:
Kartik 2017-04-04 21:19:37 +05:30 committed by fincs
parent 82049e7fc2
commit 422c3c3272
3 changed files with 145 additions and 1 deletions

View File

@ -74,6 +74,7 @@ extern "C" {
#include <3ds/ndsp/channel.h>
#include <3ds/applets/swkbd.h>
#include <3ds/applets/error.h>
#include <3ds/sdmc.h>
#include <3ds/romfs.h>

View File

@ -0,0 +1,89 @@
/**
* @file error.h
* @brief Error applet.
*/
#pragma once
enum
{
ERROR_LANGUAGE_FLAG = 0x100, ///<??-Unknown flag
ERROR_WORD_WRAP_FLAG = 0x200 ///<??-Unknown flag
};
///< Type of Error applet to be called
typedef enum
{
ERROR_CODE = 0, ///< Displays the infrastructure communications-related error message corresponding to the error code.
ERROR_TEXT, ///< Displays text passed to this applet.
ERROR_EULA, ///< Displays the EULA
ERROR_TYPE_EULA_FIRST_BOOT, ///< Use prohibited.
ERROR_TYPE_EULA_DRAW_ONLY, ///< Use prohibited.
ERROR_TYPE_AGREE, ///< Use prohibited.
ERROR_CODE_LANGUAGE = ERROR_CODE | ERROR_LANGUAGE_FLAG, ///< Displays a network error message in a specified language.
ERROR_TEXT_LANGUAGE = ERROR_TEXT | ERROR_LANGUAGE_FLAG, ///< Displays text passed to this applet in a specified language.
ERROR_EULA_LANGUAGE = ERROR_EULA | ERROR_LANGUAGE_FLAG, ///< Displays EULA in a specified language.
ERROR_TEXT_WORD_WRAP = ERROR_TEXT | ERROR_WORD_WRAP_FLAG,///< Displays the custom error message passed to this applet with automatic line wrapping
ERROR_TEXT_LANGUAGE_WORD_WRAP = ERROR_TEXT | ERROR_LANGUAGE_FLAG | ERROR_WORD_WRAP_FLAG ///< Displays the custom error message with automatic line wrapping and in the specified language.
}errorType;
///< Flags for the Upper Screen.Does nothing even if specified.
typedef enum
{
ERROR_NORMAL = 0,
ERROR_STEREO
}errorScreenFlag;
///< Return code of the Error module.Use UNKNOWN for simple apps.
typedef enum
{
ERROR_UNKNOWN = -1,
ERROR_NONE = 0,
ERROR_SUCCESS,
ERROR_NOT_SUPPORTED,
ERROR_HOME_BUTTON = 10,
ERROR_SOFTWARE_RESET,
ERROR_POWER_BUTTON
}errorReturnCode;
///< Structure to be passed to the applet.Shouldn't be modified directly.
typedef struct
{
errorType errorType;
int errorCode;
errorScreenFlag upperScreenFlag;
u16 useLanguage;
u16 Text[1900];
bool homeButton;
bool softwareReset;
bool appJump;
errorReturnCode returnCode;
u16 eulaVersion;
}errorConf;
/**
* @brief Init the error applet.
* @param err Pointer to errorConf.
* @param type errorType Type of error.
* @param lang CFG_Language Lang of error.
*/
void errorInit(errorConf* err, errorType type, CFG_Language lang);
/**
* @brief Sets error code to display.
* @param err Pointer to errorConf.
* @param error Error-code to display.
*/
void errorCode(errorConf* err, int error);
/**
* @brief Sets error text to display.
* @param err Pointer to errorConf.
* @param text Error-text to display.
*/
void errorText(errorConf* err, const char* text);
/**
* @brief Displays the error applet.
* @param err Pointer to errorConf.
*/
void errorDisp(errorConf* err);

View File

@ -0,0 +1,54 @@
#include <3ds.h>
#include <string.h>
#include <3ds/types.h>
#include <3ds/synchronization.h>
#include <3ds/services/apt.h>
#include <3ds/services/cfgu.h>
#include <3ds/util/utf.h>
#include <3ds/applets/error.h>
void errorInit(errorConf* err, errorType type, CFG_Language lang)
{
memset(err, 0, sizeof(*err));
err->errorType = type;
err->useLanguage = lang;
err->upperScreenFlag = ERROR_NORMAL;
err->eulaVersion = 0;
err->homeButton = true;
err->softwareReset = false;
err->appJump = false;
err->returnCode = ERROR_UNKNOWN;
}
void errorCode(errorConf* err, int error)
{
err->errorCode = error;
}
static void errorConvertToUTF16(u16* out, const char* in, size_t max)
{
if (!in || !*in)
{
out[0] = 0;
return;
}
ssize_t units = utf8_to_utf16(out, (const uint8_t*)in, max-1);
if (units < 0)
{
out[0] = 0;
return;
}
out[units] = 0;
}
void errorText(errorConf *err, const char* text)
{
errorConvertToUTF16(err->Text, text, 1900);
}
void errorDisp(errorConf* err)
{
aptLaunchLibraryApplet(APPID_ERROR, err, sizeof(*err), 0);
}