diff --git a/include/screens/settings.hpp b/include/screens/settings.hpp index 77de64f..fc905a3 100644 --- a/include/screens/settings.hpp +++ b/include/screens/settings.hpp @@ -46,17 +46,16 @@ private: mutable int screenPos = 0; int colorSelection = 0; int keyRepeatDelay = 0; + int settingPage = 0; // Draws. void DrawSubMenu(void) const; void DrawLanguageSelection(void) const; void DrawColorChanging(void) const; - void DrawMiscSettings(void) const; // Logic's. void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch); void LanguageSelection(u32 hDown, u32 hHeld, touchPosition touch); void colorChanging(u32 hDown, u32 hHeld, touchPosition touch); - void MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch); const std::vector mainButtons = { {80, 30, 149, 52}, // Language. diff --git a/include/utils/common.hpp b/include/utils/common.hpp index 286083d..e59ff67 100644 --- a/include/utils/common.hpp +++ b/include/utils/common.hpp @@ -63,8 +63,6 @@ using json = nlohmann::json; #endif -extern char * arg0; - #define WORKING_DIR "/" #define SCRIPTS_PATH "sdmc:/3ds/Universal-Updater/scripts/" // The Scripts will be here. #define MUSIC_PATH "sdmc:/3ds/Universal-Updater/Music.wav" // Default Music File / Path. @@ -74,4 +72,5 @@ extern char * arg0; #define ENTRIES_PER_LIST 7 #define metaFile "sdmc:/3ds/Universal-Updater/ScriptInfo.json" #define _3DSX_PATH "sdmc:/3ds" -#define _NDS_PATH "sdmc:" \ No newline at end of file +#define _NDS_PATH "sdmc:" +#define ARCHIVES_DEFAULT "sdmc:" \ No newline at end of file diff --git a/include/utils/config.hpp b/include/utils/config.hpp index e8fb784..8981a20 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -129,7 +129,9 @@ public: void _3dsxpath(std::string v) { this->v_3dsx_install_path = v; if (!this->changesMade) this->changesMade = true; } std::string ndspath() { return this->v_nds_install_path; } void ndspath(std::string v) { this->v_nds_install_path = v; if (!this->changesMade) this->changesMade = true; } - + std::string archivepath() { return this->v_archive_path; } + void archivepath(std::string v) { this->v_archive_path = v; if (!this->changesMade) this->changesMade = true; } + // Mainly helper. bool getBool(const std::string &key); void setBool(const std::string &key, bool v); @@ -150,7 +152,7 @@ private: bool v_logging, v_useBars, v_screenFade, v_progressDisplay, v_firstStartup, v_useScriptColor, v_showSpeed; // Some variables. - std::string v_3dsx_install_path, v_nds_install_path; + std::string v_3dsx_install_path, v_nds_install_path, v_archive_path; }; #endif \ No newline at end of file diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 2092ef3..af83d34 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -213,5 +213,12 @@ "SELECT_AUTHOR": "Select an author you like to view.", "SELECT_CONSOLE": "Select a console you like to view.", "NO_AUTHORS_AVAILABLE": "No authors available.", - "NO_CONSOLES_AVAILABLE": "No consoles available." + "NO_CONSOLES_AVAILABLE": "No consoles available.", + "CHANGE_3DSX_PATH": "Change 3DSX path", + "CHANGE_NDS_PATH": "Change NDS path", + "CHANGE_ARCHIVE_PATH": "Change Archive path", + "SELECT_3DSX_PATH": "Select the 3DSX path.", + "SELECT_NDS_PATH": "Select the NDS path.", + "SELECT_ARCHIVE_PATH": "Select the Archive path.", + "TOGGLE_PROGRESSBAR": "Toggle Progressbar" } diff --git a/source/screens/settings.cpp b/source/screens/settings.cpp index 544fa2d..de0e898 100644 --- a/source/screens/settings.cpp +++ b/source/screens/settings.cpp @@ -42,8 +42,6 @@ void Settings::Draw(void) const { DrawLanguageSelection(); } else if (mode == 2) { DrawColorChanging(); - } else if (mode == 4) { - DrawMiscSettings(); } } @@ -56,11 +54,27 @@ void Settings::DrawSubMenu(void) const { GFX::DrawArrow(0, 218, 0, 1); GFX::DrawArrow(318, 240, 180.0, 1); - GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, Lang::get("LANGUAGE")); - GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("COLORS")); - GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("CHANGE_BAR_STYLE")); + if (this->settingPage == 0) { + GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, Lang::get("LANGUAGE")); + GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("COLORS")); + GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("CHANGE_BAR_STYLE")); + } else if (this->settingPage == 1) { + GFX::DrawButton(mainButtons2[0].x, mainButtons2[0].y, Lang::get("CHANGE_MUSICFILE")); + GFX::DrawButton(mainButtons2[1].x, mainButtons2[1].y, Lang::get("CHANGE_KEY_DELAY")); + GFX::DrawButton(mainButtons2[2].x, mainButtons2[2].y, Lang::get("TOGGLE_FADE")); + GFX::DrawButton(mainButtons2[3].x, mainButtons2[3].y, Lang::get("TOGGLE_PROGRESSBAR")); + } else if (this->settingPage == 2) { + GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, Lang::get("CHANGE_3DSX_PATH")); + GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("CHANGE_NDS_PATH")); + GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("CHANGE_ARCHIVE_PATH")); + } + // Selector. - Animation::Button(mainButtons[Selection].x, mainButtons[Selection].y, .060); + if (this->settingPage == 0 || this->settingPage == 2) { + Animation::Button(mainButtons[Selection].x, mainButtons[Selection].y, .060); + } else { + Animation::Button(mainButtons2[Selection].x, mainButtons2[Selection].y, .060); + } if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect } @@ -219,151 +233,187 @@ void Settings::DrawColorChanging(void) const { if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect } -void Settings::DrawMiscSettings(void) const { - GFX::DrawTop(); - Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), "Universal-Updater", 400); - if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect - GFX::DrawBottom(); - GFX::DrawArrow(0, 218, 0, 1); - - GFX::DrawButton(mainButtons2[0].x, mainButtons2[0].y, Lang::get("CHANGE_MUSICFILE")); - GFX::DrawButton(mainButtons2[1].x, mainButtons2[1].y, Lang::get("CHANGE_KEY_DELAY")); - GFX::DrawButton(mainButtons2[2].x, mainButtons2[2].y, Lang::get("TOGGLE_FADE")); - - // Selector. - Animation::Button(mainButtons2[Selection].x, mainButtons2[Selection].y, .060); - if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect -} - -void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) { - if (hDown & KEY_A) { - if (Selection == 0) { - std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2); - if (tempMusic != "") { - config->musicPath(tempMusic); - } - } else if (Selection == 1) { - config->keyDelay(Input::getUint(255, Lang::get("ENTER_KEY_DELAY"))); - } else if (Selection == 2) { - if (config->screenFade()) { - if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) { - config->screenFade(false); - Msg::DisplayWarnMsg(Lang::get("DISABLED")); - } - } else { - if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) { - config->screenFade(true); - Msg::DisplayWarnMsg(Lang::get("ENABLED")); - } - } - } - } - - if (hDown & KEY_TOUCH) { - if (touching(touch, mainButtons2[0])) { - std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2); - if (tempMusic != "") { - config->musicPath(tempMusic); - } - } else if (touching(touch, mainButtons2[1])) { - config->keyDelay(Input::getUint(255, Lang::get("ENTER_KEY_DELAY"))); - } else if (touching(touch, mainButtons2[2])) { - if (config->screenFade()) { - if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) { - config->screenFade(false); - Msg::DisplayWarnMsg(Lang::get("DISABLED")); - } - } else { - if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) { - config->screenFade(true); - Msg::DisplayWarnMsg(Lang::get("ENABLED")); - } - } - } - } - - if ((hDown & KEY_B || hDown & KEY_L) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { - Selection = 0; - mode = 0; - } - - // No idea where to place the button for it, so do it here for now. - if (hDown & KEY_SELECT) { - if (config->progressDisplay()) { - if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) { - config->progressDisplay(false); - Msg::DisplayWarnMsg(Lang::get("DISABLED")); - } - } else { - if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) { - config->progressDisplay(true); - Msg::DisplayWarnMsg(Lang::get("ENABLED")); - } - } - } - - // Navigation. - if (hDown & KEY_UP) { - if (Selection > 1) Selection -= 2; - } else if (hDown & KEY_DOWN) { - if (Selection < 3 && Selection != 2 && Selection != 3) Selection += 2; - } else if (hDown & KEY_LEFT) { - if (Selection%2) Selection--; - } else if (hDown & KEY_RIGHT) { - if (!(Selection%2)) Selection++; - } -} - void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { - if (hDown & KEY_UP) { - if (Selection > 0) Selection--; - } - - if (hDown & KEY_DOWN) { - if (Selection < 2) Selection++; - } - - if (hDown & KEY_A) { - switch (Selection) { - case 0: - screenPos = 0; - selectedLang = 0; - mode = 1; - break; - case 1: - screenPos = 0; - mode = 2; - break; - case 2: - if (config->useBars()) config->useBars(false); - else config->useBars(true); - break; - } - } - - if (hDown & KEY_TOUCH) { - if (touching(touch, mainButtons[0])) { - screenPos = 0; - selectedLang = 0; - mode = 1; - } else if (touching(touch, mainButtons[1])) { - screenPos = 0; - mode = 2; - } else if (touching(touch, mainButtons[2])) { - if (config->useBars()) config->useBars(false); - else config->useBars(true); - } - } - - if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { + if ((hDown & KEY_B)) { Gui::screenBack(config->screenFade()); return; } if ((hDown & KEY_R) || (hDown & KEY_TOUCH && touching(touch, arrowPos[4]))) { - Selection = 0; - mode = 4; + if (this->settingPage < 2) { + this->settingPage++; + Selection = 0; + } + } + + if ((hDown & KEY_L) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { + if (this->settingPage > 0) { + this->settingPage--; + Selection = 0; + } + } + + if (this->settingPage == 0) { + if (hDown & KEY_UP) { + if (Selection > 0) Selection--; + } + + if (hDown & KEY_DOWN) { + if (Selection < 2) Selection++; + } + + if (hDown & KEY_A) { + switch (Selection) { + case 0: + screenPos = 0; + selectedLang = 0; + mode = 1; + break; + case 1: + screenPos = 0; + mode = 2; + break; + case 2: + if (config->useBars()) config->useBars(false); + else config->useBars(true); + break; + } + } + + if (hDown & KEY_TOUCH) { + if (touching(touch, mainButtons[0])) { + screenPos = 0; + selectedLang = 0; + mode = 1; + } else if (touching(touch, mainButtons[1])) { + screenPos = 0; + mode = 2; + } else if (touching(touch, mainButtons[2])) { + if (config->useBars()) config->useBars(false); + else config->useBars(true); + } + } + } else if (this->settingPage == 1) { + if (hDown & KEY_A) { + if (Selection == 0) { + std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2); + if (tempMusic != "") { + config->musicPath(tempMusic); + } + } else if (Selection == 1) { + config->keyDelay(Input::getUint(255, Lang::get("ENTER_KEY_DELAY"))); + } else if (Selection == 2) { + if (config->screenFade()) { + if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) { + config->screenFade(false); + Msg::DisplayWarnMsg(Lang::get("DISABLED")); + } + } else { + if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) { + config->screenFade(true); + Msg::DisplayWarnMsg(Lang::get("ENABLED")); + } + } + } else if (Selection == 3) { + if (config->progressDisplay()) { + if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) { + config->progressDisplay(false); + Msg::DisplayWarnMsg(Lang::get("DISABLED")); + } + } else { + if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) { + config->progressDisplay(true); + Msg::DisplayWarnMsg(Lang::get("ENABLED")); + } + } + } + } + + if (hDown & KEY_TOUCH) { + if (touching(touch, mainButtons2[0])) { + std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2); + if (tempMusic != "") { + config->musicPath(tempMusic); + } + } else if (touching(touch, mainButtons2[1])) { + config->keyDelay(Input::getUint(255, Lang::get("ENTER_KEY_DELAY"))); + } else if (touching(touch, mainButtons2[2])) { + if (config->screenFade()) { + if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) { + config->screenFade(false); + Msg::DisplayWarnMsg(Lang::get("DISABLED")); + } + } else { + if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) { + config->screenFade(true); + Msg::DisplayWarnMsg(Lang::get("ENABLED")); + } + } + } else if (touching(touch, mainButtons2[3])) { + if (config->progressDisplay()) { + if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) { + config->progressDisplay(false); + Msg::DisplayWarnMsg(Lang::get("DISABLED")); + } + } else { + if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) { + config->progressDisplay(true); + Msg::DisplayWarnMsg(Lang::get("ENABLED")); + } + } + } + } + + // Navigation. + if (hDown & KEY_UP) { + if (Selection > 1) Selection -= 2; + } else if (hDown & KEY_DOWN) { + if (Selection < 2) Selection += 2; + } else if (hDown & KEY_LEFT) { + if (Selection%2) Selection--; + } else if (hDown & KEY_RIGHT) { + if (!(Selection%2)) Selection++; + } + } else if (this->settingPage == 2) { + if (hDown & KEY_UP) { + if (Selection > 0) Selection--; + } + + if (hDown & KEY_DOWN) { + if (Selection < 2) Selection++; + } + + if (hDown & KEY_A) { + std::string tempPath; + switch (Selection) { + case 0: + tempPath = selectFilePath(Lang::get("SELECT_3DSX_PATH"), config->_3dsxpath(), {}); + if (tempPath != "") config->_3dsxpath(tempPath); + break; + case 1: + tempPath = selectFilePath(Lang::get("SELECT_NDS_PATH"), config->ndspath(), {}); + if (tempPath != "") config->ndspath(tempPath); + break; + case 2: + tempPath = selectFilePath(Lang::get("SELECT_ARCHIVE_PATH"), config->archivepath(), {}); + if (tempPath != "") config->archivepath(tempPath); + break; + } + } + + if (hDown & KEY_TOUCH) { + if (touching(touch, mainButtons[0])) { + std::string tempPath = selectFilePath(Lang::get("SELECT_3DSX_PATH"), config->_3dsxpath(), {}); + if (tempPath != "") config->_3dsxpath(tempPath); + } else if (touching(touch, mainButtons[1])) { + std::string tempPath = selectFilePath(Lang::get("SELECT_NDS_PATH"), config->ndspath(), {}); + if (tempPath != "") config->ndspath(tempPath); + } else if (touching(touch, mainButtons[2])) { + std::string tempPath = selectFilePath(Lang::get("SELECT_ARCHIVE_PATH"), config->archivepath(), {}); + if (tempPath != "") config->archivepath(tempPath); + } + } } } @@ -568,7 +618,5 @@ void Settings::Logic(u32 hDown, u32 hHeld, touchPosition touch) { LanguageSelection(hDown, hHeld, touch); } else if (mode == 2) { colorChanging(hDown, hHeld, touch); - } else if (mode == 4) { - MiscSettingsLogic(hDown, hHeld, touch); } } \ No newline at end of file diff --git a/source/utils/config.cpp b/source/utils/config.cpp index 8155aad..381c94c 100644 --- a/source/utils/config.cpp +++ b/source/utils/config.cpp @@ -35,6 +35,7 @@ void Config::addMissingThings() { if (this->json["VERSION"] < 2) { this->setString("3DSX_PATH", _3DSX_PATH); this->setString("NDS_PATH", _NDS_PATH); + this->setString("ARCHIVE_PATH", ARCHIVES_DEFAULT); } } @@ -74,6 +75,7 @@ void Config::initialize() { this->setBool("SHOW_SPEED", false); this->setString("3DSX_PATH", _3DSX_PATH); this->setString("NDS_PATH", _NDS_PATH); + this->setString("ARCHIVE_PATH", ARCHIVES_DEFAULT); this->setInt("VERSION", this->configVersion); // Write to file. @@ -282,6 +284,12 @@ Config::Config() { this->ndspath(this->getString("NDS_PATH")); } + if (!this->json.contains("ARCHIVE_PATH")) { + this->archivepath(ARCHIVES_DEFAULT); + } else { + this->archivepath(this->getString("ARCHIVE_PATH")); + } + this->changesMade = false; // No changes made yet. } @@ -321,6 +329,8 @@ void Config::save() { this->setBool("SHOW_SPEED", this->showSpeed()); this->setString("3DSX_PATH", this->_3dsxpath()); this->setString("NDS_PATH", this->ndspath()); + this->setString("ARCHIVE_PATH", this->archivepath()); + // Write changes to file. const std::string dump = this->json.dump(1, '\t'); fwrite(dump.c_str(), 1, this->json.dump(1, '\t').size(), file); diff --git a/source/utils/scriptHelper.cpp b/source/utils/scriptHelper.cpp index 4472adb..d94e681 100644 --- a/source/utils/scriptHelper.cpp +++ b/source/utils/scriptHelper.cpp @@ -71,6 +71,7 @@ Result ScriptHelper::downloadRelease(std::string repo, std::string file, std::st std::string out; out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxpath().c_str()); out = std::regex_replace(out, std::regex("%NDS%"), config->ndspath().c_str()); + out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str()); Result ret = NONE; if (downloadFromRelease("https://github.com/" + repo, file, out, message, includePrereleases, showVersions) != 0) { @@ -89,6 +90,7 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str std::string out; out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxpath().c_str()); out = std::regex_replace(out, std::regex("%NDS%"), config->ndspath().c_str()); + out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str()); Result ret = NONE; snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); @@ -108,13 +110,16 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str // Remove a File. Result ScriptHelper::removeFile(std::string file, std::string message) { + std::string out; + out = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str()); + Result ret = NONE; - if (access(file.c_str(), F_OK) != 0 ) { + if (access(out.c_str(), F_OK) != 0 ) { return DELETE_ERROR; } Msg::DisplayMsg(message); - deleteFile(file.c_str()); + deleteFile(out.c_str()); return ret; } @@ -130,12 +135,16 @@ void ScriptHelper::installFile(std::string file, bool updatingSelf, std::string // Extract Files. void ScriptHelper::extractFile(std::string file, std::string input, std::string output, std::string message) { + std::string out, in; + in = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str()); + out = std::regex_replace(output, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str()); + snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str()); showProgressBar = true; filesExtracted = 0; progressbarType = ProgressBar::Extracting; Threads::create((ThreadFunc)displayProgressBar); - extractArchive(file, input, output); + extractArchive(in, input, out); showProgressBar = false; }