From e973cceaddf060b3738417504856db1baa4a04fa Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 3 Sep 2018 19:00:14 -0400 Subject: control_metadata: Use alternate language names if AmericanEnglish isn't available --- src/core/file_sys/control_metadata.cpp | 12 +++++++++++- src/core/file_sys/control_metadata.h | 9 ++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src/core/file_sys') diff --git a/src/core/file_sys/control_metadata.cpp b/src/core/file_sys/control_metadata.cpp index ae21ad5b9..e76bf77bf 100644 --- a/src/core/file_sys/control_metadata.cpp +++ b/src/core/file_sys/control_metadata.cpp @@ -21,7 +21,17 @@ NACP::NACP(VirtualFile file) : raw(std::make_unique()) { } const LanguageEntry& NACP::GetLanguageEntry(Language language) const { - return raw->language_entries.at(static_cast(language)); + if (language != Language::Default) { + return raw->language_entries.at(static_cast(language)); + } else { + for (const auto& language_entry : raw->language_entries) { + if (!language_entry.GetApplicationName().empty()) + return language_entry; + } + + // Fallback to English + return GetLanguageEntry(Language::AmericanEnglish); + } } std::string NACP::GetApplicationName(Language language) const { diff --git a/src/core/file_sys/control_metadata.h b/src/core/file_sys/control_metadata.h index 1568046f1..8a510bf46 100644 --- a/src/core/file_sys/control_metadata.h +++ b/src/core/file_sys/control_metadata.h @@ -9,6 +9,7 @@ #include #include "common/common_funcs.h" #include "common/common_types.h" +#include "common/swap.h" #include "core/file_sys/vfs.h" namespace FileSys { @@ -61,6 +62,8 @@ enum class Language : u8 { Korean = 12, Taiwanese = 13, Chinese = 14, + + Default = 255, }; static constexpr std::array LANGUAGE_NAMES = { @@ -75,9 +78,9 @@ static constexpr std::array LANGUAGE_NAMES = { class NACP { public: explicit NACP(VirtualFile file); - const LanguageEntry& GetLanguageEntry(Language language = Language::AmericanEnglish) const; - std::string GetApplicationName(Language language = Language::AmericanEnglish) const; - std::string GetDeveloperName(Language language = Language::AmericanEnglish) const; + const LanguageEntry& GetLanguageEntry(Language language = Language::Default) const; + std::string GetApplicationName(Language language = Language::Default) const; + std::string GetDeveloperName(Language language = Language::Default) const; u64 GetTitleId() const; std::string GetVersionString() const; -- cgit v1.2.3