Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions include/nn/err.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
#pragma once

#include <nn/err/err_ApplicationErrorArg.h>
#include <nn/err/err_ErrorCode.h>
#include <nn/err/err_ErrorMessageDatabaseVersion.h>
#include <nn/err/err_ErrorResultVariant.h>
#include <nn/err/err_ResultBacktrace.h>
#include <nn/err/err_SystemErrorArg.h>
#include <nn/nn_Result.h>
#include <nn/settings.h>
#include <nn/time.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more specific time_* header that can be used?


namespace nn::err {
enum ErrorCodeCategoryType : uint32_t {
unk1,
unk2,
};
class EulaData; // TODO
class ErrorViewerJumpDestination {}; // TODO

class ApplicationErrorArg {
public:
ApplicationErrorArg();
ApplicationErrorArg(uint32_t error_code, const char* dialog_message,
const char* fullscreen_message,
const nn::settings::LanguageCode& languageCode);
void SetApplicationErrorCodeNumber(uint32_t error_code);
void SetDialogMessage(const char* message);
void SetFullScreenMessage(const char* message);

uint64_t unk;
uint32_t error_code;
nn::settings::LanguageCode language_code;
char dialog_message[2048];
char fullscreen_message[2048];
};

uint32_t MakeErrorCode(ErrorCodeCategoryType err_category_type, uint32_t errorCodeNumber);
ErrorCode ConvertResultToErrorCode(const Result& result);
bool CreateErrorViewerStartupParamForRecordedError(void*, std::uint64_t*, std::uint64_t,
const char*, const char*, time::PosixTime);
void ExecuteJump(ErrorViewerJumpDestination destination);
void GetErrorCodeString(char* outErrorCodeString, std::size_t errorCodeStrBufferSize,
ErrorCode errorCode);
void* GetErrorMessageDatabaseVersion(ErrorMessageDatabaseVersion* outVersion);
ErrorCode MakeErrorCode(std::uint32_t category, std::uint32_t number);
void ShowApplicationError(const ApplicationErrorArg& arg);
void ShowError(Result result);
void ShowError(ErrorCode errorCode);
void ShowError(const ErrorResultVariant& errorResultVariant);
void ShowError(Result result, ResultBacktrace& backtrace);
void ShowErrorRecord(Result result, time::PosixTime timestamp);
void ShowErrorRecord(ErrorCode errorCode, time::PosixTime timestamp);
void ShowErrorRecord(const void*, std::uint64_t);
void ShowErrorWithoutJump(Result result);
void ShowErrorWithoutJump(ErrorCode errorCode);
void ShowEula(settings::system::RegionCode regionCode);
void ShowSystemError(const SystemErrorArg& arg);
void ShowSystemUpdateEula(settings::system::RegionCode regionCode, EulaData& data);
void ShowUnacceptableAddOnContentVersionError();
void ShowUnacceptableApplicationVersionError();
} // namespace nn::err
8 changes: 8 additions & 0 deletions include/nn/err/detail/err_MessageKind.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <cstdint>

namespace nn::err::detail {
// What does Flv stand for?
enum class MessageKind : std::uint8_t { DialogueMessage, DialogueButton, FlvMessage, FlvButton };
} // namespace nn::err::detail
31 changes: 31 additions & 0 deletions include/nn/err/err_ApplicationErrorArg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <nn/settings.h>

namespace nn::err {
class ApplicationErrorArg {
public:
ApplicationErrorArg();
ApplicationErrorArg(std::uint32_t errorCode, const char* dialogMessage,
const char* fullScreenMessage, const settings::LanguageCode& languageCode);

std::uint32_t GetApplicationErrorCodeNumber() const;
const char* GetDialogMessage() const;
const char* GetFullScreenMessage() const;
settings::LanguageCode GetLanguageCode() const;

void SetApplicationErrorCodeNumber(std::uint32_t errorCode);
void SetDialogMessage(const char* message);
void SetFullScreenMessage(const char* message);
void SetLanguageCode(const settings::LanguageCode& languageCode);

private:
std::int8_t _0 = 2;
std::int8_t _1 = 1;
std::int8_t padding[6];
std::uint32_t m_ErrorCode = 0;
settings::LanguageCode m_LanguageCode;
char m_DialogMessage[2048];
char m_FullScreenMessage[2048];
};
} // namespace nn::err
23 changes: 23 additions & 0 deletions include/nn/err/err_ErrorCode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <cstdint>

namespace nn::err {
class ErrorCode {
public:
static ErrorCode GetInvalidErrorCode();

ErrorCode() {}
ErrorCode(std::uint32_t category, std::uint32_t number)
: m_Category(category), m_Number(number) {}

bool IsValid() const;

std::uint32_t GetCategory() const { return m_Category; }
std::uint32_t GetNumber() const { return m_Number; }

private:
std::uint32_t m_Category = 0;
std::uint32_t m_Number = 0;
};
} // namespace nn::err
13 changes: 13 additions & 0 deletions include/nn/err/err_ErrorMessageDatabaseVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <cstdint>

namespace nn::err {
class ErrorMessageDatabaseVersion {
public:
private:
std::int32_t m_Version;
};

static_assert(sizeof(ErrorMessageDatabaseVersion) == 4);
} // namespace nn::err
34 changes: 34 additions & 0 deletions include/nn/err/err_ErrorResultVariant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <nn/err/err_ErrorCode.h>
#include <nn/nn_Result.h>

namespace nn::err {
class ErrorResultVariant {
public:
enum class State : std::uint32_t {
Undefined,
Result,
ErrorCode,
};

ErrorResultVariant();
ErrorResultVariant(const Result& result);
ErrorResultVariant(const ErrorCode& errorCode);

State GetState() const;

operator ErrorCode() const;
operator Result() const;

ErrorResultVariant& operator=(const Result& result);
ErrorResultVariant& operator=(const ErrorCode& errorCode);

private:
State m_State = State::Undefined;
union {
Result m_Result;
ErrorCode m_ErrorCode;
} m_Value;
};
} // namespace nn::err
13 changes: 13 additions & 0 deletions include/nn/err/err_ResultBacktrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <nn/nn_Result.h>

namespace nn::err {
class ResultBacktrace {
public:
static void Make(ResultBacktrace* outBackTrace, const Result*, std::int32_t);

private:
// TODO
};
} // namespace nn::err
37 changes: 37 additions & 0 deletions include/nn/err/err_SystemErrorArg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <nn/err/err_ErrorCode.h>
#include <nn/settings.h>

namespace nn::err {
class SystemErrorArg {
public:
SystemErrorArg();
SystemErrorArg(ErrorCode errorCode, const char* dialogMessage, const char* fullScreenMessage,
const settings::LanguageCode& languageCode);

void SetErrorCode(ErrorCode errorCode);
void SetDialogMessage(const char* message);
void SetFullScreenMessage(const char* message);
void SetLanguageCode(const settings::LanguageCode& languageCode);
ErrorCode GetErrorCode() const;
const char* GetDialogMessage() const;
const char* GetFullScreenMessage() const;
settings::LanguageCode GetLanguageCode() const;
void GetStartupParam() const;

private:
std::int8_t _0 = 1;
std::int8_t _1 = 0;
std::int8_t _2 = 0;
std::int8_t _3 = 0;
std::int8_t _4 = 0;
std::int8_t _5 = 0;
std::int8_t _6 = 0;
std::int8_t _7 = 0;
ErrorCode m_ErrorCode;
settings::LanguageCode m_LanguageCode;
char m_DialogMessage[2048];
char m_FullScreenMessage[2048];
};
} // namespace nn::err
60 changes: 60 additions & 0 deletions include/nn/err/err_detail.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include <nn/err.h>
#include <nn/err/detail/err_MessageKind.h>
#include <nn/err/err_ErrorCode.h>
#include <nn/settings.h>

namespace nn::ns {
// TODO: move
class ApplicationErrorCodeCategory {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what header should this be moved to? Prefer to define the class in the right header instead of at where it's used, so people don't duplicate the definitions later.

public:
const char* GetCategory() const { return m_Category; }

private:
char m_Category[8];
};
} // namespace nn::ns

namespace nn::err {
class ErrorMessageDatabaseVersion;
} // namespace nn::err

namespace nn::err::detail {
bool CategoryExists(std::uint32_t category);
bool DefaultErrorMessageDataExists(std::uint32_t category);
bool ErrorMessageDataExists(ErrorCode errorCode);
bool IsApplicationErrorCodeString(const char* errorCodeString);
void MakeApplicationErrorCodeString(
char* outErrorCodeString, std::size_t errorCodeStringBufferSize,
const ns::ApplicationErrorCodeCategory& applicationErrorCodeCategory,
std::uint32_t errorCodeNumber);
void MakeErrorCodeString(char* outErrorCodeString, std::size_t errorCodeStringBufferSize,
ErrorCode errorCode);
void MakeErrorInfoCommonFilePath(char* outErrorInfoCommonFilePath,
std::size_t errorInfoCommonFilePathBufferSize,
ErrorCode errorCode);
void MakeErrorInfoDirectoryPath(char* outErrorInfoDirectoryPath,
std::size_t errorInfoDirectoryPathBufferSize, ErrorCode errorCode);
void MakeErrorInfoMessageFilePath(char* outErrorInfoMessageFilePath,
std::size_t errorInfoMessageFilePathBufferSize,
ErrorCode errorCode, settings::LanguageCode languageCode,
MessageKind messageKind);
void MakeErrorInfoModuleDirectoryPath(char* outErrorInfoModuleDirectoryPath,
std::size_t errorInfoModuleDirectoryPathBufferSize,
std::uint32_t errorCodeCategory);
void ParseApplicationErrorCodeString(
ns::ApplicationErrorCodeCategory* outApplicationErrorCodeCategory,
std::uint32_t* outErrorCodeCategoryNumber, const char* errorCodeString);
void ParseErrorCodeString(ErrorCode* outErrorCode, const char* errorCodeString);
void* ReadMessageFile(char16_t* outBuffer, std::int32_t* outMessageLength,
std::size_t messageBufferSize, ErrorCode errorCode,
settings::LanguageCode languageCode, MessageKind messageKind);
void ReadMessageFile(char16_t* outBuffer, std::size_t bufferSize, const char* errorCodeString,
const settings::LanguageCode& languageCode);
void ReadVersion(ErrorMessageDatabaseVersion* outVersion);
bool TryParseApplicationErrorCodeString(
ns::ApplicationErrorCodeCategory* outApplicationErrorCodeCategory,
std::uint32_t* outErrorCodeCategoryNumber, const char* errorCodeString);
bool TryParseErrorCodeString(ErrorCode* outErrorCode, const char* errorCodeString);
} // namespace nn::err::detail
5 changes: 5 additions & 0 deletions include/nn/fs/fs_Mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <nn/fs/fs_Types.h>
#include <nn/nn_Result.h>

namespace nn::ncm {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be moved to nn/ncm/ncm_Something.h?

enum class SystemDataId : std::uint64_t { Err = 0x10000000000801 }; // TODO: move
} // namespace nn::ncm

namespace nn::fs {

/*
Expand All @@ -12,6 +16,7 @@ namespace nn::fs {
bool MountSdCardForDebug(const char* mount);

Result MountSdCard(const char* mountPoint);
Result MountSystemData(const char* mountPoint, ncm::SystemDataId id);
bool IsSdCardInserted();
Result FormatSdCard();
Result FormatSdCardDryRun();
Expand Down
4 changes: 4 additions & 0 deletions include/nn/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ struct FirmwareVersion {
}
};

struct RegionCode {
std::int32_t code;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been using int32_t from cstdint (without the std:: prefix) throughout the code base, everywhere else in the PR too

};

Result GetFirmwareVersion(FirmwareVersion*);
} // namespace system

Expand Down
23 changes: 17 additions & 6 deletions include/vapours/results/results_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ namespace nn {
static BaseType GetDescriptionFromValue(BaseType value) noexcept {
return GetBitsValue(value, ModuleBits, DescriptionBits);
}

static BaseType GetInnerValue(BaseType value) noexcept {
return GetBitsValue(value, 0, ModuleBits + DescriptionBits);
}
};

/* Use CRTP for Results. */
Expand All @@ -64,12 +68,16 @@ namespace nn {
using BaseType = typename ResultTraits::BaseType;
static const BaseType SuccessValue = ResultTraits::SuccessValue;

int GetModule() const noexcept {
return static_cast<int>(ResultTraits::GetModuleFromValue(static_cast<const Self &>(*this).GetInnerValueForDebug()));
__attribute__((always_inline)) BaseType GetModule() const noexcept {
return ResultTraits::GetModuleFromValue(static_cast<const Self &>(*this).GetInnerValueForDebug());
}

__attribute__((always_inline)) BaseType GetDescription() const noexcept {
return ResultTraits::GetDescriptionFromValue(static_cast<const Self &>(*this).GetInnerValueForDebug());
}

int GetDescription() const noexcept {
return static_cast<int>(ResultTraits::GetDescriptionFromValue(static_cast<const Self &>(*this).GetInnerValueForDebug()));
__attribute__((always_inline)) BaseType GetValue() const noexcept {
return ResultTraits::GetInnerValue(static_cast<const Self&>(*this).GetInnerValueForDebug());
}
};

Expand All @@ -95,11 +103,14 @@ namespace nn {
bool IsSuccess() const noexcept { return m_value == SuccessValue; }
bool IsFailure() const noexcept { return !IsSuccess(); }

bool operator==(Result other) const noexcept { return GetValue() == other.GetValue(); }
bool operator!=(Result other) const noexcept { return !operator==(other); }
operator ResultSuccess() const noexcept;
static bool CanAccept(Result result) noexcept;

int GetModule() const noexcept { return Base::GetModule(); }
int GetDescription() const noexcept { return Base::GetDescription(); }
__attribute__((always_inline)) BaseType GetModule() const noexcept { return Base::GetModule(); }
__attribute__((always_inline)) BaseType GetDescription() const noexcept { return Base::GetDescription(); }
__attribute__((always_inline)) BaseType GetValue() const noexcept { return Base::GetValue(); }
};
static_assert(sizeof(Result) == sizeof(result::detail::ResultTraits::BaseType), "sizeof(Result) == sizeof(detail::ResultTraits::BaseType)");
static_assert(std::is_trivially_destructible<Result>::value, "std::is_trivially_destructible<Result>::value");
Expand Down
Loading