Added a fallback title based on codeset info

This commit is contained in:
zhupengfei
2020-05-15 22:34:39 +08:00
parent 1415235a13
commit 450cef3fca
3 changed files with 41 additions and 4 deletions
+20 -4
View File
@@ -404,19 +404,35 @@ static bool LoadTMD(const std::string& sdmc_path, const std::string& path, SDMCD
}
// English short title name, extdata id, encryption, seed, icon
using TitleData = std::tuple<std::string, u64, EncryptionType, bool, std::vector<u16>>;
template <typename File>
std::tuple<std::string, u64, EncryptionType, bool, std::vector<u16>> LoadTitleData(
NCCHContainer<File>& ncch) {
TitleData LoadTitleData(NCCHContainer<File>& ncch) {
std::string codeset_name;
ncch.ReadCodesetName(codeset_name);
u64 program_id{};
ncch.ReadProgramId(program_id);
std::string title_name_from_codeset;
if (!codeset_name.empty()) {
title_name_from_codeset =
fmt::format("{} (0x{:016x})", std::move(codeset_name), program_id);
}
std::vector<u8> smdh_buffer;
if (ncch.LoadSectionExeFS("icon", smdh_buffer) != ResultStatus::Success) {
LOG_WARNING(Core, "Failed to load icon in ExeFS");
return {};
TitleData data{};
std::get<0>(data) = std::move(title_name_from_codeset);
return data;
}
if (smdh_buffer.size() != sizeof(SMDH)) {
LOG_ERROR(Core, "ExeFS icon section size is not correct");
return {};
TitleData data{};
std::get<0>(data) = std::move(title_name_from_codeset);
return data;
}
SMDH smdh;
+15
View File
@@ -374,6 +374,21 @@ bool NCCHContainer<File>::HasExHeader() {
return has_exheader;
}
template <typename File>
ResultStatus NCCHContainer<File>::ReadCodesetName(std::string& name) {
ResultStatus result = Load();
if (result != ResultStatus::Success)
return result;
if (!has_exheader)
return ResultStatus::ErrorNotUsed;
std::array<char, 9> name_data{};
std::memcpy(name_data.data(), exheader_header.codeset_info.name, 8);
name = name_data.data();
return ResultStatus::Success;
}
template <typename File>
ResultStatus NCCHContainer<File>::ReadEncryptionType(EncryptionType& encryption) {
ResultStatus result = Load();
+6
View File
@@ -250,6 +250,12 @@ public:
*/
bool HasExHeader();
/**
* Reads the name of the codeset.
* @return ResultStatus result of function.
*/
ResultStatus ReadCodesetName(std::string& name);
/**
* Gets encryption type (which key is used).
* @return ResultStatus result of function.