From 3629f0029f0b4380f0f3226a2c08a17d60a48964 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sun, 13 Jun 2021 20:47:49 -0400 Subject: [PATCH] GameCardTab: display table with gamecard properties. --- include/core/gamecard.h | 3 +- include/gamecard_tab.hpp | 10 +++++ romfs/i18n/en-US/gamecard_tab.json | 14 +++++++ source/gamecard_tab.cpp | 62 ++++++++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/include/core/gamecard.h b/include/core/gamecard.h index ee107a3..7d6f6e5 100644 --- a/include/core/gamecard.h +++ b/include/core/gamecard.h @@ -137,7 +137,8 @@ typedef enum { typedef enum { GameCardCompatibilityType_Normal = 0, - GameCardCompatibilityType_Terra = 1 + GameCardCompatibilityType_Terra = 1, + GameCardCompatibilityType_Count = 2 } GameCardCompatibilityType; /// Encrypted using AES-128-CBC with the XCI header key (found in FS program memory under HOS 9.0.0+) and the IV from `GameCardHeader`. diff --git a/include/gamecard_tab.hpp b/include/gamecard_tab.hpp index 4b48f04..b56ee5a 100644 --- a/include/gamecard_tab.hpp +++ b/include/gamecard_tab.hpp @@ -39,6 +39,16 @@ namespace nxdt::views ErrorFrame *error_frame = nullptr; brls::List *list = nullptr; + + brls::Table *properties_table = nullptr; + brls::TableRow *capacity = nullptr; + brls::TableRow *total_size = nullptr; + brls::TableRow *trimmed_size = nullptr; + brls::TableRow *update_version = nullptr; + brls::TableRow *lafw_version = nullptr; + brls::TableRow *sdk_version = nullptr; + brls::TableRow *compatibility_type = nullptr; + brls::ListItem *dump_card_image = nullptr; brls::ListItem *dump_certificate = nullptr; brls::ListItem *dump_header = nullptr; diff --git a/romfs/i18n/en-US/gamecard_tab.json b/romfs/i18n/en-US/gamecard_tab.json index 71d8e64..a5e9a51 100644 --- a/romfs/i18n/en-US/gamecard_tab.json +++ b/romfs/i18n/en-US/gamecard_tab.json @@ -8,6 +8,20 @@ }, "list": { + "properties_table": { + "header": "Gamecard properties", + "capacity": "Capacity", + "total_size": "Total size", + "trimmed_size": "Trimmed size", + "update_version": "Bundled update version", + "lafw_version": "Required Lotus ASIC firmware version", + "lafw_version_value": "%lu or greater", + "sdk_version": "SDK version", + "compatibility_type": "Compatibility type" + }, + + "dump_options": "Dump options", + "dump_card_image": { "label": "Dump gamecard image", "description": "Generates a raw gamecard image. This is the option most people will want to use." diff --git a/source/gamecard_tab.cpp b/source/gamecard_tab.cpp index 1f769be..4b4b0a7 100644 --- a/source/gamecard_tab.cpp +++ b/source/gamecard_tab.cpp @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -#include +#include #include namespace i18n = brls::i18n; /* For getStr(). */ @@ -27,15 +27,36 @@ using namespace i18n::literals; /* For _i18n. */ namespace nxdt::views { + static const char *GameCardCompatibilityTypeStrings[GameCardCompatibilityType_Count] = { + [GameCardCompatibilityType_Normal] = "Normal", + [GameCardCompatibilityType_Terra] = "Terra" + }; + GameCardTab::GameCardTab(nxdt::tasks::GameCardTask *gc_status_task) : brls::LayerView(), gc_status_task(gc_status_task) { - /* Add error frame. */ + /* Error frame. */ this->error_frame = new ErrorFrame("gamecard_tab/error_frame/not_inserted"_i18n); this->addLayerWrapper(this->error_frame); - /* Add list. */ + /* List. */ this->list = new brls::List(); + /* Gamecard properties table. */ + this->list->addView(new brls::Header("gamecard_tab/list/properties_table/header"_i18n)); + + this->properties_table = new brls::Table(); + this->capacity = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/capacity"_i18n); + this->total_size = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/total_size"_i18n); + this->trimmed_size = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/trimmed_size"_i18n); + this->update_version = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/update_version"_i18n); + this->lafw_version = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/lafw_version"_i18n); + this->sdk_version = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/sdk_version"_i18n); + this->compatibility_type = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/compatibility_type"_i18n); + this->list->addView(this->properties_table); + + /* ListItem elements. */ + this->list->addView(new brls::Header("gamecard_tab/list/dump_options"_i18n)); + this->dump_card_image = new brls::ListItem("gamecard_tab/list/dump_card_image/label"_i18n, "gamecard_tab/list/dump_card_image/description"_i18n); this->list->addView(this->dump_card_image); @@ -78,8 +99,43 @@ namespace nxdt::views this->error_frame->SetMessage(i18n::getStr("gamecard_tab/error_frame/info_not_loaded"_i18n, GITHUB_NEW_ISSUE_URL)); break; case GameCardStatus_InsertedAndInfoLoaded: + { + u64 size = 0; + GameCardInfo card_info = {0}; + char strbuf[0x100] = {0}; + + gamecardGetRomCapacity(&size); + utilsGenerateFormattedSizeString(size, strbuf, sizeof(strbuf)); + this->capacity->setValue(std::string(strbuf)); + + gamecardGetTotalSize(&size); + utilsGenerateFormattedSizeString(size, strbuf, sizeof(strbuf)); + this->total_size->setValue(std::string(strbuf)); + + gamecardGetTrimmedSize(&size); + utilsGenerateFormattedSizeString(size, strbuf, sizeof(strbuf)); + this->trimmed_size->setValue(std::string(strbuf)); + + gamecardGetDecryptedCardInfoArea(&card_info); + + snprintf(strbuf, sizeof(strbuf), "%u.%u.%u-%u.%u (v%u)", card_info.upp_version.major, card_info.upp_version.minor, card_info.upp_version.micro, \ + card_info.upp_version.major_relstep, card_info.upp_version.minor_relstep, card_info.upp_version.value); + this->update_version->setValue(std::string(strbuf)); + + snprintf(strbuf, sizeof(strbuf), "gamecard_tab/list/properties_table/lafw_version_value"_i18n.c_str(), card_info.fw_version + 1); + this->lafw_version->setValue(std::string(strbuf)); + + snprintf(strbuf, sizeof(strbuf), "%u.%u.%u-%u (v%u)", card_info.fw_mode.major, card_info.fw_mode.minor, card_info.fw_mode.micro, card_info.fw_mode.relstep, card_info.fw_mode.value); + this->sdk_version->setValue(std::string(strbuf)); + + snprintf(strbuf, sizeof(strbuf), "%s (%u)", \ + card_info.compatibility_type >= GameCardCompatibilityType_Count ? "Unknown" : GameCardCompatibilityTypeStrings[card_info.compatibility_type], card_info.compatibility_type); + this->compatibility_type->setValue(std::string(strbuf)); + this->changeLayerWrapper(this->list); + break; + } default: break; }