WIP: Add Glossary and some cleanup.

This commit is contained in:
StackZ
2020-03-08 17:03:21 +01:00
parent 9998748baa
commit 1a20cc50f3
12 changed files with 1346 additions and 1039 deletions
+38
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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);
}
}
+2 -2
View File
@@ -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();
+208 -142
View File
@@ -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<json.size();i++) {
if(!json[i].contains("title")) json[i]["title"] = "TITLE";
@@ -95,37 +89,45 @@ ScriptBrowse::ScriptBrowse() {
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
// Get repo info
downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile);
// downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile);
FILE* file = fopen(metaFile, "r");
if(file) infoJson = nlohmann::json::parse(file, nullptr, false);
fclose(file);
fixInfo(infoJson);
findExistingFiles(infoJson);
maxScripts = std::to_string(infoJson.size());
maxScripts = infoJson.size();
}
void ScriptBrowse::Draw(void) const {
if (mode == 0) {
DrawBrowse();
} else {
DrawGlossary();
}
}
void ScriptBrowse::DrawBrowse(void) const {
GFX::DrawTop();
std::string revision = std::to_string(int64_t(infoJson[selection]["curRevision"]));
revision += " / ";
revision += std::to_string(int64_t(infoJson[selection]["revision"]));
std::string revision = std::to_string(int64_t(infoJson[Selection]["curRevision"]));
revision += " | ";
revision += std::to_string(int64_t(infoJson[Selection]["revision"]));
if (Config::UseBars == true) {
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), 239-Gui::GetStringHeight(0.6f, revision), 0.6f, Config::TxtColor, revision);
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, std::string(infoJson[selection]["title"]), 400);
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, std::string(infoJson[Selection]["title"]), 400);
} else {
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), 237-Gui::GetStringHeight(0.6f, revision), 0.6f, Config::TxtColor, revision);
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, std::string(infoJson[selection]["title"]), 400);
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, std::string(infoJson[Selection]["title"]), 400);
}
Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(infoJson[selection]["shortDesc"]), 400);
if (infoJson[selection]["curRevision"] == -1) {
Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(infoJson[Selection]["shortDesc"]), 400);
if (infoJson[Selection]["curRevision"] == -1) {
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("SCRIPT_NOT_FOUND"), 370);
} else if(infoJson[selection]["curRevision"] < infoJson[selection]["revision"]) {
} else if(infoJson[Selection]["curRevision"] < infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 370);
} else if(infoJson[selection]["curRevision"] == infoJson[selection]["revision"]) {
} else if(infoJson[Selection]["curRevision"] == infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 370);
} else if(infoJson[selection]["curRevision"] > 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<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
if(screenPos + i == selection) {
if(screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
}
if(infoJson[screenPos+i]["curRevision"] < infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(300, 45+(i*59), 20, 20, C2D_Color32(0xfb, 0x5b, 0x5b, 255));
} else {
Gui::Draw_Rect(300, 45+(i*59), 20, 20, C2D_Color32(0xa5, 0xdd, 0x81, 255));
if (infoJson[screenPos+i]["curRevision"] == -1) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, C2D_Color32(255, 128, 0, 255));
} else if(infoJson[screenPos+i]["curRevision"] < infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, C2D_Color32(0xfb, 0x5b, 0x5b, 255));
} else if(infoJson[screenPos+i]["curRevision"] == infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, C2D_Color32(0xa5, 0xdd, 0x81, 255));
} else if(infoJson[screenPos+i]["curRevision"] > 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<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, Config::UnselectedColor);
if(screenPosList + i == selection) {
if(screenPosList + i == Selection) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
}
if(infoJson[screenPosList+i]["curRevision"] < infoJson[screenPosList+i]["revision"]) {
// Script not found.
if (infoJson[screenPosList+i]["curRevision"] == -1) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, C2D_Color32(255, 128, 0, 255));
// Script outdaed.
} else if(infoJson[screenPosList+i]["curRevision"] < infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, C2D_Color32(0xfb, 0x5b, 0x5b, 255));
} else {
// Script up-to-date.
} else if(infoJson[screenPosList+i]["curRevision"] == infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, C2D_Color32(0xa5, 0xdd, 0x81, 255));
// Future script.
} else if(infoJson[screenPosList+i]["curRevision"] > 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<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
if(touch.py > 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<ENTRIES_PER_SCREEN && i<(int)infoJson.size();i++) {
if(touch.py > 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<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
if(touch.py > (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<ENTRIES_PER_LIST && i<(int)infoJson.size();i++) {
if(touch.py > (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;
}
}
File diff suppressed because it is too large Load Diff
+286 -234
View File
@@ -30,7 +30,6 @@
#include "json.hpp"
#include "keyboard.hpp"
#include "mainMenu.hpp"
#include "scriptHelper.hpp"
#include "unistore.hpp"
#include <algorithm>
@@ -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<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");
@@ -122,7 +102,7 @@ std::vector<std::string> 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<MainMenu>());
}
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<descLines.size();i++) {
@@ -307,7 +288,7 @@ void UniStore::DrawStoreList(void) const {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
line1 = storeInfo[screenPos + i].title;
line2 = storeInfo[screenPos + i].author;
if(screenPos + i == selection) {
if(screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, line1, 320);
@@ -317,7 +298,7 @@ void UniStore::DrawStoreList(void) const {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)storeInfo.size();i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, Config::UnselectedColor);
line1 = storeInfo[screenPosList + i].title;
if(screenPosList + i == selection) {
if(screenPosList + i == Selection) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, Config::TxtColor, line1, 320);
@@ -326,7 +307,7 @@ void UniStore::DrawStoreList(void) const {
}
void UniStore::DrawStore(void) const {
std::string entryAmount = std::to_string(selectedOptionAppStore+1) + " / " + std::to_string((int)appStoreJson.at("storeContent").size());
std::string entryAmount = std::to_string(Selection+1) + " / " + std::to_string((int)appStoreJson.at("storeContent").size());
std::string info;
GFX::DrawTop();
// Top Background.
@@ -335,11 +316,11 @@ void UniStore::DrawStore(void) const {
}
// Icon.
if (appStoreJson.at("storeContent").at(selectedOptionAppStore).at("info").contains("iconIndex") && sheetHasLoaded == true) {
if (appStoreJson.at("storeContent").at(selectedOptionAppStore).at("info").contains("posX") && appStoreJson.at("storeContent").at(selectedOptionAppStore).at("info").contains("posY")) {
drawNormal(appStoreJson["storeContent"][selectedOptionAppStore]["info"]["iconIndex"], appStoreJson["storeContent"][selectedOptionAppStore]["info"]["posX"], appStoreJson["storeContent"][selectedOptionAppStore]["info"]["posY"]);
if (appStoreJson.at("storeContent").at(Selection).at("info").contains("iconIndex") && sheetHasLoaded == true) {
if (appStoreJson.at("storeContent").at(Selection).at("info").contains("posX") && appStoreJson.at("storeContent").at(Selection).at("info").contains("posY")) {
drawNormal(appStoreJson["storeContent"][Selection]["info"]["iconIndex"], appStoreJson["storeContent"][Selection]["info"]["posX"], appStoreJson["storeContent"][Selection]["info"]["posY"]);
} else {
drawNormal(appStoreJson["storeContent"][selectedOptionAppStore]["info"]["iconIndex"], 175, 155);
drawNormal(appStoreJson["storeContent"][Selection]["info"]["iconIndex"], 175, 155);
}
}
@@ -352,18 +333,18 @@ void UniStore::DrawStore(void) const {
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 237-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, TextColor, entryAmount);
}
Gui::DrawStringCentered(0, 32, 0.6f, TextColor, Lang::get("TITLE") + std::string(appStoreJson["storeContent"][selectedOptionAppStore]["info"]["title"]), 400);
Gui::DrawStringCentered(0, 57, 0.6f, TextColor, Lang::get("AUTHOR") + std::string(appStoreJson["storeContent"][selectedOptionAppStore]["info"]["author"]), 400);
Gui::DrawStringCentered(0, 82, 0.6f, TextColor, Lang::get("DESC") + std::string(appStoreJson["storeContent"][selectedOptionAppStore]["info"]["description"]), 400);
Gui::DrawStringCentered(0, 32, 0.6f, TextColor, Lang::get("TITLE") + std::string(appStoreJson["storeContent"][Selection]["info"]["title"]), 400);
Gui::DrawStringCentered(0, 57, 0.6f, TextColor, Lang::get("AUTHOR") + std::string(appStoreJson["storeContent"][Selection]["info"]["author"]), 400);
Gui::DrawStringCentered(0, 82, 0.6f, TextColor, Lang::get("DESC") + std::string(appStoreJson["storeContent"][Selection]["info"]["description"]), 400);
if (appStoreJson["storeContent"][selectedOptionAppStore]["info"]["version"] != "") {
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + std::string(appStoreJson["storeContent"][selectedOptionAppStore]["info"]["version"]), 400);
if (appStoreJson["storeContent"][Selection]["info"]["version"] != "") {
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + std::string(appStoreJson["storeContent"][Selection]["info"]["version"]), 400);
} else {
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + Lang::get("UNKNOWN"), 400);
}
if (appStoreJson["storeContent"][selectedOptionAppStore]["info"]["fileSize"] != 0) {
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + formatBytes(int64_t(appStoreJson["storeContent"][selectedOptionAppStore]["info"]["fileSize"])), 400);
if (appStoreJson["storeContent"][Selection]["info"]["fileSize"] != 0) {
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + formatBytes(int64_t(appStoreJson["storeContent"][Selection]["info"]["fileSize"])), 400);
} else {
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + Lang::get("UNKNOWN"), 400);
}
@@ -382,8 +363,8 @@ void UniStore::DrawStore(void) const {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)appStoreJson.at("storeContent").size();i++) {
info = appStoreJson["storeContent"][screenPos2 + i]["info"]["title"];
if(screenPos2 + i == selectedOptionAppStore) {
info = appStoreJson["storeContent"][screenPos + i]["info"]["title"];
if(screenPos + i == Selection) {
if (appStoreJson.at("storeInfo").contains("buttonLarge") && sheetHasLoaded == true) {
drawNormal(appStoreJson["storeInfo"]["buttonLarge"], 0, 40+(i*57));
} else {
@@ -400,8 +381,8 @@ void UniStore::DrawStore(void) const {
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)appStoreJson.at("storeContent").size();i++) {
info = appStoreJson["storeContent"][screenPosList2 + i]["info"]["title"];
if(screenPosList2 + i == selectedOptionAppStore) {
info = appStoreJson["storeContent"][screenPosList + i]["info"]["title"];
if(screenPosList + i == Selection) {
if (appStoreJson.at("storeInfo").contains("buttonSmall") && sheetHasLoaded == true) {
drawNormal(appStoreJson["storeInfo"]["buttonSmall"], 0, (i+1)*27);
} else {
@@ -432,6 +413,8 @@ void UniStore::Draw(void) const {
DrawFullURLScreen();
} else if (mode == 5) {
DrawGitHubScreen();
} else if (mode == 6) {
DrawGlossary();
}
}
@@ -475,9 +458,11 @@ void UniStore::refreshList() {
descript();
loadStoreDesc();
}
Selection = 0;
mode = 1;
} else {
Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
Selection = 0;
mode = 0;
}
}
@@ -492,14 +477,14 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_UP) {
if(subSelection > 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<ENTRIES_PER_SCREEN && i<(int)appStoreJson.at("storeContent").size();i++) {
if(touch.py > 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<ENTRIES_PER_LIST && i<(int)appStoreJson.at("storeContent").size();i++) {
if(touch.py > (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();
}