From 14f8d113596880c3f26cdae571cf6cafa0e6a994 Mon Sep 17 00:00:00 2001 From: VoltZ <47382115+SuperSaiyajinVoltZ@users.noreply.github.com> Date: Sun, 3 Nov 2019 23:58:58 +0100 Subject: [PATCH] My last work for today. --- include/download/download.hpp | 4 +- include/utils/common.hpp | 2 +- include/utils/config.hpp | 1 + romfs/lang/en/app.json | 6 ++- source/download/download.cpp | 72 +++++++++++++++++++++++++++++++++++ source/screens/mainMenu.cpp | 5 +++ source/screens/scriptlist.cpp | 2 +- source/utils/config.cpp | 4 ++ 8 files changed, 92 insertions(+), 4 deletions(-) diff --git a/include/download/download.hpp b/include/download/download.hpp index 3e48a94..f42aeb5 100644 --- a/include/download/download.hpp +++ b/include/download/download.hpp @@ -109,4 +109,6 @@ namespace download { void deleteFileList(std::string file, std::string message); void installFileList(std::string file, std::string message); void extractFileList(std::string file, std::string input, std::string output, std::string message); -} \ No newline at end of file +} + +void downloadScripts(void); \ No newline at end of file diff --git a/include/utils/common.hpp b/include/utils/common.hpp index 1d1415a..b582b0c 100644 --- a/include/utils/common.hpp +++ b/include/utils/common.hpp @@ -59,4 +59,4 @@ using json = nlohmann::json; extern char * arg0; #define WORKING_DIR "/" -#define SCRIPTS_PATH "/3ds/Universal-Updater/scripts/" // The Scripts will be here. \ No newline at end of file +#define SCRIPTS_PATH "sdmc:/3ds/Universal-Updater/scripts/" // The Scripts will be here. \ No newline at end of file diff --git a/include/utils/config.hpp b/include/utils/config.hpp index a6ae1b0..6b07b70 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -34,6 +34,7 @@ namespace Config { // [UI] extern int lang; // The current Language. extern int Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor; // Colors! + extern std::string ScriptPath; void loadConfig(); void saveConfig(); diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index eb0deba..409dfe0 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -30,5 +30,9 @@ "INCOMPATIBLE_SCRIPT": "You have an incompatible script.", "DELETE_PROMPT": "Are you sure you want to delete this Directory?", - "CONFIRM_OR_CANCEL": "Press A to confirm, B to cancel." + "CONFIRM_OR_CANCEL": "Press A to confirm, B to cancel.", + + "GETTING_SCRIPT_LIST": "Getting Script List...", + "B_BACK": "\uE001: Back", + "A_CHOOSE": "\uE000: Choose" } diff --git a/source/download/download.cpp b/source/download/download.cpp index 97cadb2..f5fe824 100644 --- a/source/download/download.cpp +++ b/source/download/download.cpp @@ -32,6 +32,7 @@ #include "screens/screenCommon.hpp" +#include "utils/config.hpp" #include "utils/extract.hpp" #include "utils/fileBrowse.h" #include "utils/inifile.h" @@ -671,4 +672,75 @@ void download::extractFileList(std::string file, std::string input, std::string Threads::create((ThreadFunc)displayProgressBar); extractArchive(file, input, output); showProgressBar = false; +} + +// Script Browse. +void downloadScripts(void) { + int keyRepeatDelay = 0; + std::string ScriptsPath = Config::ScriptPath; + + DisplayMsg(Lang::get("GETTING_SCRIPT_LIST")); + + std::vector scriptList; + scriptList = getThemeList("Universal-Team/extras", "Scripts"); + makeDirs(ScriptsPath.c_str()); + + for(uint i=0;i 0) { + selectedScript--; + keyRepeatDelay = 3; + } + } else if(hHeld & KEY_DOWN && !keyRepeatDelay) { + if(selectedScript < (int)scriptList.size()-1) { + selectedScript++; + keyRepeatDelay = 3; + } + } else if(hHeld & KEY_LEFT && !keyRepeatDelay) { + selectedScript -= 10; + if(selectedScript < 0) { + selectedScript = 0; + } + keyRepeatDelay = 3; + } else if(hHeld & KEY_RIGHT && !keyRepeatDelay) { + selectedScript += 10; + if(selectedScript > (int)scriptList.size()) { + selectedScript = scriptList.size()-1; + } + keyRepeatDelay = 3; + } + std::string scriptText; + for(int i=(selectedScript<10) ? 0 : selectedScript-10;i<(int)scriptList.size()&&i<((selectedScript<10) ? 11 : selectedScript+1);i++) { + if(i == selectedScript) { + scriptText += "> " + scriptList[i].name + "\n"; + } else { + scriptText += " " + scriptList[i].name + "\n"; + } + } + for(uint i=0;i<((scriptList.size()<10) ? 11-scriptList.size() : 0);i++) { + scriptText += "\n"; + } + scriptText += Lang::get("B_BACK") + " " +Lang::get("A_CHOOSE"); + DisplayMsg(scriptText.c_str()); + } } \ No newline at end of file diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index a1ebedd..dffabbc 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -24,6 +24,7 @@ * reasonable ways as different from the original version. */ +#include "download/download.hpp" #include "screens/mainMenu.hpp" #include "screens/settings.hpp" #include "screens/scriptlist.hpp" @@ -91,4 +92,8 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { Gui::setScreen(std::make_unique()); } } + + if (hDown & KEY_X) { + downloadScripts(); + } } \ No newline at end of file diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index 3928747..428af96 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -265,7 +265,7 @@ void loadColors(nlohmann::json &json) { ScriptList::ScriptList() { dirContents.clear(); - chdir(SCRIPTS_PATH); + chdir(Config::ScriptPath.c_str()); getDirectoryContents(dirContents); for(uint i=0;i