Add Autoboot UniStore.

This commit is contained in:
StackZ 2020-03-04 09:31:27 +01:00
commit 526cecadfd
6 changed files with 152 additions and 18 deletions

View file

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

View file

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

View file

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

View file

@ -33,6 +33,7 @@
#include "mainMenu.hpp"
#include "screenCommon.hpp"
#include "sound.h"
#include "uniStore.hpp"
#include <3ds.h>
#include <dirent.h>
@ -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<MainMenu>());
if (Config::autobootUnistore) {
UniStoreAutoboot = true;
}
if (UniStoreAutoboot) {
if (access(Config::UniStoreFile.c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<UniStore>());
}
} else {
Gui::setScreen(std::make_unique<MainMenu>());
}
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
if( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) {

View file

@ -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<storeInfo2> storeInfo; // Store selection.
std::vector<std::string> appStoreList; // Actual store. ;P
std::vector<std::string> descLines;
std::string storeDesc = "";
// Parse the Objects.
std::vector<std::string> parseStoreObjects(std::string storeName) {
FILE* file = fopen(storeName.c_str(), "rt");
@ -111,11 +120,6 @@ std::vector<std::string> parseStoreObjects(std::string storeName) {
return objs;
}
std::vector<storeInfo2> storeInfo; // Store selection.
std::vector<std::string> appStoreList; // Actual store. ;P
std::vector<std::string> 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<MainMenu>());
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<MainMenu>());
} 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();
}
}
}

View file

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