From 1a20cc50f3f8d333a17830ad45ba852ab2953002 Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Sun, 8 Mar 2020 17:03:21 +0100 Subject: [PATCH] WIP: Add Glossary and some cleanup. --- include/animation.hpp | 38 + include/screens/scriptBrowse.hpp | 18 +- include/screens/scriptlist.hpp | 41 +- include/screens/unistore.hpp | 31 +- include/utils/common.hpp | 4 +- include/utils/scriptHelper.hpp | 18 + romfs/lang/en/app.json | 15 +- source/animation.cpp | 38 + source/download/download.cpp | 4 +- source/screens/scriptBrowse.cpp | 350 ++++---- source/screens/scriptlist.cpp | 1308 +++++++++++++++--------------- source/screens/unistore.cpp | 520 ++++++------ 12 files changed, 1346 insertions(+), 1039 deletions(-) create mode 100644 include/animation.hpp create mode 100644 source/animation.cpp diff --git a/include/animation.hpp b/include/animation.hpp new file mode 100644 index 0000000..d00a177 --- /dev/null +++ b/include/animation.hpp @@ -0,0 +1,38 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#ifndef ANIMATION_HPP +#define ANIMATION_HPP + +#include <3ds.h> +#include + +namespace Animation { + // Draw Progressbar. + void DrawProgressBar(float currentProgress, float totalProgress, int mode); +} + +#endif \ No newline at end of file diff --git a/include/screens/scriptBrowse.hpp b/include/screens/scriptBrowse.hpp index e6d85e6..7f82477 100644 --- a/include/screens/scriptBrowse.hpp +++ b/include/screens/scriptBrowse.hpp @@ -39,14 +39,26 @@ public: void Draw(void) const override; void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; ScriptBrowse(); - private: - std::vector dirContents; + // Selection. mutable int screenPos = 0; mutable int screenPosList = 0; - mutable int selection = 0; + mutable int Selection = 0; + int mode = 0; + + // Draws. + void DrawBrowse(void) const; + void DrawGlossary(void) const; + + nlohmann::json infoJson; + int maxScripts; + + // Browse stuff. int keyRepeatDelay = 0; int fastMode = false; + std::vector dirContents; + + // Button | Icon struct. std::vector arrowPos = { {295, 0, 25, 25}, // Arrow Up. {295, 215, 25, 25}, // Arrow Down. diff --git a/include/screens/scriptlist.hpp b/include/screens/scriptlist.hpp index 13c18a8..3275baf 100644 --- a/include/screens/scriptlist.hpp +++ b/include/screens/scriptlist.hpp @@ -29,6 +29,7 @@ #include "common.hpp" #include "fileBrowse.hpp" +#include "scriptHelper.hpp" #include "structs.hpp" #include @@ -38,32 +39,55 @@ class ScriptList : public Screen public: void Draw(void) const override; void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; - ScriptList(); + ScriptList(); // In case of "Autoboot", have a Constructor which handles stuff. private: + // Screen Mode. + int mode = 0; + int lastMode = 1; + + // Helper functions. void deleteScript(int selectedScript); void refreshList(); + nlohmann::json openScriptFile(); + void checkForValidate(void); + void loadDesc(void); + void runFunctions(nlohmann::json &json); + // Draw Functions. void DrawSubMenu(void) const; void DrawList(void) const; void DrawSingleObject(void) const; + void DrawGlossary(void) const; + // Logic Functions. void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch); void ListSelection(u32 hDown, u32 hHeld, touchPosition touch); void SelectFunction(u32 hDown, u32 hHeld, touchPosition touch); - int mode = 0; - int SubSelection = 0; - std::vector dirContents; + // This is for the Script Creator, so no one can access it for now, until it is stable or so. + bool isTesting = false; + + // Other includes which get destructed automatically. + std::string choice; + std::string currentFile; + std::string selectedTitle; + std::string Desc = ""; + nlohmann::json jsonFile; + std::vector fileInfo; + std::vector fileInfo2; + std::vector lines; + mutable int screenPos = 0; mutable int screenPosList = 0; - mutable int selection = 0; - mutable int screenPos2 = 0; - mutable int screenPosList2 = 0; - mutable int selection2 = 0; + mutable int Selection = 0; + // Browse stuff. int keyRepeatDelay = 0; + std::vector dirContents; int fastMode = false; + + // Button | Icon structs. std::vector arrowPos = { {295, 0, 25, 25}, // Arrow Up. {295, 215, 25, 25}, // Arrow Down. @@ -71,7 +95,6 @@ private: {5, 0, 25, 25}, // viewMode Change {45, 0, 25, 25}, // Search. }; - std::vector subPos = { {10, 70, 140, 40}, // Script list. {170, 70, 140, 40}, // Get Scripts. diff --git a/include/screens/unistore.hpp b/include/screens/unistore.hpp index b83b2b2..409547b 100644 --- a/include/screens/unistore.hpp +++ b/include/screens/unistore.hpp @@ -29,6 +29,7 @@ #include "common.hpp" #include "fileBrowse.hpp" +#include "scriptHelper.hpp" #include "structs.hpp" #include @@ -41,13 +42,17 @@ public: UniStore(); private: void refreshList(); - + nlohmann::json openStoreFile(); + void loadStoreDesc(void); + void loadStoreSheet(int pos); + void DrawSubMenu(void) const; void DrawStoreList(void) const; void DrawStore(void) const; void DrawSearch(void) const; void DrawFullURLScreen(void) const; void DrawGitHubScreen(void) const; + void DrawGlossary(void) const; void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch); void StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch); @@ -63,7 +68,7 @@ private: void deleteStore(int selectedStore); bool handleIfDisplayText(); int mode = 0; - int selectedOptionAppStore = 0; + int lastMode = 1; mutable bool displayInformations = true; // Stuff for the GitHub Store Search function and Full URL. @@ -71,20 +76,25 @@ private: std::string fileName = ""; std::string FullURL = ""; - mutable int selection = 0; - mutable int selection2 = 0; + // Selections. + mutable int Selection = 0; int screenPos = 0; - int screenPos2 = 0; mutable int screenPosList = 0; - mutable int screenPosList2 = 0; - - int searchSelection = 0; - int subSelection = 0; + // Browse stuff. int keyRepeatDelay = 0; int fastMode = false; std::vector dirContents; + // Other stuff. + std::vector storeInfo; // Store Selection. + std::vector appStoreList; // Actual store. ;P + std::vector descLines; + std::string storeDesc = ""; + nlohmann::json appStoreJson; + std::string currentStoreFile; + + // Icon | Button Structs. std::vector arrowPos = { {295, 0, 25, 25}, // Arrow Up. {295, 215, 25, 25}, // Arrow Down. @@ -93,20 +103,17 @@ private: {45, 0, 25, 25}, // Search. {85, 0, 25, 25}, // Update. }; - std::vector URLBtn = { {10, 70, 140, 40}, // FULL URL. {170, 70, 140, 40}, // Github. {10, 145, 140, 40}, // TinyDB. {170, 145, 140, 40}, // QR Code? }; - std::vector GitHubPos = { {30, 50, 260, 30}, // Owner & Repo. {30, 130, 260, 30}, // Filename. {135, 180, 50, 30}, // OK. }; - std::vector subPos = { {90, 40, 140, 35}, // StoreList. {90, 100, 140, 35}, // storeSearch. diff --git a/include/utils/common.hpp b/include/utils/common.hpp index dd76f93..5b18709 100644 --- a/include/utils/common.hpp +++ b/include/utils/common.hpp @@ -42,6 +42,7 @@ extern "C" { #ifdef __cplusplus } +#include "animation.hpp" #include "config.hpp" #include "gfx.hpp" #include "gui.hpp" @@ -70,4 +71,5 @@ extern char * arg0; #define SCRIPT_VERSION 3 #define STORE_PATH "sdmc:/3ds/Universal-Updater/stores/" // Default Store path. #define ENTRIES_PER_SCREEN 3 -#define ENTRIES_PER_LIST 7 \ No newline at end of file +#define ENTRIES_PER_LIST 7 +#define metaFile "sdmc:/3ds/Universal-Updater/ScriptInfo.json" \ No newline at end of file diff --git a/include/utils/scriptHelper.hpp b/include/utils/scriptHelper.hpp index 5612470..0a4c5cb 100644 --- a/include/utils/scriptHelper.hpp +++ b/include/utils/scriptHelper.hpp @@ -29,6 +29,24 @@ #include +// Information like Title and Author. +struct ScriptInfo { + std::string title; + std::string author; + std::string shortDesc; +}; + +// Store Information. +struct StoreInfo { + std::string title; + std::string author; + std::string description; + std::string url; + std::string file; + std::string storeSheet; + std::string sheetURL; +}; + namespace ScriptHelper { // Get stuff from a JSON. std::string getString(nlohmann::json json, const std::string &key, const std::string &key2); diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 5cc3094..37c1787 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -131,5 +131,18 @@ "REFRESHING_LIST": "Refreshing List...", "AUTOBOOT_SCRIPT": "Would you like to autoboot this Script?\n\nThis will autoboot this Script on startup!", - "STARTING_UNIVERSAL_UPDATER": "Starting Universal-Updater..." + "STARTING_UNIVERSAL_UPDATER": "Starting Universal-Updater...", + + "EXECUTE_SCRIPT": "Would you like to execute this script?", + "EXECUTE_STORE": "Would you like to execute this entry?", + + "GLOSSARY": "Glossary", + "DOWNLOAD_ALL": "Download all Scripts at once.", + "CHANGE_VIEW_MODE": "Change the viewMode.", + "ENTRY_UP": "Go one Entry up.", + "ENTRY_DOWN": "Go one Entry down.", + "GO_BACK": "Go back.", + "ENTRY": "Current Entry | Last Entry", + "REVISION": "Current Revision | Latest Revision", + "UPDATE_STORE": "Update selected UniStore." } diff --git a/source/animation.cpp b/source/animation.cpp new file mode 100644 index 0000000..76b45d7 --- /dev/null +++ b/source/animation.cpp @@ -0,0 +1,38 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019-2020 DeadPhoenix8091, Epicpkmn11, Flame, RocketRobz, StackZ, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "common.hpp" + +extern u32 progressBar; + +// Draws a Rectangle as the progressbar. +void Animation::DrawProgressBar(float currentProgress, float totalProgress, int mode) { + if (mode == 1) { + Gui::Draw_Rect(31, 121, (int)(((float)currentProgress/(float)totalProgress) * 338.0f), 28, progressBar); + } else { + Gui::Draw_Rect(31, 121, (int)(((float)currentProgress/(float)totalProgress) * 338.0f), 28, Config::progressbarColor); + } +} \ No newline at end of file diff --git a/source/download/download.cpp b/source/download/download.cpp index ae7f376..002ac7c 100644 --- a/source/download/download.cpp +++ b/source/download/download.cpp @@ -666,9 +666,9 @@ void displayProgressBar() { Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400); Gui::Draw_Rect(30, 120, 340, 30, BLACK); if (isScriptSelected == true) { - Gui::Draw_Rect(31, 121, (int)(((float)downloadNow/(float)downloadTotal) * 338.0f), 28, progressBar); + Animation::DrawProgressBar(downloadNow, downloadTotal, 1); } else { - Gui::Draw_Rect(31, 121, (int)(((float)downloadNow/(float)downloadTotal) * 338.0f), 28, Config::progressbarColor); + Animation::DrawProgressBar(downloadNow, downloadTotal, 2); } } GFX::DrawBottom(); diff --git a/source/screens/scriptBrowse.cpp b/source/screens/scriptBrowse.cpp index 7d234c4..beddef5 100644 --- a/source/screens/scriptBrowse.cpp +++ b/source/screens/scriptBrowse.cpp @@ -33,12 +33,6 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button); -nlohmann::json infoJson; - -#define metaFile "sdmc:/3ds/Universal-Updater/ScriptInfo.json" - -std::string maxScripts; - void fixInfo(nlohmann::json &json) { for(uint i=0;i infoJson[selection]["revision"]) { + } else if(infoJson[Selection]["curRevision"] > infoJson[Selection]["revision"]) { Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 370); } GFX::DrawBottom(); @@ -137,40 +139,96 @@ void ScriptBrowse::Draw(void) const { GFX::DrawSpriteBlend(sprites_view_idx, arrowPos[4].x, arrowPos[4].y); //Gui::spriteBlend(sprites_search_idx, arrowPos[5].x, arrowPos[5].y); - Gui::DrawStringCentered(-23, 1, 0.6f, Config::TxtColor, std::to_string(selection + 1) + " / " + maxScripts); + Gui::DrawStringCentered(0, 1, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts)); if (Config::viewMode == 0) { for(int i=0;i infoJson[screenPos+i]["revision"]) { + Gui::Draw_Rect(295, 45+(i*59), 20, 20, C2D_Color32(255, 255, 0, 255)); } - Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["title"], 320); - Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["author"], 320); + + Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["title"], 317); + Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, infoJson[screenPos+i]["author"], 317); } } else if (Config::viewMode == 1) { for(int i=0;i infoJson[screenPosList+i]["revision"]) { + Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, C2D_Color32(255, 255, 0, 255)); } - Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, Config::TxtColor, infoJson[screenPosList+i]["title"], 320); + + Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, Config::TxtColor, infoJson[screenPosList+i]["title"], 317); } } } +void ScriptBrowse::DrawGlossary(void) const { + GFX::DrawTop(); + if (Config::UseBars == true) { + Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400); + } else { + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400); + } + + Gui::Draw_Rect(20, 30, 30, 30, C2D_Color32(255, 128, 0, 255)); + Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("SCRIPT_NOT_FOUND"), 300); + + Gui::Draw_Rect(20, 70, 30, 30, C2D_Color32(0xfb, 0x5b, 0x5b, 255)); + Gui::DrawString(65, 75, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 300); + + Gui::Draw_Rect(20, 110, 30, 30, C2D_Color32(0xa5, 0xdd, 0x81, 255)); + Gui::DrawString(65, 115, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 300); + + Gui::Draw_Rect(20, 150, 30, 30, C2D_Color32(255, 255, 0, 255)); + Gui::DrawString(65, 155, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 300); + + Gui::DrawString(15, 185, 0.7f, Config::TxtColor, std::to_string(int64_t(infoJson[Selection]["curRevision"])) + " | " + std::to_string(int64_t(infoJson[Selection]["revision"])), 40); + Gui::DrawString(65, 185, 0.7f, Config::TxtColor, Lang::get("REVISION"), 300); + GFX::DrawBottom(); + + GFX::DrawSpriteBlend(sprites_download_all_idx, 20, 40); + Gui::DrawString(50, 42, 0.6f, Config::TxtColor, Lang::get("DOWNLOAD_ALL"), 260); + GFX::DrawSpriteBlend(sprites_view_idx, 20, 70); + Gui::DrawString(50, 72, 0.6f, Config::TxtColor, Lang::get("CHANGE_VIEW_MODE"), 260); + + GFX::DrawArrow(20, 100); + Gui::DrawString(50, 102, 0.6f, Config::TxtColor, Lang::get("ENTRY_UP"), 260); + GFX::DrawArrow(42, 155, 180.0); + Gui::DrawString(50, 132, 0.6f, Config::TxtColor, Lang::get("ENTRY_DOWN"), 260); + GFX::DrawArrow(20, 160, 0, 1); + Gui::DrawString(50, 162, 0.6f, Config::TxtColor, Lang::get("GO_BACK"), 260); + + Gui::DrawString(10, 192, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts), 35); + Gui::DrawString(50, 192, 0.6f, Config::TxtColor, Lang::get("ENTRY"), 260); + + GFX::DrawArrow(0, 218, 0, 1); +} + void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (keyRepeatDelay) keyRepeatDelay--; if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { @@ -179,133 +237,141 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { return; } - if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) { - if (selection < (int)infoJson.size()-1) { - selection++; - } else { - selection = 0; + if (mode == 0) { + if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) { + if (Selection < (int)infoJson.size()-1) { + Selection++; + } else { + Selection = 0; + } + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } } - if (fastMode == true) { - keyRepeatDelay = 3; - } else if (fastMode == false){ - keyRepeatDelay = 6; - } - } - if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) { - if (selection > 0) { - selection--; - } else { - selection = (int)infoJson.size()-1; + if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) { + if (Selection > 0) { + Selection--; + } else { + Selection = (int)infoJson.size()-1; + } + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } } - if (fastMode == true) { - keyRepeatDelay = 3; - } else if (fastMode == false){ - keyRepeatDelay = 6; - } - } - if (hDown & KEY_TOUCH) { - if (Config::viewMode == 0) { - for(int i=0;i 40+(i*57) && touch.py < 40+(i*57)+45) { - if (infoJson.size() != 0) { - std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPos + i]["title"]); - std::string titleFix = infoJson[screenPos + i]["title"]; - for (int l = 0; l < (int)titleFix.size(); l++) { - if (titleFix[l] == '/') { - titleFix[l] = '-'; + if (hDown & KEY_TOUCH) { + if (Config::viewMode == 0) { + for(int i=0;i 40+(i*57) && touch.py < 40+(i*57)+45) { + if (infoJson.size() != 0) { + std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPos + i]["title"]); + std::string titleFix = infoJson[screenPos + i]["title"]; + for (int l = 0; l < (int)titleFix.size(); l++) { + if (titleFix[l] == '/') { + titleFix[l] = '-'; + } } + Msg::DisplayMsg(fileName); + downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json"); + infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"]; } - Msg::DisplayMsg(fileName); - downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json"); - infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"]; } } + } else if (Config::viewMode == 1) { + for(int i=0;i (i+1)*27 && touch.py < (i+2)*27) { + if (infoJson.size() != 0) { + std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPosList + i]["title"]); + std::string titleFix = infoJson[screenPosList + i]["title"]; + for (int l = 0; l < (int)titleFix.size(); l++) { + if (titleFix[l] == '/') { + titleFix[l] = '-'; + } + } + Msg::DisplayMsg(fileName); + downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json"); + infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"]; + } + } + } + } + } + + if (hDown & KEY_A) { + if (infoJson.size() != 0) { + std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[Selection]["title"]); + + std::string titleFix = infoJson[Selection]["title"]; + for (int i = 0; i < (int)titleFix.size(); i++) { + if (titleFix[i] == '/') { + titleFix[i] = '-'; + } + } + Msg::DisplayMsg(fileName); + + downloadToFile(infoJson[Selection]["url"], Config::ScriptPath + titleFix + ".json"); + infoJson[Selection]["curRevision"] = infoJson[Selection]["revision"]; + } + } + + if (hDown & KEY_R) { + fastMode = true; + } + + if (hDown & KEY_L) { + fastMode = false; + } + + if ((hDown & KEY_X) || (hDown & KEY_TOUCH && touching(touch, arrowPos[4]))) { + if (Config::viewMode == 0) { + Config::viewMode = 1; + } else { + Config::viewMode = 0; + } + } + + if (Config::viewMode == 0) { + if(Selection < screenPos) { + screenPos = Selection; + } else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) { + screenPos = Selection - ENTRIES_PER_SCREEN + 1; } } else if (Config::viewMode == 1) { - for(int i=0;i (i+1)*27 && touch.py < (i+2)*27) { - if (infoJson.size() != 0) { - std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPosList + i]["title"]); - std::string titleFix = infoJson[screenPosList + i]["title"]; - for (int l = 0; l < (int)titleFix.size(); l++) { - if (titleFix[l] == '/') { - titleFix[l] = '-'; - } + if(Selection < screenPosList) { + screenPosList = Selection; + } else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) { + screenPosList = Selection - ENTRIES_PER_LIST + 1; + } + } + + if ((hDown & KEY_Y) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) { + if (infoJson.size() != 0) { + for (int i = 0; i < (int)infoJson.size(); i++) { + int current = i+1; + int total = infoJson.size(); + std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[i]["title"]); + std::string titleFix = infoJson[i]["title"]; + for (int l = 0; l < (int)titleFix.size(); l++) { + if (titleFix[l] == '/') { + titleFix[l] = '-'; } - Msg::DisplayMsg(fileName); - downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json"); - infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"]; } + Msg::DisplayMsg(fileName + " " + std::to_string(current) + " / " + std::to_string(total)); + downloadToFile(infoJson[i]["url"], Config::ScriptPath + titleFix + ".json"); + infoJson[i]["curRevision"] = infoJson[i]["revision"]; } } } } - if (hDown & KEY_A) { - if (infoJson.size() != 0) { - std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[selection]["title"]); - - std::string titleFix = infoJson[selection]["title"]; - for (int i = 0; i < (int)titleFix.size(); i++) { - if (titleFix[i] == '/') { - titleFix[i] = '-'; - } - } - Msg::DisplayMsg(fileName); - - downloadToFile(infoJson[selection]["url"], Config::ScriptPath + titleFix + ".json"); - infoJson[selection]["curRevision"] = infoJson[selection]["revision"]; - } - } - - if (hDown & KEY_R) { - fastMode = true; - } - - if (hDown & KEY_L) { - fastMode = false; - } - - if ((hDown & KEY_X) || (hDown & KEY_TOUCH && touching(touch, arrowPos[4]))) { - if (Config::viewMode == 0) { - Config::viewMode = 1; - } else { - Config::viewMode = 0; - } - } - - if (Config::viewMode == 0) { - if(selection < screenPos) { - screenPos = selection; - } else if (selection > screenPos + ENTRIES_PER_SCREEN - 1) { - screenPos = selection - ENTRIES_PER_SCREEN + 1; - } - } else if (Config::viewMode == 1) { - if(selection < screenPosList) { - screenPosList = selection; - } else if (selection > screenPosList + ENTRIES_PER_LIST - 1) { - screenPosList = selection - ENTRIES_PER_LIST + 1; - } - } - - if ((hDown & KEY_Y) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) { - if (infoJson.size() != 0) { - for (int i = 0; i < (int)infoJson.size(); i++) { - int current = i+1; - int total = infoJson.size(); - std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[i]["title"]); - std::string titleFix = infoJson[i]["title"]; - for (int l = 0; l < (int)titleFix.size(); l++) { - if (titleFix[l] == '/') { - titleFix[l] = '-'; - } - } - Msg::DisplayMsg(fileName + " " + std::to_string(current) + " / " + std::to_string(total)); - downloadToFile(infoJson[i]["url"], Config::ScriptPath + titleFix + ".json"); - infoJson[i]["curRevision"] = infoJson[i]["revision"]; - } - } + // Switch to Glossary and back. + if (hDown & KEY_RIGHT || hDown & KEY_LEFT) { + if (mode == 0) mode = 1; + else mode = 0; } } \ No newline at end of file diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index ee92509..6086383 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -28,7 +28,6 @@ #include "mainMenu.hpp" #include "scriptBrowse.hpp" #include "scriptCreator.hpp" -#include "scriptHelper.hpp" #include "scriptlist.hpp" #include @@ -40,25 +39,10 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button); extern bool checkWifiStatus(void); extern void notImplemented(void); -// This is for the Script Creator, so no one can access it for now, until it is stable or so. -bool isTesting = false; - bool isScriptSelected = false; -// Information like Title and Author. -struct Info { - std::string title; - std::string author; - std::string shortDesc; -}; - -std::string choice; -std::string currentFile; -std::string selectedTitle; -std::string Desc = ""; -nlohmann::json jsonFile; - -Info parseInfo(std::string fileName) { +// Parse the script for the list. +ScriptInfo parseInfo(std::string fileName) { FILE* file = fopen(fileName.c_str(), "rt"); if(!file) { printf("File not found\n"); @@ -67,14 +51,15 @@ Info parseInfo(std::string fileName) { nlohmann::json json = nlohmann::json::parse(file, nullptr, false); fclose(file); - Info info; + ScriptInfo info; info.title = ScriptHelper::getString(json, "info", "title"); info.author = ScriptHelper::getString(json, "info", "author"); info.shortDesc = ScriptHelper::getString(json, "info", "shortDesc"); return info; } -void checkForValidate(void) { +// Check if Script version has the current version. +void ScriptList::checkForValidate(void) { FILE* file = fopen(currentFile.c_str(), "rt"); nlohmann::json json = nlohmann::json::parse(file, nullptr, false); fclose(file); @@ -84,7 +69,8 @@ void checkForValidate(void) { } } -nlohmann::json openScriptFile() { +// Open a script file and return it to a JSON. +nlohmann::json ScriptList::openScriptFile() { FILE* file = fopen(currentFile.c_str(), "rt"); nlohmann::json jsonFile; if(file) jsonFile = nlohmann::json::parse(file, nullptr, false); @@ -92,7 +78,7 @@ nlohmann::json openScriptFile() { return jsonFile; } -// Objects like Release or Nightly. +// Parse the objects from a script. std::vector parseObjects(std::string fileName) { FILE* file = fopen(fileName.c_str(), "rt"); if(!file) { @@ -111,6 +97,7 @@ std::vector parseObjects(std::string fileName) { return objs; } +// Parse the description from the script. std::string Description(nlohmann::json &json) { std::string out = ""; if (json.at("info").contains("description")) out = json.at("info").at("description"); @@ -118,7 +105,667 @@ std::string Description(nlohmann::json &json) { return out; } -void runFunctions(nlohmann::json &json) { + +// Return the color for the script. +u32 getColor(std::string colorString) { + if(colorString.length() < 7 || std::regex_search(colorString.substr(1), std::regex("[^0-9a-f]"))) { // invalid color + return 0; + } + + int r = std::stoi(colorString.substr(1, 2), nullptr, 16); + int g = std::stoi(colorString.substr(3, 2), nullptr, 16); + int b = std::stoi(colorString.substr(5, 2), nullptr, 16); + return RGBA8(r, g, b, 0xFF); +} + +// Color listing! +u32 barColor; +u32 bgTopColor; +u32 bgBottomColor; +u32 TextColor; +u32 selected; +u32 unselected; +u32 progressBar; + +// Load the colors from the script. +void loadColors(nlohmann::json &json) { + u32 colorTemp; + colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor")); + barColor = colorTemp == 0 ? Config::Color1 : colorTemp; + + colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor")); + bgTopColor = colorTemp == 0 ? Config::Color2 : colorTemp; + + colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor")); + bgBottomColor = colorTemp == 0 ? Config::Color3 : colorTemp; + + colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor")); + TextColor = colorTemp == 0 ? Config::TxtColor : colorTemp; + + colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor")); + selected = colorTemp == 0 ? Config::SelectedColor : colorTemp; + + colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor")); + unselected = colorTemp == 0 ? Config::UnselectedColor : colorTemp; + + colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor")); + progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp; +} + +void ScriptList::DrawSubMenu(void) const { + GFX::DrawTop(); + if (Config::UseBars == true) { + Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400); + } else { + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400); + } + + GFX::DrawBottom(); + GFX::DrawArrow(0, 218, 0, 1); + + for (int i = 0; i < 4; i++) { + Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::UnselectedColor); + if (Selection == i) { + Gui::drawAnimatedSelector(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, .060, TRANSPARENT, Config::SelectedColor); + } + } + + Gui::DrawStringCentered(-80, subPos[0].y+12, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 130); + Gui::DrawStringCentered(80, subPos[1].y+12, 0.6f, Config::TxtColor, Lang::get("GET_SCRIPTS"), 130); + Gui::DrawStringCentered(-80, subPos[2].y+12, 0.6f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 130); + Gui::DrawStringCentered(80, subPos[3].y+12, 0.6f, Config::TxtColor, Lang::get("CHANGE_SCRIPTPATH"), 130); +} + +// Load the description. +void ScriptList::loadDesc(void) { + lines.clear(); + while(Desc.find('\n') != Desc.npos) { + lines.push_back(Desc.substr(0, Desc.find('\n'))); + Desc = Desc.substr(Desc.find('\n')+1); + } + lines.push_back(Desc.substr(0, Desc.find('\n'))); +} + +// MUST be included there and not in the Header. +extern int AutobootWhat; +bool changeBackHandle = false; + +ScriptList::ScriptList() { + if (AutobootWhat == 2) { + // If Script isn't found, go to MainMenu. + if (access(Config::AutobootFile.c_str(), F_OK) != 0) { + AutobootWhat = 0; + changeBackHandle = true; + Gui::setScreen(std::make_unique()); + } + + if (ScriptHelper::checkIfValid(Config::AutobootFile) == true) { + ScriptInfo fI = parseInfo(Config::AutobootFile); + currentFile = Config::AutobootFile; + selectedTitle = fI.title; + jsonFile = openScriptFile(); + Desc = Description(jsonFile); + checkForValidate(); + fileInfo2 = parseObjects(currentFile); + loadColors(jsonFile); + loadDesc(); + isScriptSelected = true; + Selection = 0; + mode = 2; + changeBackHandle = true; + AutobootWhat = 0; + } else { + AutobootWhat = 0; + changeBackHandle = true; + Gui::setScreen(std::make_unique()); + } + } +} + +void ScriptList::DrawList(void) const { + std::string line1; + std::string line2; + std::string scriptAmount = std::to_string(Selection +1) + " | " + std::to_string(fileInfo.size()); + GFX::DrawTop(); + if (Config::UseBars == true) { + Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400); + Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 239-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, Config::TxtColor, scriptAmount); + } else { + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); + Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 237-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, Config::TxtColor, scriptAmount); + } + Gui::DrawStringCentered(0, 80, 0.7f, Config::TxtColor, Lang::get("TITLE") + std::string(fileInfo[Selection].title), 400); + Gui::DrawStringCentered(0, 100, 0.7f, Config::TxtColor, Lang::get("AUTHOR") + std::string(fileInfo[Selection].author), 400); + Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(fileInfo[Selection].shortDesc), 400); + + GFX::DrawBottom(); + GFX::DrawArrow(295, -1); + GFX::DrawArrow(315, 240, 180.0); + GFX::DrawArrow(0, 218, 0, 1); + GFX::DrawSpriteBlend(sprites_view_idx, arrowPos[3].x, arrowPos[3].y); + + if (Config::viewMode == 0) { + for(int i=0;i()); + } else { + Gui::screenBack(); + return; + } + } + + // 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++; + } + + if (hDown & KEY_A) { + switch(Selection) { + case 0: + if (returnIfExist(Config::ScriptPath, {"json"}) == true) { + Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); + dirContents.clear(); + chdir(Config::ScriptPath.c_str()); + getDirectoryContents(dirContents, {"json"}); + for(uint i=0;i()); + } else { + notConnectedMsg(); + } + break; + case 2: + if (isTesting == true) { + Gui::setScreen(std::make_unique()); + } else { + notImplemented(); + } + break; + case 3: + std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); + if (tempScript != "") { + Config::ScriptPath = tempScript; + } + break; + } + } + + if (hDown & KEY_TOUCH) { + if (touching(touch, subPos[0])) { + if (returnIfExist(Config::ScriptPath, {"json"}) == true) { + Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); + dirContents.clear(); + chdir(Config::ScriptPath.c_str()); + getDirectoryContents(dirContents, {"json"}); + for(uint i=0;i()); + } else { + notConnectedMsg(); + } + } else if (touching(touch, subPos[2])) { + if (isTesting == true) { + Gui::setScreen(std::make_unique()); + } else { + notImplemented(); + } + } else if (touching(touch, subPos[3])) { + std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); + if (tempScript != "") { + Config::ScriptPath = tempScript; + } + } + } +} + +void ScriptList::deleteScript(int selectedScript) { + std::string path = Config::ScriptPath; + path += dirContents[selectedScript].name; + deleteFile(path.c_str()); + // Refresh the list. + Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); + Selection = 0; + dirContents.clear(); + fileInfo.clear(); + chdir(Config::ScriptPath.c_str()); + getDirectoryContents(dirContents, {"json"}); + for(uint i=0;i 0) { + Selection--; + } else { + Selection = (int)fileInfo.size()-1; + } + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } + } + + if (hDown & KEY_TOUCH) { + if (Config::viewMode == 0) { + for(int i=0;i 40+(i*57) && touch.py < 40+(i*57)+45) { + if (dirContents[screenPos + i].isDirectory) { + } else if (fileInfo.size() != 0) { + if (ScriptHelper::checkIfValid(dirContents[screenPos + i].name) == true) { + currentFile = dirContents[screenPos + i].name; + selectedTitle = fileInfo[screenPos + i].title; + jsonFile = openScriptFile(); + Desc = Description(jsonFile); + checkForValidate(); + fileInfo2 = parseObjects(currentFile); + loadColors(jsonFile); + loadDesc(); + isScriptSelected = true; + Selection = 0; + mode = 2; + } + } + } + } + } else if (Config::viewMode == 1) { + for(int i=0;i (i+1)*27 && touch.py < (i+2)*27) { + if (dirContents[screenPosList + i].isDirectory) { + } else if (fileInfo.size() != 0) { + if (ScriptHelper::checkIfValid(dirContents[screenPosList + i].name) == true) { + currentFile = dirContents[screenPosList + i].name; + selectedTitle = fileInfo[screenPosList + i].title; + jsonFile = openScriptFile(); + Desc = Description(jsonFile); + checkForValidate(); + fileInfo2 = parseObjects(currentFile); + loadColors(jsonFile); + loadDesc(); + isScriptSelected = true; + Selection = 0; + mode = 2; + } + } + } + } + } + } + + if (hDown & KEY_A) { + if (dirContents[Selection].isDirectory) { + } else if (fileInfo.size() != 0) { + if (ScriptHelper::checkIfValid(dirContents[Selection].name) == true) { + currentFile = dirContents[Selection].name; + selectedTitle = fileInfo[Selection].title; + jsonFile = openScriptFile(); + Desc = Description(jsonFile); + checkForValidate(); + fileInfo2 = parseObjects(currentFile); + loadColors(jsonFile); + loadDesc(); + isScriptSelected = true; + Selection = 0; + mode = 2; + } + } + } + + if (hDown & KEY_R) { + fastMode = true; + } + + if (hDown & KEY_L) { + fastMode = false; + } + + if (Config::viewMode == 0) { + if(Selection < screenPos) { + screenPos = Selection; + } else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) { + screenPos = Selection - ENTRIES_PER_SCREEN + 1; + } + } else if (Config::viewMode == 1) { + if(Selection < screenPosList) { + screenPosList = Selection; + } else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) { + screenPosList = Selection - ENTRIES_PER_LIST + 1; + } + } +} + +void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) { + if (keyRepeatDelay) keyRepeatDelay--; + + if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { + Selection = 0; + fileInfo2.clear(); + isScriptSelected = false; + refreshList(); + } + + if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) { + if (Selection < (int)fileInfo2.size()-1) { + Selection++; + } else { + Selection = 0; + } + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } + } + + if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) { + if (Selection > 0) { + Selection--; + } else { + Selection = (int)fileInfo2.size()-1; + } + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } + } + + if (hDown & KEY_TOUCH) { + if (Config::viewMode == 0) { + for(int i=0;i 40+(i*57) && touch.py < 40+(i*57)+45) { + if (fileInfo2.size() != 0) { + choice = fileInfo2[screenPos + i]; + runFunctions(jsonFile); + } + } + } + } else if (Config::viewMode == 1) { + for(int i=0;i (i+1)*27 && touch.py < (i+2)*27) { + if (fileInfo2.size() != 0) { + choice = fileInfo2[screenPosList + i]; + if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n\n" + choice)) { + runFunctions(jsonFile); + } + } + } + } + } + } + + if (hDown & KEY_A) { + if (fileInfo2.size() != 0) { + choice = fileInfo2[Selection]; + if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n\n" + choice)) { + runFunctions(jsonFile); + } + } + } + + if (hDown & KEY_R) { + fastMode = true; + } + + if (hDown & KEY_L) { + fastMode = false; + } + + if (hDown & KEY_SELECT) { + Config::Color1 = barColor; + Config::Color2 = bgTopColor; + Config::Color3 = bgBottomColor; + Config::TxtColor = TextColor; + Config::SelectedColor = selected; + Config::UnselectedColor = unselected; + Config::save(); + } + + if (Config::viewMode == 0) { + if(Selection < screenPos) { + screenPos = Selection; + } else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) { + screenPos = Selection - ENTRIES_PER_SCREEN + 1; + } + } else if (Config::viewMode == 1) { + if(Selection < screenPosList) { + screenPosList = Selection; + } else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) { + screenPosList = Selection - ENTRIES_PER_LIST + 1; + } + } +} + +void ScriptList::Logic(u32 hDown, u32 hHeld, touchPosition touch) { + if (mode == 0) { + SubMenuLogic(hDown, hHeld, touch); + } else if (mode == 1) { + ListSelection(hDown, hHeld, touch); + } else if (mode == 2) { + SelectFunction(hDown, hHeld, touch); + } + + if ((hDown & KEY_X) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) { + if (Config::viewMode == 0) { + Config::viewMode = 1; + } else { + Config::viewMode = 0; + } + } + + if (hDown & KEY_LEFT || hDown & KEY_RIGHT) { + if (mode == 3) { + mode = lastMode; + } else if (mode == 1) { + mode = 3; + lastMode = 1; // To go back after it. + } else if (mode == 2) { + mode = 3; + lastMode = 2; + } + } +} + +void ScriptList::DrawGlossary(void) const { + GFX::DrawTop(); + if (Config::UseBars == true) { + Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400); + } else { + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400); + } + + if (lastMode == 1) { + Gui::DrawString(15, 35, 0.7f, Config::TxtColor, std::to_string(Selection +1) + " | " + std::to_string(fileInfo.size()), 40); + Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("ENTRY"), 300); + } else if (lastMode == 2) { + Gui::DrawString(15, 35, 0.7f, Config::TxtColor, std::to_string(Selection+1) + " | " + std::to_string(fileInfo2.size()), 40); + Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("ENTRY"), 300); + } + GFX::DrawBottom(); + + GFX::DrawSpriteBlend(sprites_view_idx, 20, 40); + Gui::DrawString(50, 42, 0.6f, Config::TxtColor, Lang::get("CHANGE_VIEW_MODE"), 260); + + GFX::DrawArrow(20, 70); + Gui::DrawString(50, 72, 0.6f, Config::TxtColor, Lang::get("ENTRY_UP"), 260); + GFX::DrawArrow(42, 125, 180.0); + Gui::DrawString(50, 102, 0.6f, Config::TxtColor, Lang::get("ENTRY_DOWN"), 260); + GFX::DrawArrow(20, 130, 0, 1); + Gui::DrawString(50, 132, 0.6f, Config::TxtColor, Lang::get("GO_BACK"), 260); + GFX::DrawArrow(0, 218, 0, 1); +} + +// Execute | run the script. +void ScriptList::runFunctions(nlohmann::json &json) { for(int i=0;i<(int)json.at(choice).size();i++) { std::string type = json.at(choice).at(i).at("type"); @@ -210,8 +857,10 @@ void runFunctions(nlohmann::json &json) { seconds = json.at(choice).at(i).at("seconds"); else missing = true; if(!missing) ScriptHelper::displayTimeMsg(message, seconds); + } else if (type == "saveConfig") { Config::save(); + } else if (type == "deleteTitle") { std::string TitleID = ""; std::string message = ""; @@ -223,6 +872,7 @@ void runFunctions(nlohmann::json &json) { if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message"); else missing = true; if(!missing) ScriptHelper::deleteTitle(TitleID, isNAND, message); + } else if (type == "bootTitle") { std::string TitleID = ""; std::string message = ""; @@ -237,616 +887,4 @@ void runFunctions(nlohmann::json &json) { } } doneMsg(); -} - - -std::vector fileInfo; -std::vector fileInfo2; -std::vector lines; - - -u32 getColor(std::string colorString) { - if(colorString.length() < 7 || std::regex_search(colorString.substr(1), std::regex("[^0-9a-f]"))) { // invalid color - return 0; - } - - int r = std::stoi(colorString.substr(1, 2), nullptr, 16); - int g = std::stoi(colorString.substr(3, 2), nullptr, 16); - int b = std::stoi(colorString.substr(5, 2), nullptr, 16); - return RGBA8(r, g, b, 0xFF); -} - -// Color listing! -u32 barColor; -u32 bgTopColor; -u32 bgBottomColor; -u32 TextColor; -u32 selected; -u32 unselected; -u32 progressBar; - -void loadColors(nlohmann::json &json) { - u32 colorTemp; - colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor")); - barColor = colorTemp == 0 ? Config::Color1 : colorTemp; - - colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor")); - bgTopColor = colorTemp == 0 ? Config::Color2 : colorTemp; - - colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor")); - bgBottomColor = colorTemp == 0 ? Config::Color3 : colorTemp; - - colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor")); - TextColor = colorTemp == 0 ? Config::TxtColor : colorTemp; - - colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor")); - selected = colorTemp == 0 ? Config::SelectedColor : colorTemp; - - colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor")); - unselected = colorTemp == 0 ? Config::UnselectedColor : colorTemp; - - colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor")); - progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp; -} - -void ScriptList::DrawSubMenu(void) const { - GFX::DrawTop(); - if (Config::UseBars == true) { - Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400); - } else { - Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400); - } - - GFX::DrawBottom(); - GFX::DrawArrow(0, 218, 0, 1); - - for (int i = 0; i < 4; i++) { - Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::UnselectedColor); - if (SubSelection == i) { - Gui::drawAnimatedSelector(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, .060, TRANSPARENT, Config::SelectedColor); - } - } - - Gui::DrawStringCentered(-80, subPos[0].y+12, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 130); - Gui::DrawStringCentered(80, subPos[1].y+12, 0.6f, Config::TxtColor, Lang::get("GET_SCRIPTS"), 130); - Gui::DrawStringCentered(-80, subPos[2].y+12, 0.6f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 130); - Gui::DrawStringCentered(80, subPos[3].y+12, 0.6f, Config::TxtColor, Lang::get("CHANGE_SCRIPTPATH"), 130); -} - -void loadDesc(void) { - lines.clear(); - while(Desc.find('\n') != Desc.npos) { - lines.push_back(Desc.substr(0, Desc.find('\n'))); - Desc = Desc.substr(Desc.find('\n')+1); - } - lines.push_back(Desc.substr(0, Desc.find('\n'))); -} - -extern int AutobootWhat; -bool changeBackHandle = false; - -ScriptList::ScriptList() { - if (AutobootWhat == 2) { - // If Script isn't found, go to MainMenu. - if (access(Config::AutobootFile.c_str(), F_OK) != 0) { - AutobootWhat = 0; - changeBackHandle = true; - Gui::setScreen(std::make_unique()); - } - - if (ScriptHelper::checkIfValid(Config::AutobootFile) == true) { - Info fI = parseInfo(Config::AutobootFile); - currentFile = Config::AutobootFile; - selectedTitle = fI.title; - jsonFile = openScriptFile(); - Desc = Description(jsonFile); - checkForValidate(); - fileInfo2 = parseObjects(currentFile); - loadColors(jsonFile); - loadDesc(); - isScriptSelected = true; - selection = 0; - mode = 2; - changeBackHandle = true; - AutobootWhat = 0; - } else { - AutobootWhat = 0; - changeBackHandle = true; - Gui::setScreen(std::make_unique()); - } - } -} - -void ScriptList::DrawList(void) const { - std::string line1; - std::string line2; - std::string scriptAmount = std::to_string(selection +1) + " / " + std::to_string(fileInfo.size()); - GFX::DrawTop(); - if (Config::UseBars == true) { - Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400); - Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 239-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, Config::TxtColor, scriptAmount); - } else { - Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400); - Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 237-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, Config::TxtColor, scriptAmount); - } - Gui::DrawStringCentered(0, 80, 0.7f, Config::TxtColor, Lang::get("TITLE") + std::string(fileInfo[selection].title), 400); - Gui::DrawStringCentered(0, 100, 0.7f, Config::TxtColor, Lang::get("AUTHOR") + std::string(fileInfo[selection].author), 400); - Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(fileInfo[selection].shortDesc), 400); - - GFX::DrawBottom(); - GFX::DrawArrow(295, -1); - GFX::DrawArrow(315, 240, 180.0); - GFX::DrawArrow(0, 218, 0, 1); - GFX::DrawSpriteBlend(sprites_view_idx, arrowPos[3].x, arrowPos[3].y); - - if (Config::viewMode == 0) { - for(int i=0;i()); - } else { - Gui::screenBack(); - return; - } - } - - // Navigation. - if(hDown & KEY_UP) { - if(SubSelection > 1) SubSelection -= 2; - } else if(hDown & KEY_DOWN) { - if(SubSelection < 3 && SubSelection != 2 && SubSelection != 3) SubSelection += 2; - } else if (hDown & KEY_LEFT) { - if (SubSelection%2) SubSelection--; - } else if (hDown & KEY_RIGHT) { - if (!(SubSelection%2)) SubSelection++; - } - - if (hDown & KEY_A) { - switch(SubSelection) { - case 0: - if (returnIfExist(Config::ScriptPath, {"json"}) == true) { - Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); - dirContents.clear(); - chdir(Config::ScriptPath.c_str()); - getDirectoryContents(dirContents, {"json"}); - for(uint i=0;i()); - } else { - notConnectedMsg(); - } - break; - case 2: - if (isTesting == true) { - Gui::setScreen(std::make_unique()); - } else { - notImplemented(); - } - break; - case 3: - std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); - if (tempScript != "") { - Config::ScriptPath = tempScript; - } - break; - } - } - - if (hDown & KEY_TOUCH) { - if (touching(touch, subPos[0])) { - if (returnIfExist(Config::ScriptPath, {"json"}) == true) { - Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); - dirContents.clear(); - chdir(Config::ScriptPath.c_str()); - getDirectoryContents(dirContents, {"json"}); - for(uint i=0;i()); - } else { - notConnectedMsg(); - } - } else if (touching(touch, subPos[2])) { - if (isTesting == true) { - Gui::setScreen(std::make_unique()); - } else { - notImplemented(); - } - } else if (touching(touch, subPos[3])) { - std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); - if (tempScript != "") { - Config::ScriptPath = tempScript; - } - } - } -} - -void ScriptList::deleteScript(int selectedScript) { - std::string path = Config::ScriptPath; - path += dirContents[selectedScript].name; - deleteFile(path.c_str()); - // Refresh the list. - Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); - dirContents.clear(); - fileInfo.clear(); - chdir(Config::ScriptPath.c_str()); - getDirectoryContents(dirContents, {"json"}); - for(uint i=0;i 0) { - selection--; - } else { - selection = (int)fileInfo.size()-1; - } - if (fastMode == true) { - keyRepeatDelay = 3; - } else if (fastMode == false){ - keyRepeatDelay = 6; - } - } - - if (hDown & KEY_TOUCH) { - if (Config::viewMode == 0) { - for(int i=0;i 40+(i*57) && touch.py < 40+(i*57)+45) { - if (dirContents[screenPos + i].isDirectory) { - } else if (fileInfo.size() != 0) { - if (ScriptHelper::checkIfValid(dirContents[screenPos + i].name) == true) { - currentFile = dirContents[screenPos + i].name; - selectedTitle = fileInfo[screenPos + i].title; - jsonFile = openScriptFile(); - Desc = Description(jsonFile); - checkForValidate(); - fileInfo2 = parseObjects(currentFile); - loadColors(jsonFile); - loadDesc(); - isScriptSelected = true; - selection = 0; - mode = 2; - } - } - } - } - } else if (Config::viewMode == 1) { - for(int i=0;i (i+1)*27 && touch.py < (i+2)*27) { - if (dirContents[screenPosList + i].isDirectory) { - } else if (fileInfo.size() != 0) { - if (ScriptHelper::checkIfValid(dirContents[screenPosList + i].name) == true) { - currentFile = dirContents[screenPosList + i].name; - selectedTitle = fileInfo[screenPosList + i].title; - jsonFile = openScriptFile(); - Desc = Description(jsonFile); - checkForValidate(); - fileInfo2 = parseObjects(currentFile); - loadColors(jsonFile); - loadDesc(); - isScriptSelected = true; - selection = 0; - mode = 2; - } - } - } - } - } - } - - if (hDown & KEY_A) { - if (dirContents[selection].isDirectory) { - } else if (fileInfo.size() != 0) { - if (ScriptHelper::checkIfValid(dirContents[selection].name) == true) { - currentFile = dirContents[selection].name; - selectedTitle = fileInfo[selection].title; - jsonFile = openScriptFile(); - Desc = Description(jsonFile); - checkForValidate(); - fileInfo2 = parseObjects(currentFile); - loadColors(jsonFile); - loadDesc(); - isScriptSelected = true; - selection = 0; - mode = 2; - } - } - } - - if (hDown & KEY_R) { - fastMode = true; - } - - if (hDown & KEY_L) { - fastMode = false; - } - - if (Config::viewMode == 0) { - if(selection < screenPos) { - screenPos = selection; - } else if (selection > screenPos + ENTRIES_PER_SCREEN - 1) { - screenPos = selection - ENTRIES_PER_SCREEN + 1; - } - } else if (Config::viewMode == 1) { - if(selection < screenPosList) { - screenPosList = selection; - } else if (selection > screenPosList + ENTRIES_PER_LIST - 1) { - screenPosList = selection - ENTRIES_PER_LIST + 1; - } - } -} - -void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) { - if (keyRepeatDelay) keyRepeatDelay--; - - if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { - selection2 = 0; - fileInfo2.clear(); - isScriptSelected = false; - refreshList(); - } - - if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) { - if (selection2 < (int)fileInfo2.size()-1) { - selection2++; - } else { - selection2 = 0; - } - if (fastMode == true) { - keyRepeatDelay = 3; - } else if (fastMode == false){ - keyRepeatDelay = 6; - } - } - - if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) { - if (selection2 > 0) { - selection2--; - } else { - selection2 = (int)fileInfo2.size()-1; - } - if (fastMode == true) { - keyRepeatDelay = 3; - } else if (fastMode == false){ - keyRepeatDelay = 6; - } - } - - if (hDown & KEY_TOUCH) { - if (Config::viewMode == 0) { - for(int i=0;i 40+(i*57) && touch.py < 40+(i*57)+45) { - if (fileInfo2.size() != 0) { - choice = fileInfo2[screenPos2 + i]; - runFunctions(jsonFile); - } - } - } - } else if (Config::viewMode == 1) { - for(int i=0;i (i+1)*27 && touch.py < (i+2)*27) { - if (fileInfo2.size() != 0) { - choice = fileInfo2[screenPosList2 + i]; - runFunctions(jsonFile); - } - } - } - } - } - - if (hDown & KEY_A) { - if (fileInfo2.size() != 0) { - choice = fileInfo2[selection2]; - runFunctions(jsonFile); - } - } - - if (hDown & KEY_R) { - fastMode = true; - } - - if (hDown & KEY_L) { - fastMode = false; - } - - if (hDown & KEY_SELECT) { - Config::Color1 = barColor; - Config::Color2 = bgTopColor; - Config::Color3 = bgBottomColor; - Config::TxtColor = TextColor; - Config::SelectedColor = selected; - Config::UnselectedColor = unselected; - Config::save(); - } - - if (Config::viewMode == 0) { - if(selection2 < screenPos2) { - screenPos2 = selection2; - } else if (selection2 > screenPos2 + ENTRIES_PER_SCREEN - 1) { - screenPos2 = selection2 - ENTRIES_PER_SCREEN + 1; - } - } else if (Config::viewMode == 1) { - if(selection2 < screenPosList2) { - screenPosList2 = selection2; - } else if (selection2 > screenPosList2 + ENTRIES_PER_LIST - 1) { - screenPosList2 = selection2 - ENTRIES_PER_LIST + 1; - } - } -} - - -void ScriptList::Logic(u32 hDown, u32 hHeld, touchPosition touch) { - if (mode == 0) { - SubMenuLogic(hDown, hHeld, touch); - } else if (mode == 1) { - ListSelection(hDown, hHeld, touch); - } else if (mode == 2) { - SelectFunction(hDown, hHeld, touch); - } - - if ((hDown & KEY_X) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) { - if (Config::viewMode == 0) { - Config::viewMode = 1; - } else { - Config::viewMode = 0; - } - } } \ No newline at end of file diff --git a/source/screens/unistore.cpp b/source/screens/unistore.cpp index 2f85450..17ed589 100644 --- a/source/screens/unistore.cpp +++ b/source/screens/unistore.cpp @@ -30,7 +30,6 @@ #include "json.hpp" #include "keyboard.hpp" #include "mainMenu.hpp" -#include "scriptHelper.hpp" #include "unistore.hpp" #include @@ -39,8 +38,6 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button); extern u32 getColor(std::string colorString); -nlohmann::json appStoreJson; -std::string currentStoreFile; extern bool isScriptSelected; extern u32 barColor; @@ -55,20 +52,8 @@ bool changeBackState = false; C2D_SpriteSheet appStoreSheet; -struct storeInfo2 { - std::string title; - std::string author; - std::string description; - std::string url; - std::string file; - std::string storeSheet; - std::string sheetURL; -}; - -storeInfo2 SI; - // Parse informations like URL, Title, Author, Description. -storeInfo2 parseStoreInfo(std::string fileName) { +StoreInfo parseStoreInfo(std::string fileName) { FILE* file = fopen(fileName.c_str(), "rt"); if(!file) { printf("File not found\n"); @@ -77,7 +62,7 @@ storeInfo2 parseStoreInfo(std::string fileName) { nlohmann::json json = nlohmann::json::parse(file, nullptr, false); fclose(file); - storeInfo2 info; + StoreInfo info; info.title = ScriptHelper::getString(json, "storeInfo", "title"); info.author = ScriptHelper::getString(json, "storeInfo", "author"); info.description = ScriptHelper::getString(json, "storeInfo", "description"); @@ -88,7 +73,7 @@ storeInfo2 parseStoreInfo(std::string fileName) { return info; } -nlohmann::json openStoreFile() { +nlohmann::json UniStore::openStoreFile() { FILE* file = fopen(currentStoreFile.c_str(), "rt"); nlohmann::json jsonFile; if(file) jsonFile = nlohmann::json::parse(file, nullptr, false); @@ -96,11 +81,6 @@ nlohmann::json openStoreFile() { return jsonFile; } -std::vector storeInfo; // Store selection. -std::vector appStoreList; // Actual store. ;P -std::vector descLines; -std::string storeDesc = ""; - // Parse the Objects. std::vector parseStoreObjects(std::string storeName) { FILE* file = fopen(storeName.c_str(), "rt"); @@ -122,7 +102,7 @@ std::vector parseStoreObjects(std::string storeName) { bool sheetHasLoaded = false; // Sheet / Icon stuff. -void loadStoreSheet(int pos) { +void UniStore::loadStoreSheet(int pos) { if (sheetHasLoaded == false) { appStoreSheet = C2D_SpriteSheetLoad(storeInfo[pos].storeSheet.c_str()); sheetHasLoaded = true; @@ -157,12 +137,12 @@ void drawNormal(int key, int x, int y) { } void UniStore::descript() { - if (storeInfo[selection].description != "" || storeInfo[selection].description != "MISSING: storeInfo.description") { - storeDesc = storeInfo[selection].description; + if (storeInfo[Selection].description != "" || storeInfo[Selection].description != "MISSING: storeInfo.description") { + storeDesc = storeInfo[Selection].description; } else storeDesc = ""; } -void loadStoreDesc(void) { +void UniStore::loadStoreDesc(void) { descLines.clear(); while(storeDesc.find('\n') != storeDesc.npos) { descLines.push_back(storeDesc.substr(0, storeDesc.find('\n'))); @@ -205,7 +185,8 @@ UniStore::UniStore() { changeBackState = true; Gui::setScreen(std::make_unique()); } - + + StoreInfo SI; // If WiFi enabled & File exist, update store. if (ScriptHelper::checkIfValid(Config::AutobootFile, 1) == true) { SI = parseStoreInfo(Config::AutobootFile); @@ -236,7 +217,7 @@ UniStore::UniStore() { appStoreJson = openStoreFile(); appStoreList = parseStoreObjects(currentStoreFile); loadStoreColors(appStoreJson); - selectedOptionAppStore = 0; + Selection = 0; displayInformations = handleIfDisplayText(); isScriptSelected = true; mode = 2; @@ -266,7 +247,7 @@ void UniStore::DrawSubMenu(void) const { for (int i = 0; i < 3; i++) { Gui::Draw_Rect(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, Config::UnselectedColor); - if (subSelection == i) { + if (Selection == i) { Gui::drawAnimatedSelector(subPos[i].x, subPos[i].y, subPos[i].w, subPos[i].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -281,13 +262,13 @@ void UniStore::DrawSubMenu(void) const { void UniStore::DrawStoreList(void) const { std::string line1; std::string line2; - std::string storeAmount = std::to_string(selection +1) + " / " + std::to_string(storeInfo.size()); + std::string storeAmount = std::to_string(Selection +1) + " / " + std::to_string(storeInfo.size()); GFX::DrawTop(); if (Config::UseBars == true) { - Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, storeInfo[selection].title, 400); + Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, storeInfo[Selection].title, 400); Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), 239-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, Config::TxtColor, storeAmount); } else { - Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, storeInfo[selection].title, 400); + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, storeInfo[Selection].title, 400); Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), 237-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, Config::TxtColor, storeAmount); } for(uint i=0;i 0) subSelection--; + if(Selection > 0) Selection--; } if (hDown & KEY_DOWN) { - if(subSelection < 2) subSelection++; + if(Selection < 2) Selection++; } if (hDown & KEY_A) { - switch(subSelection) { + switch(Selection) { case 0: if (returnIfExist(Config::StorePath, {"unistore"}) == true) { Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); @@ -512,6 +497,7 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { descript(); loadStoreDesc(); } + Selection = 0; mode = 1; } else { Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST")); @@ -519,6 +505,7 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { break; case 1: if (checkWifiStatus()) { + Selection = 0; mode = 3; } else { notConnectedMsg(); @@ -546,12 +533,14 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { descript(); loadStoreDesc(); } + Selection = 0; mode = 1; } else { Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST")); } } else if (touching(touch, subPos[1])) { if (checkWifiStatus() == true) { + Selection = 0; mode = 3; } else { notConnectedMsg(); @@ -571,6 +560,7 @@ void UniStore::deleteStore(int selectedStore) { deleteFile(path.c_str()); // Refresh the list. Msg::DisplayMsg(Lang::get("REFRESHING_LIST")); + Selection = 0; dirContents.clear(); storeInfo.clear(); chdir(Config::StorePath.c_str()); @@ -583,6 +573,7 @@ void UniStore::deleteStore(int selectedStore) { if (dirContents.size() == 0) { dirContents.clear(); storeInfo.clear(); + Selection = 0; mode = 0; } } @@ -606,16 +597,17 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { storeInfo.clear(); + Selection = 0; mode = 0; } if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) { - if (selection < (int)storeInfo.size()-1) { - selection++; + if (Selection < (int)storeInfo.size()-1) { + Selection++; descript(); loadStoreDesc(); } else { - selection = 0; + Selection = 0; descript(); loadStoreDesc(); } @@ -626,12 +618,12 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { } } if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) { - if (selection > 0) { - selection--; + if (Selection > 0) { + Selection--; descript(); loadStoreDesc(); } else { - selection = (int)storeInfo.size()-1; + Selection = (int)storeInfo.size()-1; descript(); loadStoreDesc(); } @@ -643,27 +635,28 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { } if ((hDown & KEY_Y) || (hDown & KEY_TOUCH && touching(touch, arrowPos[5]))) { - updateStore(selection); + updateStore(Selection); } if (hDown & KEY_A) { - if (dirContents[selection].isDirectory) { + if (dirContents[Selection].isDirectory) { } else if (storeInfo.size() != 0) { - if (ScriptHelper::checkIfValid(dirContents[selection].name, 1) == true) { - updateStore(selection); - currentStoreFile = dirContents[selection].name; + if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) { + updateStore(Selection); + currentStoreFile = dirContents[Selection].name; Msg::DisplayMsg(Lang::get("PREPARE_STORE")); - if (storeInfo[selection].storeSheet != "" || storeInfo[selection].storeSheet != "MISSING: storeInfo.sheet") { - if(access(storeInfo[selection].storeSheet.c_str(), F_OK) != -1 ) { - loadStoreSheet(selection); + if (storeInfo[Selection].storeSheet != "" || storeInfo[Selection].storeSheet != "MISSING: storeInfo.sheet") { + if(access(storeInfo[Selection].storeSheet.c_str(), F_OK) != -1 ) { + loadStoreSheet(Selection); } } appStoreJson = openStoreFile(); appStoreList = parseStoreObjects(currentStoreFile); loadStoreColors(appStoreJson); - selectedOptionAppStore = 0; + Selection = 0; displayInformations = handleIfDisplayText(); isScriptSelected = true; + Selection = 0; mode = 2; } } @@ -678,22 +671,22 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { } if (Config::viewMode == 0) { - if(selection < screenPos) { - screenPos = selection; - } else if (selection > screenPos + ENTRIES_PER_SCREEN - 1) { - screenPos = selection - ENTRIES_PER_SCREEN + 1; + if(Selection < screenPos) { + screenPos = Selection; + } else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) { + screenPos = Selection - ENTRIES_PER_SCREEN + 1; } } else if (Config::viewMode == 1) { - if(selection < screenPosList) { - screenPosList = selection; - } else if (selection > screenPosList + ENTRIES_PER_LIST - 1) { - screenPosList = selection - ENTRIES_PER_LIST + 1; + if(Selection < screenPosList) { + screenPosList = Selection; + } else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) { + screenPosList = Selection - ENTRIES_PER_LIST + 1; } } if (hDown & KEY_SELECT) { if (Msg::promptMsg(Lang::get("DELETE_STORE"))) { - deleteStore(selection); + deleteStore(Selection); } } @@ -713,7 +706,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { appStoreJson = openStoreFile(); appStoreList = parseStoreObjects(currentStoreFile); loadStoreColors(appStoreJson); - selectedOptionAppStore = 0; + Selection = 0; displayInformations = handleIfDisplayText(); isScriptSelected = true; mode = 2; @@ -735,7 +728,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { appStoreJson = openStoreFile(); appStoreList = parseStoreObjects(currentStoreFile); loadStoreColors(appStoreJson); - selectedOptionAppStore = 0; + Selection = 0; displayInformations = handleIfDisplayText(); isScriptSelected = true; mode = 2; @@ -752,11 +745,11 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { Config::AutobootFile = ""; } } else { - if (dirContents[selection].isDirectory) { + if (dirContents[Selection].isDirectory) { } else if (storeInfo.size() != 0) { - if (ScriptHelper::checkIfValid(dirContents[selection].name, 1) == true) { + if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) { if (Msg::promptMsg(Lang::get("AUTOBOOT_STORE"))) { - Config::AutobootFile = Config::StorePath + dirContents[selection].name; + Config::AutobootFile = Config::StorePath + dirContents[Selection].name; Config::autoboot = 1; } } @@ -770,12 +763,11 @@ void UniStore::StoreLogic(u32 hDown, u32 hHeld, touchPosition touch) { if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { refreshList(); + Selection = 0; + mode = 1; appStoreList.clear(); isScriptSelected = false; - selection2 = 0; - if (sheetHasLoaded == true) { - freeSheet(); - } + freeSheet(); } if (hDown & KEY_R) { @@ -788,10 +780,10 @@ void UniStore::StoreLogic(u32 hDown, u32 hHeld, touchPosition touch) { // Go one entry up. if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) { - if (selectedOptionAppStore > 0) { - selectedOptionAppStore--; + if (Selection > 0) { + Selection--; } else { - selectedOptionAppStore = (int)appStoreJson.at("storeContent").size()-1; + Selection = (int)appStoreJson.at("storeContent").size()-1; } if (fastMode == true) { keyRepeatDelay = 3; @@ -802,10 +794,10 @@ void UniStore::StoreLogic(u32 hDown, u32 hHeld, touchPosition touch) { // Go one entry down. if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) { - if (selectedOptionAppStore < (int)appStoreJson.at("storeContent").size()-1) { - selectedOptionAppStore++; + if (Selection < (int)appStoreJson.at("storeContent").size()-1) { + Selection++; } else { - selectedOptionAppStore = 0; + Selection = 0; } if (fastMode == true) { keyRepeatDelay = 3; @@ -819,35 +811,44 @@ void UniStore::StoreLogic(u32 hDown, u32 hHeld, touchPosition touch) { if (Config::viewMode == 0) { for(int i=0;i 40+(i*57) && touch.py < 40+(i*57)+45) { - selectedOptionAppStore = screenPos2 + i; - execute(); + Selection = screenPos + i; + std::string info = appStoreJson["storeContent"][Selection]["info"]["title"]; + if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) { + execute(); + } } } } else if (Config::viewMode == 1) { for(int i=0;i (i+1)*27 && touch.py < (i+2)*27) { - selectedOptionAppStore = screenPosList2 + i; - execute(); + Selection = screenPosList + i; + std::string info = appStoreJson["storeContent"][Selection]["info"]["title"]; + if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) { + execute(); + } } } } } // Execute that Entry. if (hDown & KEY_A) { - execute(); + std::string info = appStoreJson["storeContent"][Selection]["info"]["title"]; + if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) { + execute(); + } } if (Config::viewMode == 0) { - if(selectedOptionAppStore < screenPos2) { - screenPos2 = selectedOptionAppStore; - } else if (selectedOptionAppStore > screenPos2 + ENTRIES_PER_SCREEN - 1) { - screenPos2 = selectedOptionAppStore - ENTRIES_PER_SCREEN + 1; + if(Selection < screenPos) { + screenPos = Selection; + } else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) { + screenPos = Selection - ENTRIES_PER_SCREEN + 1; } } else if (Config::viewMode == 1) { - if(selectedOptionAppStore < screenPosList2) { - screenPosList2 = selectedOptionAppStore; - } else if (selectedOptionAppStore > screenPosList2 + ENTRIES_PER_LIST - 1) { - screenPosList2 = selectedOptionAppStore - ENTRIES_PER_LIST + 1; + if(Selection < screenPosList) { + screenPosList = Selection; + } else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) { + screenPosList = Selection - ENTRIES_PER_LIST + 1; } } } @@ -875,129 +876,18 @@ void UniStore::Logic(u32 hDown, u32 hHeld, touchPosition touch) { Config::viewMode = 0; } } -} -// Execute Entry. -void UniStore::execute() { - for(int i=0;i<(int)appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").size();i++) { - std::string type = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("type"); - if(type == "deleteFile") { - bool missing = false; - std::string file, message; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("file"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - if(!missing) ScriptHelper::removeFile(file, message); - - } else if(type == "downloadFile") { - bool missing = false; - std::string file, output, message; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("file"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("output"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - if(!missing) ScriptHelper::downloadFile(file, output, message); - - } else if(type == "downloadRelease") { - bool missing = false, includePrereleases = false; - std::string repo, file, output, message; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("repo")) repo = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("repo"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("file"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("output"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("includePrereleases") && appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("includePrereleases").is_boolean()) - includePrereleases = appStoreJson.at(selectedOptionAppStore).at("script").at(i).at("includePrereleases"); - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - if(!missing) ScriptHelper::downloadRelease(repo, file, output, includePrereleases, message); - - } else if(type == "extractFile") { - bool missing = false; - std::string file, input, output, message; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("file"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("input")) input = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("input"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("output"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - if(!missing) ScriptHelper::extractFile(file, input, output, message); - - } else if(type == "installCia") { - bool missing = false; - std::string file, message; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("file"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - if(!missing) ScriptHelper::installFile(file, message); - - } else if (type == "mkdir") { - bool missing = false; - std::string directory, message; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("directory"); - else missing = true; - if(!missing) makeDirs(directory.c_str()); - - } else if (type == "rmdir") { - bool missing = false; - std::string directory, message, promptmsg; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("directory"); - else missing = true; - promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory; - if(!missing) { - if (Msg::promptMsg(promptmsg)) { - removeDirRecursive(directory.c_str()); - } - } - - } else if (type == "mkfile") { - bool missing = false; - std::string file; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("file"); - else missing = true; - if(!missing) ScriptHelper::createFile(file.c_str()); - - } else if (type == "timeMsg") { - bool missing = false; - std::string message; - int seconds; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("seconds") && appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("seconds").is_number()) - seconds = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("seconds"); - else missing = true; - if(!missing) ScriptHelper::displayTimeMsg(message, seconds); - } else if (type == "saveConfig") { - Config::save(); - } else if (type == "notImplemented") { - notImplemented(); - } else if (type == "deleteTitle") { - std::string TitleID = ""; - std::string message = ""; - bool isNAND = false, missing = false; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("TitleID"); - else missing = true; - if (appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("NAND"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - else missing = true; - if(!missing) ScriptHelper::deleteTitle(TitleID, isNAND, message); - } else if (type == "bootTitle") { - std::string TitleID = ""; - std::string message = ""; - bool isNAND = false, missing = false; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("TitleID"); - else missing = true; - if (appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("NAND"); - else missing = true; - if(appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(selectedOptionAppStore).at("script").at(i).at("message"); - else missing = true; - if(!missing) ScriptHelper::bootTitle(TitleID, isNAND, message); + if (hDown & KEY_LEFT || hDown & KEY_RIGHT) { + if (mode == 6) { + mode = lastMode; + } else if (mode == 1) { + lastMode = 1; + mode = 6; + } else if (mode == 2) { + lastMode = 2; + mode = 6; } } - doneMsg(); } void UniStore::DrawSearch(void) const { @@ -1014,7 +904,7 @@ void UniStore::DrawSearch(void) const { for (int i = 0; i < 3; i++) { Gui::Draw_Rect(URLBtn[i].x, URLBtn[i].y, URLBtn[i].w, URLBtn[i].h, Config::UnselectedColor); - if (searchSelection == i) { + if (Selection == i) { Gui::drawAnimatedSelector(URLBtn[i].x, URLBtn[i].y, URLBtn[i].w, URLBtn[i].h, .060, TRANSPARENT, Config::SelectedColor); } } @@ -1026,37 +916,42 @@ void UniStore::DrawSearch(void) const { void UniStore::SearchLogic(u32 hDown, u32 hHeld, touchPosition touch) { if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { + Selection = 0; mode = 0; } if (hDown & KEY_RIGHT || hDown & KEY_R) { - if (searchSelection == 0) searchSelection = 1; + if (Selection == 0) Selection = 1; } if (hDown & KEY_LEFT || hDown & KEY_L) { - if (searchSelection == 1) searchSelection = 0; + if (Selection == 1) Selection = 0; } if (hDown & KEY_DOWN) { - if (searchSelection == 0) searchSelection = 2; + if (Selection == 0) Selection = 2; } if (hDown & KEY_UP) { - if (searchSelection == 2) searchSelection = 0; + if (Selection == 2) Selection = 0; } if (hDown & KEY_A) { - if (searchSelection == 0) { + if (Selection == 0) { + Selection = 0; mode = 4; - } else if (searchSelection == 1) { + } else if (Selection == 1) { + Selection = 0; mode = 5; - } else if (searchSelection == 2) { + } else if (Selection == 2) { ScriptHelper::downloadFile("https://tinydb.eiphax.tech/api/tinydb.unistore", Config::StorePath + "TinyDB.unistore", Lang::get("DOWNLOADING") + "TinyDB"); } } if (hDown & KEY_TOUCH && touching(touch, URLBtn[0])) { + Selection = 0; mode = 4; } else if (hDown & KEY_TOUCH && touching(touch, URLBtn[1])) { + Selection = 0; mode = 5; } else if (hDown & KEY_TOUCH && touching(touch, URLBtn[2])) { ScriptHelper::downloadFile("https://tinydb.eiphax.tech/api/tinydb.unistore", Config::StorePath + "TinyDB.unistore", Lang::get("DOWNLOADING") + "TinyDB"); @@ -1113,6 +1008,7 @@ void UniStore::GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch) { // Reset everything. OwnerAndRepo = ""; fileName = ""; + Selection = 0; mode = 3; } } @@ -1163,6 +1059,162 @@ void UniStore::FullURLLogic(u32 hDown, u32 hHeld, touchPosition touch) { // Reset everything. FullURL = ""; fileName = ""; + Selection = 0; mode = 3; } +} + + +void UniStore::DrawGlossary(void) const { + GFX::DrawTop(); + if (Config::UseBars == true) { + Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400); + } else { + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400); + } + + if (lastMode == 1) { + Gui::DrawString(15, 35, 0.7f, Config::TxtColor, std::to_string(Selection +1) + " / " + std::to_string(storeInfo.size()), 40); + Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("ENTRY"), 300); + } else if (lastMode == 2) { + Gui::DrawString(15, 35, 0.7f, Config::TxtColor, std::to_string(Selection+1) + " / " + std::to_string((int)appStoreJson.at("storeContent").size()), 40); + Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("ENTRY"), 300); + } + GFX::DrawBottom(); + + GFX::DrawSpriteBlend(sprites_view_idx, 20, 40); + Gui::DrawString(50, 42, 0.6f, Config::TxtColor, Lang::get("CHANGE_VIEW_MODE"), 260); + GFX::DrawArrow(20, 70); + Gui::DrawString(50, 72, 0.6f, Config::TxtColor, Lang::get("ENTRY_UP"), 260); + GFX::DrawArrow(42, 125, 180.0); + Gui::DrawString(50, 102, 0.6f, Config::TxtColor, Lang::get("ENTRY_DOWN"), 260); + GFX::DrawArrow(20, 130, 0, 1); + Gui::DrawString(50, 132, 0.6f, Config::TxtColor, Lang::get("GO_BACK"), 260); + if (lastMode == 1) { + GFX::DrawSpriteBlend(sprites_update_idx, 20, 160); + Gui::DrawString(50, 162, 0.6f, Config::TxtColor, Lang::get("UPDATE_STORE"), 260); + } +} + +// Execute Entry. +void UniStore::execute() { + for(int i=0;i<(int)appStoreJson.at("storeContent").at(Selection).at("script").size();i++) { + std::string type = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("type"); + if(type == "deleteFile") { + bool missing = false; + std::string file, message; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + if(!missing) ScriptHelper::removeFile(file, message); + + } else if(type == "downloadFile") { + bool missing = false; + std::string file, output, message; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + if(!missing) ScriptHelper::downloadFile(file, output, message); + + } else if(type == "downloadRelease") { + bool missing = false, includePrereleases = false; + std::string repo, file, output, message; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("repo")) repo = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("repo"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("includePrereleases") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("includePrereleases").is_boolean()) + includePrereleases = appStoreJson.at(Selection).at("script").at(i).at("includePrereleases"); + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + if(!missing) ScriptHelper::downloadRelease(repo, file, output, includePrereleases, message); + + } else if(type == "extractFile") { + bool missing = false; + std::string file, input, output, message; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("input")) input = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("input"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("output"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + if(!missing) ScriptHelper::extractFile(file, input, output, message); + + } else if(type == "installCia") { + bool missing = false; + std::string file, message; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + if(!missing) ScriptHelper::installFile(file, message); + + } else if (type == "mkdir") { + bool missing = false; + std::string directory, message; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("directory"); + else missing = true; + if(!missing) makeDirs(directory.c_str()); + + } else if (type == "rmdir") { + bool missing = false; + std::string directory, message, promptmsg; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("directory"); + else missing = true; + promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory; + if(!missing) { + if (Msg::promptMsg(promptmsg)) { + removeDirRecursive(directory.c_str()); + } + } + + } else if (type == "mkfile") { + bool missing = false; + std::string file; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("file"); + else missing = true; + if(!missing) ScriptHelper::createFile(file.c_str()); + + } else if (type == "timeMsg") { + bool missing = false; + std::string message; + int seconds; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("seconds") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("seconds").is_number()) + seconds = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("seconds"); + else missing = true; + if(!missing) ScriptHelper::displayTimeMsg(message, seconds); + } else if (type == "saveConfig") { + Config::save(); + } else if (type == "notImplemented") { + notImplemented(); + } else if (type == "deleteTitle") { + std::string TitleID = ""; + std::string message = ""; + bool isNAND = false, missing = false; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID"); + else missing = true; + if (appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + else missing = true; + if(!missing) ScriptHelper::deleteTitle(TitleID, isNAND, message); + } else if (type == "bootTitle") { + std::string TitleID = ""; + std::string message = ""; + bool isNAND = false, missing = false; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID"); + else missing = true; + if (appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("NAND"); + else missing = true; + if(appStoreJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = appStoreJson.at("storeContent").at(Selection).at("script").at(i).at("message"); + else missing = true; + if(!missing) ScriptHelper::bootTitle(TitleID, isNAND, message); + } + } + doneMsg(); } \ No newline at end of file