From 49651f448b8a3a2cd4794eef5a443224ffef5662 Mon Sep 17 00:00:00 2001 From: Huntereb Date: Fri, 20 Dec 2019 19:08:54 -0500 Subject: [PATCH] Select languages in options menu --- config/config.ini | 1 + include/ui/optionsPage.hpp | 1 + include/util/config.hpp | 1 + romfs/lang/en.json | 6 ++++++ source/ui/optionsPage.cpp | 35 ++++++++++++++++++++++++++++++++++- source/util/config.cpp | 8 +++++--- source/util/lang.cpp | 19 ++++++++++++------- 7 files changed, 60 insertions(+), 11 deletions(-) diff --git a/config/config.ini b/config/config.ini index d459c2c..2f95565 100755 --- a/config/config.ini +++ b/config/config.ini @@ -5,4 +5,5 @@ overClock=0 deletePrompt=1 gayMode=0 sigPatchesUrl=https://github.com/Huntereb/Awoo-Installer/releases/download/SignaturePatches/patches.zip +languageSetting=99 usbAck=0 diff --git a/include/ui/optionsPage.hpp b/include/ui/optionsPage.hpp index 6674484..31c2e51 100755 --- a/include/ui/optionsPage.hpp +++ b/include/ui/optionsPage.hpp @@ -21,5 +21,6 @@ namespace inst::ui { pu::ui::elm::Menu::Ref menu; void setMenuText(); std::string getMenuOptionIcon(bool ourBool); + std::string getMenuLanguage(int ourLangCode); }; } \ No newline at end of file diff --git a/include/util/config.hpp b/include/util/config.hpp index 5bcc747..3d035fa 100755 --- a/include/util/config.hpp +++ b/include/util/config.hpp @@ -10,6 +10,7 @@ namespace inst::config { extern std::string sigPatchesUrl; extern std::string gAuthKey; extern std::vector updateInfo; + extern int languageSetting; extern bool ignoreReqVers; extern bool validateNCAs; extern bool overClock; diff --git a/romfs/lang/en.json b/romfs/lang/en.json index a6fddc7..f7a93e4 100755 --- a/romfs/lang/en.json +++ b/romfs/lang/en.json @@ -149,6 +149,7 @@ "auto_update": "Check for updates to Awoo Installer automatically", "gay_option": "Remove anime", "sig_url": "Signature patches source URL: ", + "language": "Language: ", "check_update": "Check for updates to Awoo Installer", "credits": "Credits" }, @@ -176,6 +177,11 @@ "title": "Thanks to the following people!", "desc": "- HookedBehemoth for A LOT of contributions\n- Adubbz and other contributors for Tinfoil\n- XorTroll for Plutonium and Goldleaf\n- blawar (wife beater) and nicoboss for NSZ support\n- The kind folks at the AtlasNX Discuck (or at least some of them)\n- The also kind folks at the RetroNX Discuck (of no direct involvement)\n- namako8982 for the Momiji art\n- TheXzoron for being a baka" }, + "language": { + "title": "Select Awoo Installer's language", + "desc": "The software will be closed after changing languages. Press B to cancel.", + "system_language": "System default" + }, "title": "Change Awoo Installer's settings!", "buttons": "\ue0e0 Select/Change \ue0e1 Cancel " }, diff --git a/source/ui/optionsPage.cpp b/source/ui/optionsPage.cpp index 5aae9e7..e8687d8 100755 --- a/source/ui/optionsPage.cpp +++ b/source/ui/optionsPage.cpp @@ -16,6 +16,8 @@ namespace inst::ui { extern MainApplication *mainApp; + std::vector languageStrings = {"English"}; + optionsPage::optionsPage() : Layout::Layout() { this->SetBackgroundColor(COLOR("#670000FF")); if (std::filesystem::exists(inst::config::appDir + "/background.png")) this->SetBackgroundImage(inst::config::appDir + "/background.png"); @@ -72,6 +74,16 @@ namespace inst::ui { else return "romfs:/images/icons/checkbox-blank-outline.png"; } + std::string optionsPage::getMenuLanguage(int ourLangCode) { + switch (ourLangCode) { + case(1): + case(12): + return languageStrings[0].AsUTF8(); + default: + return "options.language.system_language"_lang; + } + } + void optionsPage::setMenuText() { this->menu->ClearItems(); auto ignoreFirmOption = pu::ui::elm::MenuItem::New("options.menu_items.ignore_firm"_lang); @@ -101,6 +113,9 @@ namespace inst::ui { auto sigPatchesUrlOption = pu::ui::elm::MenuItem::New("options.menu_items.sig_url"_lang + inst::util::shortenString(inst::config::sigPatchesUrl, 42, false)); sigPatchesUrlOption->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(sigPatchesUrlOption); + auto languageOption = pu::ui::elm::MenuItem::New("options.menu_items.language"_lang + this->getMenuLanguage(inst::config::languageSetting)); + languageOption->SetColor(COLOR("#FFFFFFFF")); + this->menu->AddItem(languageOption); auto updateOption = pu::ui::elm::MenuItem::New("options.menu_items.check_update"_lang); updateOption->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(updateOption); @@ -115,7 +130,9 @@ namespace inst::ui { } if ((Down & KEY_A) || (Up & KEY_TOUCH)) { std::string keyboardResult; + int rc; std::vector downloadUrl; + std::vector languageList; switch (this->menu->GetSelectedIndex()) { case 0: inst::config::ignoreReqVers = !inst::config::ignoreReqVers; @@ -167,6 +184,22 @@ namespace inst::ui { } break; case 7: + languageList = languageStrings; + languageList.push_back("options.language.system_language"_lang); + rc = inst::ui::mainApp->CreateShowDialog("options.language.title"_lang, "options.language.desc"_lang, languageList, false); + if (rc == -1) break; + switch(rc) { + case 0: + inst::config::languageSetting = 1; + break; + default: + inst::config::languageSetting = 99; + } + inst::config::setConfig(); + mainApp->FadeOut(); + mainApp->Close(); + break; + case 8: if (inst::util::getIPAddress() == "1.0.0.127") { inst::ui::mainApp->CreateShowDialog("main.net.title"_lang, "main.net.desc"_lang, {"common.ok"_lang}, true); break; @@ -178,7 +211,7 @@ namespace inst::ui { } this->askToUpdate(downloadUrl); break; - case 8: + case 9: inst::ui::mainApp->CreateShowDialog("options.credits.title"_lang, "options.credits.desc"_lang, {"common.close"_lang}, true); break; default: diff --git a/source/util/config.cpp b/source/util/config.cpp index 6064ec1..2f51a3d 100755 --- a/source/util/config.cpp +++ b/source/util/config.cpp @@ -5,10 +5,11 @@ #include "util/config.hpp" namespace inst::config { - static const char* configBase = "[settings]\nignoreReqVers=%d\nvalidateNCAs=%d\noverClock=%d\ndeletePrompt=%d\nautoUpdate=%d\ngayMode=%d\nsigPatchesUrl=%s\ngAuthKey=%s\nusbAck=%d"; + static const char* configBase = "[settings]\nignoreReqVers=%d\nvalidateNCAs=%d\noverClock=%d\ndeletePrompt=%d\nautoUpdate=%d\ngayMode=%d\nsigPatchesUrl=%s\ngAuthKey=%s\nlanguageSetting=%i\nusbAck=%d"; std::string sigPatchesUrl; std::string gAuthKey; std::vector updateInfo; + int languageSetting; bool ignoreReqVers; bool validateNCAs; bool overClock; @@ -27,14 +28,15 @@ namespace inst::config { gayMode = reader.GetBoolean("settings", "gayMode", false); sigPatchesUrl = reader.GetString("settings", "sigPatchesUrl", "https://github.com/Huntereb/Awoo-Installer/releases/download/SignaturePatches/patches.zip"); gAuthKey = reader.GetString("settings", "gAuthKey", {0x41,0x49,0x7a,0x61,0x53,0x79,0x42,0x4d,0x71,0x76,0x34,0x64,0x58,0x6e,0x54,0x4a,0x4f,0x47,0x51,0x74,0x5a,0x5a,0x53,0x33,0x43,0x42,0x6a,0x76,0x66,0x37,0x34,0x38,0x51,0x76,0x78,0x53,0x7a,0x46,0x30}); + languageSetting = reader.GetInteger("settings", "languageSetting", 99); usbAck = reader.GetBoolean("settings", "usbAck", false); return; } void setConfig() { std::filesystem::remove(inst::config::configPath); - char data[119 + sigPatchesUrl.size() + gAuthKey.size()]; - sprintf(data, configBase, ignoreReqVers, validateNCAs, overClock, deletePrompt, autoUpdate, gayMode, sigPatchesUrl.c_str(), gAuthKey.c_str(), usbAck); + char data[139 + sigPatchesUrl.size() + gAuthKey.size()]; + sprintf(data, configBase, ignoreReqVers, validateNCAs, overClock, deletePrompt, autoUpdate, gayMode, sigPatchesUrl.c_str(), gAuthKey.c_str(), languageSetting, usbAck); FILE * configFile = fopen(inst::config::configPath.c_str(), "w"); fwrite(data, sizeof(char), strlen(data), configFile); fflush(configFile); diff --git a/source/util/lang.cpp b/source/util/lang.cpp index 3cda11b..9cdaa20 100755 --- a/source/util/lang.cpp +++ b/source/util/lang.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "util/config.hpp" namespace Language { json lang; @@ -10,13 +11,17 @@ namespace Language { void Load() { std::ifstream ifs; std::string languagePath; - setInitialize(); - u64 lcode = 0; - SetLanguage ourLang = SetLanguage_ENUS; - setGetSystemLanguage(&lcode); - setMakeLanguage(lcode, &ourLang); - setExit(); - switch (ourLang) { + int langInt = inst::config::languageSetting; + if (langInt == 99) { + SetLanguage ourLang; + u64 lcode = 0; + setInitialize(); + setGetSystemLanguage(&lcode); + setMakeLanguage(lcode, &ourLang); + setExit(); + langInt = (int)ourLang; + } + switch (langInt) { case 0: languagePath = "romfs:/lang/ja.json"; break;