From 46b17521a7d5ad85005b32c42729622c81c96f63 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Sat, 20 Mar 2021 17:49:39 -0500 Subject: [PATCH] Use system fonts for Chinese --- Universal-Core | 2 +- include/utils/config.hpp | 6 +----- source/init.cpp | 26 +++++++++++++++--------- source/main.cpp | 16 ++++++++++++--- source/menu/settings.cpp | 43 +++++++++++++++++++++++++--------------- source/utils/config.cpp | 15 +++----------- source/utils/lang.cpp | 4 ++-- 7 files changed, 64 insertions(+), 48 deletions(-) diff --git a/Universal-Core b/Universal-Core index 1275935..bb168fd 160000 --- a/Universal-Core +++ b/Universal-Core @@ -1 +1 @@ -Subproject commit 12759353de264a22f40beedd9dfbea718bbe30c8 +Subproject commit bb168fdab1cb6a8aee1bd7fbd6e2c29ed3f87a1b diff --git a/include/utils/config.hpp b/include/utils/config.hpp index 344f898..08cae17 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -86,10 +86,6 @@ public: bool customfont() const { return this->v_customFont; }; void customfont(bool v) { this->v_customFont = v; if (!this->changesMade) this->changesMade = true; }; - /* The most recently downloaded language font */ - std::string downloadedFont() const { return this->v_downloadedFont; }; - void downloadedFont(const std::string &v) { this->v_downloadedFont = v; if (!this->changesMade) this->changesMade = true; }; - /* The shortcut path. */ std::string shortcut() const { return this->v_shortcutPath; }; void shortcut(const std::string &v) { this->v_shortcutPath = v; if (!this->changesMade) this->changesMade = true; }; @@ -119,7 +115,7 @@ private: int v_theme = 0; - std::string v_language = "en", v_lastStore = "universal-db.unistore", v_downloadedFont = "", + std::string v_language = "en", v_lastStore = "universal-db.unistore", v_3dsxPath = "sdmc:/3ds", v_ndsPath = "sdmc:", v_archivePath = "sdmc:", v_shortcutPath = "sdmc:/3ds/Universal-Updater/shortcuts", v_firmPath = "sdmc:/luma/payloads"; diff --git a/source/init.cpp b/source/init.cpp index 47e1d70..ce1f5ed 100644 --- a/source/init.cpp +++ b/source/init.cpp @@ -118,21 +118,12 @@ void Init::UnloadFont() { Result Init::Initialize() { gfxInitDefault(); romfsInit(); - u8 region; - CFGU_SecureInfoGetRegion(®ion); - Gui::init((CFG_Region)region); cfguInit(); ptmuInit(); amInit(); acInit(); - APT_GetAppCpuTimeLimit(&old_time_limit); - APT_SetAppCpuTimeLimit(30); // Needed for QR Scanner to work. - getCurrentUsage(); - aptSetSleepAllowed(false); - hidSetRepeatParameters(20, 8); - /* Create Directories, if missing. */ mkdir("sdmc:/3ds", 0777); mkdir("sdmc:/3ds/Universal-Updater", 0777); @@ -140,6 +131,23 @@ Result Init::Initialize() { mkdir("sdmc:/3ds/Universal-Updater/shortcuts", 0777); config = std::make_unique(); + + CFG_Region region = CFG_REGION_USA; + if(config->language() == "zh-CN") { + region = CFG_REGION_CHN; + } else if(config->language() == "zh-TW") { + region = CFG_REGION_TWN; + } else if(config->language() == "ko") { + region = CFG_REGION_KOR; + } + Gui::init(region); + + APT_GetAppCpuTimeLimit(&old_time_limit); + APT_SetAppCpuTimeLimit(30); // Needed for QR Scanner to work. + getCurrentUsage(); + aptSetSleepAllowed(false); + hidSetRepeatParameters(20, 8); + GFX::SelectedTheme = config->theme(); if (GFX::SelectedTheme > (_THEME_AMOUNT - 1)) GFX::SelectedTheme = 0; // In case it is above the max themes. Lang::load(config->language()); diff --git a/source/main.cpp b/source/main.cpp index b98fdda..a48a4e0 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -37,10 +37,8 @@ std::string _3dsxPath = ""; static void InitForARG() { gfxInitDefault(); romfsInit(); + cfguInit(); - u8 region; - CFGU_SecureInfoGetRegion(®ion); - Gui::init((CFG_Region)region); amInit(); acInit(); @@ -50,6 +48,18 @@ static void InitForARG() { mkdir("sdmc:/3ds/Universal-Updater/stores", 0777); mkdir("sdmc:/3ds/Universal-Updater/shortcuts", 0777); + config = std::make_unique(); + + CFG_Region region = CFG_REGION_USA; + if(config->language() == "zh-CN") { + region = CFG_REGION_CHN; + } else if(config->language() == "zh-TW") { + region = CFG_REGION_TWN; + } else if(config->language() == "ko") { + region = CFG_REGION_KOR; + } + Gui::init(region); + config = std::make_unique(); GFX::SelectedTheme = config->theme(); if (GFX::SelectedTheme > (_THEME_AMOUNT - 1)) GFX::SelectedTheme = 0; // In case it is above the max themes. diff --git a/source/menu/settings.cpp b/source/menu/settings.cpp index 1ea2d5f..4c8267e 100644 --- a/source/menu/settings.cpp +++ b/source/menu/settings.cpp @@ -577,17 +577,24 @@ static void LanguageLogic(int &page, int &selection, int &sPos) { const std::string l = langsTemp[selection]; /* Check if language needs a custom font. */ - u8 region; - CFGU_SecureInfoGetRegion(®ion); - if (l == "uk" || (l == "zh-CN" && region != CFG_REGION_CHN) || (l == "zh-TW" && region != CFG_REGION_TWN)) { - if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0 || config->downloadedFont() != l) { - ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + l + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true); - config->downloadedFont(l); + if (l == "uk") { + if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0) { + ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/universal-updater.bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true); Init::UnloadFont(); } config->customfont(true); Init::LoadFont(); + } else if(!config->customfont()) { + CFG_Region region = CFG_REGION_USA; + if(l == "zh-CN") { + region = CFG_REGION_CHN; + } else if(l == "zh-TW") { + region = CFG_REGION_TWN; + } else if(l == "ko") { + region = CFG_REGION_KOR; + } + Gui::loadSystemFont(region); } config->language(l); @@ -604,17 +611,24 @@ static void LanguageLogic(int &page, int &selection, int &sPos) { const std::string l = langsTemp[i + sPos]; /* Check if language needs a custom font. */ - u8 region; - CFGU_SecureInfoGetRegion(®ion); - if (l == "uk" || (l == "zh-CN" && region != CFG_REGION_CHN) || (l == "zh-TW" && region != CFG_REGION_TWN)) { - if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0 || config->downloadedFont() != l) { - ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + l + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true); - config->downloadedFont(l); + if (l == "uk") { + if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0) { + ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/universal-updater.bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true); Init::UnloadFont(); } config->customfont(true); Init::LoadFont(); + } else if(!config->customfont()) { + CFG_Region region = CFG_REGION_USA; + if(l == "zh-CN") { + region = CFG_REGION_CHN; + } else if(l == "zh-TW") { + region = CFG_REGION_TWN; + } else if(l == "ko") { + region = CFG_REGION_KOR; + } + Gui::loadSystemFont(region); } config->language(l); @@ -631,10 +645,7 @@ static void LanguageLogic(int &page, int &selection, int &sPos) { if (touching(touch, langButtons[6])) { /* Download Font. */ std::string l = config->language(); - if(l != "uk" && l != "zh-CN" && l != "zh-TW") - l = "uk"; - ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + l + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true); - config->downloadedFont(l); + ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/universal-updater.bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true); config->customfont(true); Init::UnloadFont(); Init::LoadFont(); diff --git a/source/utils/config.cpp b/source/utils/config.cpp index 0166b58..66f275c 100644 --- a/source/utils/config.cpp +++ b/source/utils/config.cpp @@ -27,7 +27,6 @@ #include "common.hpp" #include "config.hpp" #include "json.hpp" -#include "scriptUtils.hpp" #include #include @@ -118,6 +117,9 @@ Config::Config() { /* Let us create a new one. */ if (!this->json.contains("Version")) this->initialize(); + if (!this->json.contains("Language")) this->sysLang(); + else this->language(this->getString("Language")); + if (this->json.contains("LastStore")) this->lastStore(this->getString("LastStore")); if (this->json.contains("List")) this->list(this->getBool("List")); if (this->json.contains("AutoUpdate")) this->autoupdate(this->getBool("AutoUpdate")); @@ -130,21 +132,11 @@ Config::Config() { if (this->json.contains("UpdateCheck")) this->updatecheck(this->getBool("UpdateCheck")); if (this->json.contains("UseBG")) this->usebg(this->getBool("UseBG")); if (this->json.contains("CustomFont")) this->customfont(this->getBool("CustomFont")); - if (this->json.contains("DownloadedFont")) this->downloadedFont(this->getString("DownloadedFont")); if (this->json.contains("Shortcut_Path")) this->shortcut(this->getString("Shortcut_Path")); if (this->json.contains("Display_Changelog")) this->changelog(this->getBool("Display_Changelog")); if (this->json.contains("Active_Theme")) this->theme(this->getInt("Active_Theme")); if (this->json.contains("Prompt")) this->prompt(this->getBool("Prompt")); - if (!this->json.contains("Language")) { - this->sysLang(); - if((this->language() == "zh-CN" || this->language() == "zh-TW") && (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0 || this->downloadedFont() != this->language())) { - ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + this->language() + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", "Downloading compatible font...", true); - this->downloadedFont(this->language()); - this->customfont(true); - } - } else this->language(this->getString("Language")); - this->changesMade = false; // No changes made yet. } @@ -168,7 +160,6 @@ void Config::save() { this->setBool("UpdateCheck", this->updatecheck()); this->setBool("UseBG", this->usebg()); this->setBool("CustomFont", this->customfont()); - this->setString("DownloadedFont", this->downloadedFont()); this->setString("Shortcut_Path", this->shortcut()); this->setBool("Display_Changelog", this->changelog()); this->setInt("Active_Theme", this->theme()); diff --git a/source/utils/lang.cpp b/source/utils/lang.cpp index 5a7cd46..bdc6ceb 100644 --- a/source/utils/lang.cpp +++ b/source/utils/lang.cpp @@ -41,13 +41,13 @@ void Lang::load(const std::string &lang) { /* Check if exist. */ if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0) { - values = fopen(std::string(("romfs:/lang/" + lang + "/app.json")).c_str(), "rt"); + values = fopen(("romfs:/lang/" + lang + "/app.json").c_str(), "rt"); appJson = nlohmann::json::parse(values, nullptr, false); fclose(values); return; } else { - values = fopen(("romfs:/lang/en/app.json"), "rt"); + values = fopen("romfs:/lang/en/app.json", "rt"); appJson = nlohmann::json::parse(values, nullptr, false); fclose(values); return;