Select languages in options menu

This commit is contained in:
Huntereb 2019-12-20 19:08:54 -05:00
parent a5cd41e47e
commit 49651f448b
7 changed files with 60 additions and 11 deletions

View File

@ -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

View File

@ -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);
};
}

View File

@ -10,6 +10,7 @@ namespace inst::config {
extern std::string sigPatchesUrl;
extern std::string gAuthKey;
extern std::vector<std::string> updateInfo;
extern int languageSetting;
extern bool ignoreReqVers;
extern bool validateNCAs;
extern bool overClock;

View File

@ -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 "
},

View File

@ -16,6 +16,8 @@
namespace inst::ui {
extern MainApplication *mainApp;
std::vector<pu::String> 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<std::string> downloadUrl;
std::vector<pu::String> 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:

View File

@ -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<std::string> 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);

View File

@ -3,6 +3,7 @@
#include <iostream>
#include <switch.h>
#include <filesystem>
#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;