From 526cecadfd43b1e3cb613052139ac2ed73b27856 Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Wed, 4 Mar 2020 09:31:27 +0100 Subject: [PATCH] Add Autoboot UniStore. --- include/screens/unistore.hpp | 1 + include/utils/config.hpp | 4 +- romfs/lang/en/app.json | 5 +- source/init.cpp | 15 ++++- source/screens/unistore.cpp | 121 +++++++++++++++++++++++++++++++---- source/utils/config.cpp | 24 +++++++ 6 files changed, 152 insertions(+), 18 deletions(-) diff --git a/include/screens/unistore.hpp b/include/screens/unistore.hpp index 82c0f39..4e7f09d 100644 --- a/include/screens/unistore.hpp +++ b/include/screens/unistore.hpp @@ -38,6 +38,7 @@ class UniStore : public Screen public: void Draw(void) const override; void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; + UniStore(); private: void DrawSubMenu(void) const; void DrawStoreList(void) const; diff --git a/include/utils/config.hpp b/include/utils/config.hpp index ff217a5..c013b71 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -31,8 +31,8 @@ namespace Config { extern int LangPath, lang, Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor, viewMode, progressbarColor; - extern std::string ScriptPath, MusicPath, StorePath; - extern bool Logging, UseBars, GodMode; + extern std::string ScriptPath, MusicPath, StorePath, UniStoreFile; + extern bool Logging, UseBars, GodMode, autobootUnistore; void load(); void save(); diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 187fc48..d327caa 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -121,5 +121,8 @@ "GODMODE": "GodMode: ", "FUNCTION_NOT_ALLOWED": "This function is not allowed without GodMode!", "ENABLE_GODMODE": "Enable GodMode", - "ENABLE_GODMODE_PROMPT": "Would you like to enable GodMode?\n\nBe careful when you use GodMode!!" + "ENABLE_GODMODE_PROMPT": "Would you like to enable GodMode?\n\nBe careful when you use GodMode!!", + + "DISABLE_AUTOBOOT_STORE": "Would you like to disable autoboot?", + "AUTOBOOT_STORE": "Would you like to autoboot this Store?\n\nThis will autoboot this store on startup!" } diff --git a/source/init.cpp b/source/init.cpp index cd820e3..dc40b79 100644 --- a/source/init.cpp +++ b/source/init.cpp @@ -33,6 +33,7 @@ #include "mainMenu.hpp" #include "screenCommon.hpp" #include "sound.h" +#include "uniStore.hpp" #include <3ds.h> #include @@ -47,6 +48,7 @@ bool dspFound = false; touchPosition touch; sound *bgm = NULL; bool songIsFound = false; +bool UniStoreAutoboot = false; // Include all spritesheet's. C2D_SpriteSheet sprites; @@ -107,7 +109,18 @@ Result Init::Initialize() { Logging::createLogFile(); } - Gui::setScreen(std::make_unique()); + if (Config::autobootUnistore) { + UniStoreAutoboot = true; + } + + if (UniStoreAutoboot) { + if (access(Config::UniStoreFile.c_str(), F_OK) == 0) { + Gui::setScreen(std::make_unique()); + } + } else { + Gui::setScreen(std::make_unique()); + } + osSetSpeedupEnable(true); // Enable speed-up for New 3DS users if( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) { diff --git a/source/screens/unistore.cpp b/source/screens/unistore.cpp index c7572ec..c365737 100644 --- a/source/screens/unistore.cpp +++ b/source/screens/unistore.cpp @@ -29,6 +29,7 @@ #include "formatting.hpp" #include "json.hpp" #include "keyboard.hpp" +#include "mainMenu.hpp" #include "scriptHelper.hpp" #include "unistore.hpp" @@ -49,6 +50,9 @@ extern u32 TextColor; extern u32 progressBar; extern u32 selected; extern u32 unselected; +extern bool UniStoreAutoboot; +bool changeBackState = false; + C2D_SpriteSheet appStoreSheet; struct storeInfo2 { @@ -61,7 +65,7 @@ struct storeInfo2 { std::string sheetURL; }; -extern void notImplemented(void); +storeInfo2 SI; // Parse informations like URL, Title, Author, Description. storeInfo2 parseStoreInfo(std::string fileName) { @@ -92,6 +96,11 @@ 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"); @@ -111,11 +120,6 @@ std::vector parseStoreObjects(std::string storeName) { return objs; } -std::vector storeInfo; // Store selection. -std::vector appStoreList; // Actual store. ;P -std::vector descLines; -std::string storeDesc = ""; - bool sheetHasLoaded = false; // Sheet / Icon stuff. void loadStoreSheet(int pos) { @@ -124,6 +128,14 @@ void loadStoreSheet(int pos) { sheetHasLoaded = true; } } + +void loadStoreAutobootSheet(const std::string &sheet) { + if (sheetHasLoaded == false) { + appStoreSheet = C2D_SpriteSheetLoad(sheet.c_str()); + sheetHasLoaded = true; + } +} + void freeSheet() { if (sheetHasLoaded == true) { C2D_SpriteSheetFree(appStoreSheet); @@ -184,6 +196,53 @@ void loadStoreColors(nlohmann::json &json) { progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp; } +UniStore::UniStore() { + // Autobooting UniStore. ;) + if (UniStoreAutoboot) { + // If store isn't found, go to MainMenu. + if (access(Config::UniStoreFile.c_str(), F_OK) != 0) { + Gui::setScreen(std::make_unique()); + changeBackState = true; + } + + // Parse store. + SI = parseStoreInfo(Config::UniStoreFile); + // If WiFi enabled & File exist, update store. + if (checkWifiStatus()) { + if (Msg::promptMsg(Lang::get("WOULD_YOU_LIKE_UPDATE"))) { + if(SI.url != "" && SI.url != "MISSING: storeInfo.url" && SI.file != "" && SI.file != "MISSING: storeInfo.file") { + ScriptHelper::downloadFile(SI.url, SI.file, Lang::get("UPDATING")); + } + if(SI.sheetURL != "" && SI.sheetURL != "MISSING: storeInfo.sheetURL" && SI.storeSheet != "" && SI.storeSheet != "MISSING: storeInfo.sheet") { + ScriptHelper::downloadFile(SI.sheetURL, SI.storeSheet, Lang::get("UPDATING")); + } + } + } else { + notConnectedMsg(); + } + + if (ScriptHelper::checkIfValid(Config::UniStoreFile, 1) == true) { + currentStoreFile = Config::UniStoreFile; + Msg::DisplayMsg(Lang::get("PREPARE_STORE")); + if (SI.storeSheet != "" || SI.storeSheet != "MISSING: storeInfo.sheet") { + if(access(SI.storeSheet.c_str(), F_OK) != -1 ) { + loadStoreAutobootSheet(SI.storeSheet); + } + } + appStoreJson = openStoreFile(); + appStoreList = parseStoreObjects(currentStoreFile); + loadStoreColors(appStoreJson); + selectedOptionAppStore = 0; + displayInformations = handleIfDisplayText(); + isScriptSelected = true; + mode = 2; + changeBackState = true; + } + } +} + +extern void notImplemented(void); + void UniStore::DrawSubMenu(void) const { GFX::DrawTop(); if (Config::UseBars == true) { @@ -396,8 +455,12 @@ void UniStore::updateStore(int selectedStore) { void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { - Gui::screenBack(); - return; + if (changeBackState) { + Gui::setScreen(std::make_unique()); + } else { + Gui::screenBack(); + return; + } } if (hDown & KEY_UP) { @@ -650,18 +713,48 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) { } } } + + if (hDown & KEY_START) { + if (Config::autobootUnistore) { + if (Msg::promptMsg(Lang::get("DISABLE_AUTOBOOT_STORE"))) { + Config::autobootUnistore = false; + Config::UniStoreFile = ""; + } + } else { + if (dirContents[selection].isDirectory) { + } else if (storeInfo.size() != 0) { + if (ScriptHelper::checkIfValid(dirContents[selection].name, 1) == true) { + if (Msg::promptMsg(Lang::get("AUTOBOOT_STORE"))) { + Config::UniStoreFile = Config::StorePath + dirContents[selection].name; + Config::autobootUnistore = true; + } + } + } + } + } } void UniStore::StoreLogic(u32 hDown, u32 hHeld, touchPosition touch) { if (keyRepeatDelay) keyRepeatDelay--; if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) { - mode = 1; - appStoreList.clear(); - isScriptSelected = false; - selection2 = 0; - if (sheetHasLoaded == true) { - freeSheet(); + if (UniStoreAutoboot) { + UniStoreAutoboot = false; + mode = 0; + appStoreList.clear(); + isScriptSelected = false; + selection2 = 0; + if (sheetHasLoaded == true) { + freeSheet(); + } + } else { + mode = 1; + appStoreList.clear(); + isScriptSelected = false; + selection2 = 0; + if (sheetHasLoaded == true) { + freeSheet(); + } } } diff --git a/source/utils/config.cpp b/source/utils/config.cpp index 1829c48..e5995d2 100644 --- a/source/utils/config.cpp +++ b/source/utils/config.cpp @@ -48,6 +48,8 @@ bool Config::UseBars; std::string Config::StorePath; int Config::LangPath; bool Config::GodMode = false; +bool Config::autobootUnistore = false; +std::string Config::UniStoreFile = ""; nlohmann::json configJson; void Config::load() { @@ -145,6 +147,18 @@ void Config::load() { Config::StorePath = getString("STOREPATH"); } + if(!configJson.contains("UNISTORE_AUTOBOOT")) { + Config::autobootUnistore = false; + } else { + Config::autobootUnistore = getBool("UNISTORE_AUTOBOOT"); + } + + if(!configJson.contains("UNISTORE_FILE")) { + Config::UniStoreFile = ""; + } else { + Config::UniStoreFile = getString("UNISTORE_FILE"); + } + fclose(file); } else { Config::Color1 = BarColor; @@ -162,6 +176,8 @@ void Config::load() { Config::Logging = false; Config::UseBars = true; Config::StorePath = STORE_PATH; + Config::autobootUnistore = false; + Config::UniStoreFile = ""; } } @@ -181,6 +197,10 @@ void Config::save() { Config::setBool("LOGGING", Config::Logging); Config::setBool("BARS", Config::UseBars); Config::setString("STOREPATH", Config::StorePath); + + Config::setBool("UNISTORE_AUTOBOOT", Config::autobootUnistore); + Config::setString("UNISTORE_FILE", Config::UniStoreFile); + FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w"); if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file); fclose(file); @@ -204,6 +224,10 @@ void Config::initializeNewConfig() { Config::setBool("LOGGING", false); Config::setBool("BARS", true); Config::setString("STOREPATH", STORE_PATH); + + Config::setBool("UNISTORE_AUTOBOOT", false); + Config::setString("UNISTORE_FILE", ""); + if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file); fclose(file); }