UniStore v2! (#36)

* Do not build here.

* WIP: UniStoreV2!

This implementation is ugly and a big cleanup is needed.

* [UniStoreV2]: Add `Lang::get(...)`.

* Add back UniStore autobooting.

* UniStoreV2: Add List Layout.

* Some more UniStore work.

Also constify vector's.

* Some more spritesheet checks.

* oops.. forgot to do `Config::fading`.

* Display UniStore version on the Store list bar.

* version now needs to be `0` or `1` or not included.

versions with 2, 3, 4 and up shows an error now.

* You can now also scroll to the next page with D-Pad Left/D-Pad Right!

* Last fix before merge?
This commit is contained in:
StackZ
2020-06-19 04:54:05 +02:00
committed by GitHub
parent d86f612d09
commit 2641e4922b
23 changed files with 1598 additions and 798 deletions
+1 -1
View File
@@ -861,7 +861,7 @@ void displayProgressBar() {
formatBytes(downloadNow).c_str(),
formatBytes(downloadTotal).c_str(),
((float)downloadNow/(float)downloadTotal) * 100.0f,
Lang::get("DOWNLOAD_SPEED").c_str(), (downloadSpeed), Lang::get("BYTES_PER_SECOND").c_str());
Lang::get("DOWNLOAD_SPEED").c_str(), (downloadSpeed / 1000), Lang::get("KB_PER_SECOND").c_str());
// Extracting.
} else if (progressBarType == 1) {
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
+4 -4
View File
@@ -77,13 +77,11 @@ void GFX::DrawBottom(void) {
extern C2D_SpriteSheet sprites;
void GFX::DrawSprite(int img, int x, int y, float ScaleX, float ScaleY)
{
void GFX::DrawSprite(int img, int x, int y, float ScaleX, float ScaleY) {
Gui::DrawSprite(sprites, img, x, y, ScaleX, ScaleY);
}
void GFX::DrawSpriteBlend(int img, int x, int y, float ScaleX, float ScaleY)
{
void GFX::DrawSpriteBlend(int img, int x, int y, float ScaleX, float ScaleY) {
C2D_ImageTint tint;
if (isScriptSelected) {
C2D_SetImageTint(&tint, C2D_TopLeft, TextColor, 0.5);
@@ -96,6 +94,7 @@ void GFX::DrawSpriteBlend(int img, int x, int y, float ScaleX, float ScaleY)
C2D_SetImageTint(&tint, C2D_BotLeft, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, Config::TxtColor, 0.5);
}
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, img), x, y, 0.5f, &tint, ScaleX, ScaleY);
}
@@ -119,6 +118,7 @@ void GFX::DrawArrow(int x, int y, float rotation, int arrowSprite) {
} else {
C2D_SpriteFromSheet(&sprite, sprites, sprites_side_arrow_idx);
}
C2D_SpriteRotateDegrees(&sprite, rotation);
C2D_SpriteSetPos(&sprite, x, y);
C2D_SpriteSetDepth(&sprite, 0.5);
+1 -5
View File
@@ -119,7 +119,7 @@ Result Init::Initialize() {
if (Config::autoboot == 1) {
if (access(Config::AutobootFile.c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<UniStore>(), false, true);
Gui::setScreen(std::make_unique<UniStore>(true, Config::AutobootFile), false, true);
} else {
AutobootWhat = 0;
Config::autoboot = 0;
@@ -179,8 +179,6 @@ Result Init::MainLoop() {
return 0;
}
extern void freeSheet();
Result Init::Exit() {
if (songIsFound == true) {
stopMusic();
@@ -190,8 +188,6 @@ Result Init::Exit() {
ndspExit();
}
// Free UniStore spritesheet, just in case.
freeSheet();
// Only save config, if *any* changes are made. (To reduce SD Writes.)
if (changesMade) {
Config::save();
-37
View File
@@ -1,37 +0,0 @@
/*
* 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"
#include "exiting.hpp"
void Exiting::Draw(void) const {
GFX::DrawTop();
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, 255)); // Fade in/out effect
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, 255)); // Fade in/out effect
}
void Exiting::Logic(u32 hDown, u32 hHeld, touchPosition touch) { }
+4 -5
View File
@@ -25,7 +25,6 @@
*/
#include "config.hpp"
#include "exiting.hpp"
#include "ftpScreen.hpp"
#include "mainMenu.hpp"
#include "scriptHelper.hpp"
@@ -68,9 +67,9 @@ void MainMenu::Draw(void) const {
void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_START) || (hDown & KEY_TOUCH && touching(touch, mainButtons[4]))) {
exiting = true;
Gui::setScreen(std::make_unique<Exiting>(), Config::fading, true);
fadeout = true;
fadecolor = 0;
exiting = true;
}
// Navigation.
@@ -87,7 +86,7 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_A) {
switch(Selection) {
case 0:
Gui::setScreen(std::make_unique<UniStore>(), Config::fading, true);
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), Config::fading, true);
break;
case 1:
Gui::setScreen(std::make_unique<ScriptList>(), Config::fading, true);
@@ -103,7 +102,7 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
Gui::setScreen(std::make_unique<UniStore>(), Config::fading, true);
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), Config::fading, true);
} else if (touching(touch, mainButtons[1])) {
Gui::setScreen(std::make_unique<ScriptList>(), Config::fading, true);
} else if (touching(touch, mainButtons[2])) {
File diff suppressed because it is too large Load Diff
+540
View File
@@ -0,0 +1,540 @@
/*
* 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 "download.hpp"
#include "formatting.hpp"
#include "json.hpp"
#include "scriptHelper.hpp"
#include "unistore_v1.hpp"
#include <unistd.h>
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern u32 getColor(std::string colorString);
extern bool isScriptSelected;
extern u32 barColor;
extern u32 bgTopColor;
extern u32 bgBottomColor;
extern u32 TextColor;
extern u32 progressBar;
extern u32 selected;
extern u32 unselected;
extern bool didAutoboot;
UniStoreV1::UniStoreV1(nlohmann::json &JSON, const std::string sheetPath, bool displayInf) {
this->storeJson = JSON;
this->displayInformations = displayInf;
if (access(sheetPath.c_str(), F_OK) != 0) {
this->sheetHasLoaded = false;
} else {
Gui::loadSheet(sheetPath.c_str(), this->sheet);
this->sheetHasLoaded = true;
}
u32 colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
barColor = colorTemp == 0 ? Config::Color1 : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
bgTopColor = colorTemp == 0 ? Config::Color2 : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
bgBottomColor = colorTemp == 0 ? Config::Color3 : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
TextColor = colorTemp == 0 ? Config::TxtColor : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
selected = colorTemp == 0 ? Config::SelectedColor : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
unselected = colorTemp == 0 ? Config::UnselectedColor : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp;
}
void UniStoreV1::drawBlend(int key, int x, int y) const {
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_DrawImageAt(C2D_SpriteSheetGetImage(this->sheet, key), x, y, 0.5f, &tint);
}
void UniStoreV1::parseObjects() {
this->objects.clear();
for(auto it = this->storeJson.begin();it != this->storeJson.end(); it++) {
if (it.key() != "storeInfo") {
this->objects.push_back(it.key());
}
}
}
UniStoreV1::~UniStoreV1() {
// Only unload if sheet has loaded.
if (this->sheetHasLoaded) {
Gui::unloadSheet(this->sheet);
}
}
void UniStoreV1::Draw(void) const {
std::string entryAmount = std::to_string(this->Selection+1) + " | " + std::to_string((int)this->storeJson.at("storeContent").size());
std::string info;
GFX::DrawTop();
// Top Background.
if (this->storeJson.at("storeInfo").contains("iconIndexTop") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["iconIndexTop"], 0, 0);
}
// Icon.
if (this->storeJson.at("storeContent").at(Selection).at("info").contains("iconIndex") && sheetHasLoaded == true) {
if (this->storeJson.at("storeContent").at(Selection).at("info").contains("posX") && this->storeJson.at("storeContent").at(Selection).at("info").contains("posY")) {
Gui::DrawSprite(this->sheet, this->storeJson["storeContent"][Selection]["info"]["iconIndex"], this->storeJson["storeContent"][Selection]["info"]["posX"], this->storeJson["storeContent"][Selection]["info"]["posY"]);
} else {
Gui::DrawSprite(this->sheet, this->storeJson["storeContent"][Selection]["info"]["iconIndex"], 175, 155);
}
}
if (displayInformations != false) {
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, TextColor, std::string(this->storeJson["storeInfo"]["title"]), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 239-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, TextColor, entryAmount);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, std::string(this->storeJson["storeInfo"]["title"]), 400);
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(this->storeJson["storeContent"][Selection]["info"]["title"]), 400);
Gui::DrawStringCentered(0, 57, 0.6f, TextColor, Lang::get("AUTHOR") + std::string(this->storeJson["storeContent"][Selection]["info"]["author"]), 400);
Gui::DrawStringCentered(0, 82, 0.6f, TextColor, Lang::get("DESC") + std::string(this->storeJson["storeContent"][Selection]["info"]["description"]), 400);
if (this->storeJson["storeContent"][Selection]["info"]["version"] != "") {
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + std::string(this->storeJson["storeContent"][Selection]["info"]["version"]), 400);
} else {
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + Lang::get("UNKNOWN"), 400);
}
if (this->storeJson["storeContent"][Selection]["info"]["fileSize"] != 0) {
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + formatBytes(int64_t(this->storeJson["storeContent"][Selection]["info"]["fileSize"])), 400);
} else {
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + Lang::get("UNKNOWN"), 400);
}
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
// Bottom Background.
if (this->storeJson.at("storeInfo").contains("iconIndexBottom") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["iconIndexBottom"], 0, 0);
}
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
if (Config::viewMode == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)this->storeJson.at("storeContent").size(); i++) {
info = this->storeJson["storeContent"][screenPos + i]["info"]["title"];
if (screenPos + i == Selection) {
if (this->storeJson.at("storeInfo").contains("buttonLarge") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["buttonLarge"], 0, 40+(i*57));
} else {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, selected);
}
}
} else {
if (this->storeJson.at("storeInfo").contains("buttonLarge") && sheetHasLoaded == true) {
this->drawBlend(this->storeJson["storeInfo"]["buttonLarge"], 0, 40+(i*57));
} else {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, unselected);
}
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, TextColor, info, 320);
}
} else if (Config::viewMode == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)this->storeJson.at("storeContent").size(); i++) {
info = this->storeJson["storeContent"][screenPosList + i]["info"]["title"];
if(screenPosList + i == Selection) {
if (this->storeJson.at("storeInfo").contains("buttonSmall") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["buttonSmall"], 0, (i+1)*27);
} else {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, selected);
}
}
} else {
if (this->storeJson.at("storeInfo").contains("buttonSmall") && sheetHasLoaded == true) {
this->drawBlend(this->storeJson["storeInfo"]["buttonSmall"], 0, (i+1)*27);
} else {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
}
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, TextColor, info, 320);
}
}
// DropDown Menu.
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 44, barColor);
Gui::drawAnimatedSelector(dropPos[0].x, dropPos[0].y, dropPos[0].w, dropPos[0].h, .090, TRANSPARENT, Config::SelectedColor);
// Draw Dropdown Icons.
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[0].x, dropPos[0].y);
// Dropdown Text.
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, Config::TxtColor, Lang::get("VIEW_DDM"), 100);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
//DropDown Logic.
if (dropDownMenu) {
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropDownMenu = false;
}
if (hDown & KEY_DOWN) {
if (dropSelection < 1) dropSelection++;
}
if (hDown & KEY_UP) {
if (dropSelection > 0) dropSelection--;
}
if (hDown & KEY_A) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
} else {
Config::viewMode = 0;
}
dropDownMenu = false;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, dropPos[0])) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
} else {
Config::viewMode = 0;
}
dropDownMenu = false;
}
}
} else {
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropSelection = 0;
dropDownMenu = true;
}
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
if (!didAutoboot) didAutoboot = true;
Gui::screenBack(Config::fading);
return;
}
// Go one entry up.
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
if (Selection > 0) {
Selection--;
} else {
Selection = (int)this->storeJson.at("storeContent").size()-1;
}
keyRepeatDelay = Config::keyDelay;
}
// Go one entry down.
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
if (Selection < (int)this->storeJson.at("storeContent").size()-1) {
Selection++;
} else {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (Selection < (int)this->storeJson.at("storeContent").size()-1-3) {
Selection += 3;
} else {
Selection = (int)this->storeJson.at("storeContent").size()-1;
}
} else {
if (Selection < (int)this->storeJson.at("storeContent").size()-1-6) {
Selection += 7;
} else {
Selection = (int)this->storeJson.at("storeContent").size()-1;
}
}
keyRepeatDelay = Config::keyDelay;
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (Selection > 2) {
Selection -= 3;
} else {
Selection = 0;
}
} else {
if (Selection > 6) {
Selection -= 7;
} else {
Selection = 0;
}
}
keyRepeatDelay = Config::keyDelay;
}
// Execute touched Entry.
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)this->storeJson.at("storeContent").size();i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
Selection = screenPos + i;
std::string info = this->storeJson["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)this->storeJson.at("storeContent").size();i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
Selection = screenPosList + i;
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
execute();
}
}
}
}
}
// Execute that Entry.
if (hDown & KEY_A) {
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
execute();
}
}
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;
}
}
}
}
// Execute Entry.
Result UniStoreV1::execute() {
Result ret = NONE; // No Error has been occured now.
for(int i=0;i<(int)this->storeJson.at("storeContent").at(Selection).at("script").size();i++) {
if (ret == NONE) {
std::string type = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("type");
if(type == "deleteFile") {
bool missing = false;
std::string file, message;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ret = ScriptHelper::removeFile(file, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadFile") {
bool missing = false;
std::string file, output, message;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ret = ScriptHelper::downloadFile(file, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadRelease") {
bool missing = false, includePrereleases = false, showVersions = false;
std::string repo, file, output, message;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("repo")) repo = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("repo");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("includePrereleases") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("includePrereleases").is_boolean())
includePrereleases = this->storeJson.at(Selection).at("script").at(i).at("includePrereleases");
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("showVersions") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("showVersions").is_boolean())
showVersions = this->storeJson.at(Selection).at("script").at(i).at("showVersions");
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
else ret = SYNTAX_ERROR;
} else if(type == "extractFile") {
bool missing = false;
std::string file, input, output, message;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("input")) input = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("input");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::extractFile(file, input, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "installCia") {
bool missing = false, updateSelf = false;
std::string file, message;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("updateSelf") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("updateSelf").is_boolean()) {
updateSelf = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("updateSelf");
}
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if(!missing) ScriptHelper::installFile(file, updateSelf, message);
else ret = SYNTAX_ERROR;
} else if (type == "mkdir") {
bool missing = false;
std::string directory, message;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
if(!missing) makeDirs(directory.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "rmdir") {
bool missing = false;
std::string directory, message, promptmsg;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
if(!missing) {
if(access(directory.c_str(), F_OK) != 0 ) {
ret = DELETE_ERROR;
} else {
if (Msg::promptMsg(promptmsg)) {
removeDirRecursive(directory.c_str());
}
}
}
else ret = SYNTAX_ERROR;
} else if (type == "mkfile") {
bool missing = false;
std::string file;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if(!missing) ScriptHelper::createFile(file.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "timeMsg") {
bool missing = false;
std::string message;
int seconds;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("seconds") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("seconds").is_number())
seconds = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("seconds");
else missing = true;
if(!missing) ScriptHelper::displayTimeMsg(message, seconds);
else ret = SYNTAX_ERROR;
} else if (type == "saveConfig") {
Config::save();
} else if (type == "notImplemented") {
notImplemented();
} else if (type == "bootTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("NAND");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if(!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
else ret = SYNTAX_ERROR;
} else if (type == "promptMessage") {
std::string Message = "";
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
ret = ScriptHelper::prompt(Message);
} else if (type == "copy") {
std::string Message = "", source = "", destination = "";
bool missing = false;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("source")) source = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("source");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("destination")) destination = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("destination");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ret = ScriptHelper::copyFile(source, destination, Message);
else ret = SYNTAX_ERROR;
} else if (type == "move") {
std::string Message = "", oldFile = "", newFile = "";
bool missing = false;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("old")) oldFile = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("old");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("new")) newFile = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("new");
else missing = true;
if(this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ret = ScriptHelper::renameFile(oldFile, newFile, Message);
else ret = SYNTAX_ERROR;
}
}
}
if (ret == NONE) doneMsg();
else if (ret == FAILED_DOWNLOAD) Msg::DisplayWarnMsg(Lang::get("DOWNLOAD_ERROR"));
else if (ret == SCRIPT_CANCELED) Msg::DisplayWarnMsg(Lang::get("SCRIPT_CANCELED"));
else if (ret == SYNTAX_ERROR) Msg::DisplayWarnMsg(Lang::get("SYNTAX_ERROR"));
else if (ret == COPY_ERROR) Msg::DisplayWarnMsg(Lang::get("COPY_ERROR"));
else if (ret == MOVE_ERROR) Msg::DisplayWarnMsg(Lang::get("MOVE_ERROR"));
else if (ret == DELETE_ERROR) Msg::DisplayWarnMsg(Lang::get("DELETE_ERROR"));
return ret;
}
+721
View File
@@ -0,0 +1,721 @@
/*
* 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 "download.hpp"
#include "json.hpp"
#include "scriptHelper.hpp"
#include "unistore_v2.hpp"
#include <unistd.h>
extern u32 getColor(std::string colorString);
extern bool touching(touchPosition touch, Structs::ButtonPos button);
#define STORE_ENTRIES 9
#define STORE_ENTRIES_LIST 3
#define DOWNLOAD_ENTRIES 5
extern bool didAutoboot;
UniStoreV2::UniStoreV2(nlohmann::json &JSON, const std::string sheetPath) {
this->storeJson = JSON;
if (access(sheetPath.c_str(), F_OK) != 0) {
this->iconAmount = 0;
this->sheetLoaded = false;
} else {
if (C2D_SpriteSheetLoad(sheetPath.c_str()) != nullptr) {
this->sheet = C2D_SpriteSheetLoad(sheetPath.c_str());
this->iconAmount = (int)C2D_SpriteSheetCount(this->sheet);
this->sheetLoaded = true;
} else {
this->iconAmount = 0;
this->sheetLoaded = false;
}
}
// Get colors.
this->barColorLight = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barLight"));
this->barColorDark = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barDark"));
this->bgColorLight = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgLight"));
this->bgColorDark = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgDark"));
this->textColorLight = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textLight"));
this->textColorDark = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textDark"));
this->boxColorLight = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "boxLight"));
this->boxColorDark = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "boxDark"));
this->outlineColorLight = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "outlineLight"));
this->outlineColorDark = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "outlineDark"));
}
UniStoreV2::~UniStoreV2() {
// Only unload if sheet has loaded.
if (this->sheetLoaded) {
C2D_SpriteSheetFree(this->sheet);
}
}
u32 UniStoreV2::returnTextColor() const {
return this->darkMode ? this->textColorDark : this->textColorLight;
}
// Base draws.
void UniStoreV2::DrawBaseTop(void) const {
Gui::ScreenDraw(Top);
Gui::Draw_Rect(0, 0, 400, 25, this->darkMode ? this->barColorDark : this->barColorLight);
Gui::Draw_Rect(0, 25, 400, 190, this->darkMode ? this->bgColorDark : this->bgColorLight);
Gui::Draw_Rect(0, 215, 400, 25, this->darkMode ? this->barColorDark : this->barColorLight);
if (Config::UseBars == true) {
GFX::DrawSprite(sprites_top_screen_top_idx, 0, 0);
GFX::DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
}
void UniStoreV2::DrawBaseBottom(void) const {
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 25, this->darkMode ? this->barColorDark : this->barColorLight);
Gui::Draw_Rect(0, 25, 320, 190, this->darkMode ? this->bgColorDark : this->bgColorLight);
Gui::Draw_Rect(0, 215, 320, 25, this->darkMode ? this->barColorDark : this->barColorLight);
if (Config::UseBars == true) {
GFX::DrawSprite(sprites_top_screen_top_idx, 0, 0);
GFX::DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
}
// Draw a box.
void UniStoreV2::drawBox(float xPos, float yPos, float width, float height, bool selected) const {
static constexpr int w = 1;
const u32 tempColor = this->darkMode ? this->outlineColorDark : this->outlineColorLight;
const u32 outlineColor = selected ? tempColor : C2D_Color32(0, 0, 0, 255);
C2D_DrawRectSolid(xPos, yPos, 0.5, width, height, this->darkMode ? this->boxColorDark : this->boxColorLight);
// Grid part.
C2D_DrawRectSolid(xPos, yPos, 0.5, width, w, outlineColor); // top
C2D_DrawRectSolid(xPos, yPos + w, 0.5, w, height - 2 * w, outlineColor); // left
C2D_DrawRectSolid(xPos + width - w, yPos + w, 0.5, w, height - 2 * w, outlineColor); // right
C2D_DrawRectSolid(xPos, yPos + height - w, 0.5, width, w, outlineColor); // bottom
}
void UniStoreV2::DrawGrid(void) const {
for (int i = 0, i2 = 0 + (this->storePage * STORE_ENTRIES); i2 < STORE_ENTRIES + (this->storePage * STORE_ENTRIES) && i2 < (int)this->storeJson.at("storeContent").size(); i2++, i++) {
if (i == this->selectedBox) {
this->drawBox(this->StoreBoxesGrid[i].x, this->StoreBoxesGrid[i].y, 100, 50, true);
} else {
this->drawBox(this->StoreBoxesGrid[i].x, this->StoreBoxesGrid[i].y, 100, 50, false);
}
if (this->sheetLoaded) {
if (this->storeJson.at("storeContent").at(i + (this->storePage * STORE_ENTRIES)).at("info").contains("icon_index")) {
if ((int)this->storeJson.at("storeContent").at(i + (this->storePage * STORE_ENTRIES)).at("info").at("icon_index") < this->iconAmount) {
Gui::DrawSprite(this->sheet, this->storeJson.at("storeContent").at(i + (this->storePage * STORE_ENTRIES)).at("info").at("icon_index"), this->StoreBoxesGrid[i].x+26, this->StoreBoxesGrid[i].y+1);
} else {
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesGrid[i].x+26, this->StoreBoxesGrid[i].y+1);
}
} else {
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesGrid[i].x+26, this->StoreBoxesGrid[i].y+1);
}
} else {
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesGrid[i].x+26, this->StoreBoxesGrid[i].y+1);
}
}
}
void UniStoreV2::DrawList(void) const {
for (int i = 0, i2 = 0 + (this->storePageList * STORE_ENTRIES_LIST); i2 < STORE_ENTRIES_LIST + (this->storePageList * STORE_ENTRIES_LIST) && i2 < (int)this->storeJson.at("storeContent").size(); i2++, i++) {
if (i == this->selectedBoxList) {
this->drawBox(this->StoreBoxesList[i].x, this->StoreBoxesList[i].y, 360, 50, true);
} else {
this->drawBox(this->StoreBoxesList[i].x, this->StoreBoxesList[i].y, 360, 50, false);
}
if (this->sheetLoaded) {
if (this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").contains("icon_index")) {
if ((int)this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("icon_index") < this->iconAmount) {
Gui::DrawSprite(this->sheet, this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("icon_index"), this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1);
} else {
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1);
}
} else {
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1);
}
} else {
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1);
}
// Display Author & App name.
if (this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").contains("title")) {
Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+12, 0.45f, this->returnTextColor(), (std::string)this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("title"), 300);
} else {
Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+12, 0.45f, this->returnTextColor(), "?", 300);
}
if (this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").contains("author")) {
Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+28, 0.45f, this->returnTextColor(), (std::string)this->storeJson.at("storeContent").at(i + (this->storePageList * STORE_ENTRIES_LIST)).at("info").at("author"), 300);
} else {
Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+28, 0.45f, this->returnTextColor(), "?", 300);
}
}
}
// Parse the objects from a script.
void UniStoreV2::parseObjects(int selection) {
this->objects.clear();
for(auto it = this->storeJson.at("storeContent").at(selection).begin(); it != this->storeJson.at("storeContent").at(selection).end(); it++) {
if (it.key() != "info") {
this->objects.push_back(it.key());
}
}
}
void UniStoreV2::DropDownMenu(void) const {
if (this->mode != 2) {
// DropDown Menu.
if (this->isDropDown) {
// Draw Operation Box.
for (int i = 0; i < 2; i++) {
Gui::Draw_Rect(dropPos[i].x, dropPos[i].y, dropPos[i].w, dropPos[i].h, this->darkMode ? this->barColorDark : this->barColorLight);
}
Gui::drawAnimatedSelector(dropPos[dropSelection].x, dropPos[dropSelection].y, dropPos[dropSelection].w, dropPos[dropSelection].h, .090, this->darkMode ? this->barColorDark : this->barColorLight, TRANSPARENT);
// Draw Dropdown Icons.
//GFX::DrawSpriteBlend(sprites_theme_idx, this->dropPos[0].x, this->dropPos[0].y); // Theme Icon instead.
//GFX::DrawSpriteBlend(sprites_style_idx, this->dropPos[1].x, this->dropPos[1].y); // Style Icon instead.
// Dropdown Text.
Gui::DrawString(this->dropPos[0].x+30, this->dropPos[0].y+5, 0.4f, this->returnTextColor(), Lang::get("CHANGE_THEME"), 100);
Gui::DrawString(this->dropPos[1].x+30, this->dropPos[1].y+5, 0.4f, this->returnTextColor(), Lang::get("CHANGE_STYLE"), 100);
}
}
}
void UniStoreV2::displaySelectedEntry(int selection) const {
this->DrawBaseTop();
Gui::DrawStringCentered(0, 218, 0.7f, this->returnTextColor(), std::to_string(this->downloadPage + 1) + " | " + std::to_string(1 + (this->objects.size() / DOWNLOAD_ENTRIES)));
if (this->storeJson.at("storeContent").at(selection).at("info").contains("title")) {
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, this->returnTextColor(), (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("title"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, this->returnTextColor(), (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("title"), 400);
}
} else {
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, this->returnTextColor(), "?", 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, this->returnTextColor(), "?", 400);
}
}
if (this->storeJson.at("storeContent").at(selection).at("info").contains("author")) {
Gui::DrawStringCentered(0, 40, 0.6f, this->returnTextColor(), Lang::get("AUTHOR") + (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("author"), 400);
} else {
Gui::DrawStringCentered(0, 40, 0.6f, this->returnTextColor(), Lang::get("AUTHOR") + "?", 400);
}
if (this->storeJson.at("storeContent").at(selection).at("info").contains("version")) {
Gui::DrawStringCentered(0, 60, 0.6f, this->returnTextColor(), Lang::get("VERSION") + (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("version"), 400);
} else {
Gui::DrawStringCentered(0, 60, 0.6f, this->returnTextColor(), Lang::get("VERSION") + "?", 400);
}
if (this->storeJson.at("storeContent").at(selection).at("info").contains("category")) {
Gui::DrawStringCentered(0, 80, 0.6f, this->returnTextColor(), Lang::get("CATEGORY") + (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("category"), 400);
} else {
Gui::DrawStringCentered(0, 80, 0.6f, this->returnTextColor(), Lang::get("CATEGORY") + "?", 400);
}
if (this->storeJson.at("storeContent").at(selection).at("info").contains("console")) {
Gui::DrawStringCentered(0, 100, 0.6f, this->returnTextColor(), Lang::get("SYSTEM") + (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("console"), 400);
} else {
Gui::DrawStringCentered(0, 100, 0.6f, this->returnTextColor(), Lang::get("SYSTEM") + "?", 400);
}
if (this->storeJson.at("storeContent").at(selection).at("info").contains("last_updated")) {
Gui::DrawStringCentered(0, 120, 0.6f, this->returnTextColor(), Lang::get("LAST_UPDATED") + (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("last_updated"), 400);
} else {
Gui::DrawStringCentered(0, 120, 0.6f, this->returnTextColor(), Lang::get("LAST_UPDATED") + "?", 400);
}
if (this->storeJson.at("storeContent").at(selection).at("info").contains("description")) {
Gui::DrawStringCentered(0, 140, 0.5f, this->returnTextColor(), Lang::get("DESC") + (std::string)this->storeJson.at("storeContent").at(selection).at("info").at("description"), 400);
} else {
Gui::DrawStringCentered(0, 140, 0.5f, this->returnTextColor(), Lang::get("DESC") + "?", 400);
}
this->DrawBaseBottom();
if (this->objects.size() > 0) {
for (int i = 0, i2 = (this->downloadPage * DOWNLOAD_ENTRIES); i2 < DOWNLOAD_ENTRIES + (this->downloadPage * DOWNLOAD_ENTRIES) && i2 < (int)this->objects.size(); i2++, i++) {
if (i + (this->downloadPage * DOWNLOAD_ENTRIES) == this->subSelection) {
this->drawBox(downloadBoxes[i].x, downloadBoxes[i].y, downloadBoxes[i].w, downloadBoxes[i].h, true);
} else {
this->drawBox(downloadBoxes[i].x, downloadBoxes[i].y, downloadBoxes[i].w, downloadBoxes[i].h, false);
}
Gui::DrawStringCentered(0, downloadBoxes[i].y+4, 0.5f, this->returnTextColor(), this->objects[i + (this->downloadPage * DOWNLOAD_ENTRIES)], 280);
}
} else {
Gui::DrawStringCentered(0, downloadBoxes[0].y+4, 0.5f, this->returnTextColor(), Lang::get("NO_DOWNLOADS_AVAILABLE"), 280);
}
}
void UniStoreV2::Draw(void) const {
if (this->mode == 0) {
this->DrawBaseTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.6f, this->returnTextColor(), (std::string)this->storeJson.at("storeInfo").at("title"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.6f, this->returnTextColor(), (std::string)this->storeJson.at("storeInfo").at("title"), 400);
}
this->DrawGrid();
Gui::DrawStringCentered(0, 218, 0.6f, this->returnTextColor(), std::to_string(this->storePage + 1) + " | " + std::to_string(1 + (this->storeJson.at("storeContent").size() / STORE_ENTRIES)));
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
this->DrawBaseBottom();
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
} else if (this->mode == 1) {
this->DrawBaseTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.6f, this->returnTextColor(), (std::string)this->storeJson.at("storeInfo").at("title"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.6f, this->returnTextColor(), (std::string)this->storeJson.at("storeInfo").at("title"), 400);
}
this->DrawList();
Gui::DrawStringCentered(0, 218, 0.6f, this->returnTextColor(), std::to_string(this->storePageList + 1) + " | " + std::to_string(1 + (this->storeJson.at("storeContent").size() / STORE_ENTRIES_LIST)));
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
this->DrawBaseBottom();
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
} else if (this->mode == 2) {
this->displaySelectedEntry(this->selection);
}
if (this->mode != 2) GFX::DrawSpriteBlend(sprites_dropdown_idx, iconPos[0].x, iconPos[0].y);
this->DropDownMenu();
}
void UniStoreV2::DropLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->mode != 2) {
if (hDown & KEY_DOWN) {
if (this->dropSelection < (int)this->dropPos.size()-1) this->dropSelection++;
}
if (hDown & KEY_UP) {
if (this->dropSelection > 0) this->dropSelection--;
}
if (hDown & KEY_A) {
switch(this->dropSelection) {
case 0:
if (this->darkMode) this->darkMode = false;
else this->darkMode = true;
break;
case 1:
if (this->mode == 0) this->mode = 1;
else this->mode = 0;
break;
}
this->isDropDown = false;
}
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, this->iconPos[3]))) {
this->isDropDown = false;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, this->dropPos[0])) {
if (this->darkMode) this->darkMode = false;
else this->darkMode = true;
this->isDropDown = false;
} else if (touching(touch, this->dropPos[1])) {
if (this->mode == 0) this->mode = 1;
else this->mode = 0;
this->isDropDown = false;
}
}
}
}
void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->isDropDown) {
this->DropLogic(hDown, hHeld, touch);
} else {
if (this->mode == 0) {
if (hDown & KEY_B) {
if (!didAutoboot) didAutoboot = true;
Gui::screenBack(Config::fading);
return;
}
if (hDown & KEY_RIGHT) {
// Try to go to next page.
if (this->selectedBox == 2 || this->selectedBox == 5 || this->selectedBox == 8) {
if (STORE_ENTRIES + (this->storePage * STORE_ENTRIES) < (int)this->storeJson.at("storeContent").size()) {
this->selectedBox = 0;
this->storePage++;
}
} else {
if ((this->storePage * STORE_ENTRIES) + this->selectedBox + 1 < (int)this->storeJson.at("storeContent").size()) {
if (this->selectedBox < 8 + (this->storePage * STORE_ENTRIES)) this->selectedBox++;
}
}
}
if (hDown & KEY_LEFT) {
// Try to go to next page.
if (this->selectedBox == 0 || this->selectedBox == 3 || this->selectedBox == 6) {
if (this->storePage > 0) {
this->selectedBox = 0;
this->storePage--;
}
} else {
if (this->selectedBox > 0) this->selectedBox--;
}
}
if (hDown & KEY_UP) {
if (this->selectedBox > 2 + (this->storePage * STORE_ENTRIES)) this->selectedBox -= 3;
}
if (hDown & KEY_DOWN) {
if ((this->storePage * STORE_ENTRIES) + this->selectedBox + 3 < (int)this->storeJson.at("storeContent").size()) {
if (this->selectedBox < 6) this->selectedBox += 3;
}
}
if (hDown & KEY_R) {
if (STORE_ENTRIES + (this->storePage * STORE_ENTRIES) < (int)this->storeJson.at("storeContent").size()) {
this->selectedBox = 0;
this->storePage++;
}
}
if (hDown & KEY_L) {
if (this->storePage > 0) {
this->selectedBox = 0;
this->storePage--;
}
}
if (hDown & KEY_A) {
if (this->selectedBox + (this->storePage * STORE_ENTRIES) < (int)this->storeJson.at("storeContent").size()) {
this->selection = this->selectedBox + (this->storePage * STORE_ENTRIES);
this->parseObjects(this->selection);
this->canDisplay = true;
this->lastViewMode = this->mode;
this->mode = 2;
}
}
} else if (this->mode == 1) {
if (hDown & KEY_B) {
if (!didAutoboot) didAutoboot = true;
Gui::screenBack(Config::fading);
return;
}
if (hDown & KEY_DOWN) {
if ((this->storePageList * STORE_ENTRIES_LIST) + this->selectedBoxList + 1 < (int)this->storeJson.at("storeContent").size()) {
if (this->selectedBoxList < STORE_ENTRIES_LIST-1) this->selectedBoxList++;
}
}
if (hDown & KEY_UP) {
if (this->selectedBoxList > 0) this->selectedBoxList--;
}
if (hDown & KEY_RIGHT || hDown & KEY_R) {
if (STORE_ENTRIES_LIST + (this->storePageList * STORE_ENTRIES_LIST) < (int)this->storeJson.at("storeContent").size()) {
this->selectedBoxList = 0;
this->storePageList++;
}
}
if (hDown & KEY_LEFT || hDown & KEY_L) {
if (this->storePageList > 0) {
this->selectedBoxList = 0;
this->storePageList--;
}
}
if (hDown & KEY_A) {
if (this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST) < (int)this->storeJson.at("storeContent").size()) {
this->selection = this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST);
this->parseObjects(this->selection);
this->canDisplay = true;
this->lastViewMode = this->mode;
this->mode = 2;
}
}
} else if (this->mode == 2) {
if (hDown & KEY_TOUCH) {
if (this->objects.size() > 0) {
for (int i = 0, i2 = 0 + (this->downloadPage * DOWNLOAD_ENTRIES); i2 < DOWNLOAD_ENTRIES + (this->downloadPage * DOWNLOAD_ENTRIES) && i2 < (int)this->objects.size(); i2++, i++) {
if (touching(touch, downloadBoxes[i])) {
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n" + this->objects[i + (this->downloadPage * DOWNLOAD_ENTRIES)])) runFunctions(this->objects[i + (this->downloadPage * DOWNLOAD_ENTRIES)]);
}
}
}
}
if (hDown & KEY_A) {
if (this->objects.size() > 0) {
if ((int)this->objects.size() >= this->subSelection) {
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n" + this->objects[this->subSelection])) runFunctions(this->objects[this->subSelection]);
}
}
}
if (hDown & KEY_DOWN) {
if (this->subSelection < (int)this->objects.size()-1) {
if (this->subSelection < DOWNLOAD_ENTRIES + (this->downloadPage * DOWNLOAD_ENTRIES)-1) {
this->subSelection++;
}
}
}
if (hDown & KEY_UP) {
if (this->subSelection > 0) {
if (this->subSelection > this->downloadPage * DOWNLOAD_ENTRIES) {
this->subSelection--;
}
}
}
if (hDown & KEY_R || hDown & KEY_RIGHT) {
if (DOWNLOAD_ENTRIES + (this->downloadPage * DOWNLOAD_ENTRIES) < (int)this->objects.size()) {
this->downloadPage++;
this->subSelection = this->downloadPage * DOWNLOAD_ENTRIES;
}
}
if (hDown & KEY_L || hDown & KEY_LEFT) {
if (this->downloadPage > 0) {
this->downloadPage--;
this->subSelection = this->downloadPage * DOWNLOAD_ENTRIES;
}
}
if (hDown & KEY_B) {
this->downloadPage = 0; // Reset page to 0.
this->subSelection = 0;
this->mode = this->lastViewMode;
}
}
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, iconPos[0]))) {
if (this->mode != 2) {
this->dropSelection = 0;
this->isDropDown = true;
}
}
}
}
// Execute | run the script.
Result UniStoreV2::runFunctions(std::string entry) {
Result ret = NONE; // No Error as of yet.
for(int i=0;i<(int)this->storeJson.at("storeContent").at(this->selection).at(entry).size();i++) {
if (ret == NONE) {
std::string type = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("type");
if (type == "deleteFile") {
bool missing = false;
std::string file, message;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("file")) file = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
if(!missing) ret = ScriptHelper::removeFile(file, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadFile") {
bool missing = false;
std::string file, output, message;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("file")) file = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("output")) output = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("output");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
if(!missing) ret = ScriptHelper::downloadFile(file, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadRelease") {
bool missing = false, includePrereleases = false, showVersions = false;
std::string repo, file, output, message;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("repo")) repo = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("repo");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("file")) file = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("output")) output = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("output");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("includePrereleases") && this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("includePrereleases").is_boolean())
includePrereleases = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("includePrereleases");
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("showVersions") && this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("showVersions").is_boolean())
showVersions = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("showVersions");
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
if(!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
} else if(type == "extractFile") {
bool missing = false;
std::string file, input, output, message;
if(this->storeJson.at("storeContent").at("storeContent").at(this->selection).at(entry).at(i).contains("file")) file = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("input")) input = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("input");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("output")) output = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("output");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
if(!missing) ScriptHelper::extractFile(file, input, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "installCia") {
bool missing = false, updateSelf = false;
std::string file, message;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("file")) file = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("file");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("updateSelf") && this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("updateSelf").is_boolean()) {
updateSelf = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("updateSelf");
}
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
if(!missing) ScriptHelper::installFile(file, updateSelf, message);
else ret = SYNTAX_ERROR;
} else if (type == "mkdir") {
bool missing = false;
std::string directory, message;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("directory");
else missing = true;
if(!missing) makeDirs(directory.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "rmdir") {
bool missing = false;
std::string directory, message, promptmsg;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("directory");
else missing = true;
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
if(!missing) {
if(access(directory.c_str(), F_OK) != 0 ) {
ret = DELETE_ERROR;
} else {
if (Msg::promptMsg(promptmsg)) {
removeDirRecursive(directory.c_str());
}
}
}
else ret = SYNTAX_ERROR;
} else if (type == "mkfile") {
bool missing = false;
std::string file;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("file")) file = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("file");
else missing = true;
if(!missing) ScriptHelper::createFile(file.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "timeMsg") {
bool missing = false;
std::string message;
int seconds;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("seconds") && this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("seconds").is_number())
seconds = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("seconds");
else missing = true;
if(!missing) ScriptHelper::displayTimeMsg(message, seconds);
else ret = SYNTAX_ERROR;
} else if (type == "saveConfig") {
Config::save();
} else if (type == "bootTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("TitleID")) TitleID = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("TitleID");
else missing = true;
if (this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("NAND") && this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("NAND").is_boolean()) isNAND = this->storeJson.at(this->selection).at(entry).at(i).at("NAND");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
else missing = true;
if(!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
else ret = SYNTAX_ERROR;
} else if (type == "promptMessage") {
std::string Message = "";
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) Message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
ret = ScriptHelper::prompt(Message);
} else if (type == "copy") {
std::string Message = "", source = "", destination = "";
bool missing = false;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("source")) source = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("source");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("destination")) destination = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("destination");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) Message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
if (!missing) ret = ScriptHelper::copyFile(source, destination, Message);
else ret = SYNTAX_ERROR;
} else if (type == "move") {
std::string Message = "", oldFile = "", newFile = "";
bool missing = false;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("old")) oldFile = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("old");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("new")) newFile = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("new");
else missing = true;
if(this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).contains("message")) Message = this->storeJson.at("storeContent").at(this->selection).at(entry).at(i).at("message");
if (!missing) ret = ScriptHelper::renameFile(oldFile, newFile, Message);
else ret = SYNTAX_ERROR;
}
}
}
if (ret == NONE) doneMsg();
else if (ret == FAILED_DOWNLOAD) Msg::DisplayWarnMsg(Lang::get("DOWNLOAD_ERROR"));
else if (ret == SCRIPT_CANCELED) Msg::DisplayWarnMsg(Lang::get("SCRIPT_CANCELED"));
else if (ret == SYNTAX_ERROR) Msg::DisplayWarnMsg(Lang::get("SYNTAX_ERROR"));
else if (ret == COPY_ERROR) Msg::DisplayWarnMsg(Lang::get("COPY_ERROR"));
else if (ret == MOVE_ERROR) Msg::DisplayWarnMsg(Lang::get("MOVE_ERROR"));
else if (ret == DELETE_ERROR) Msg::DisplayWarnMsg(Lang::get("DELETE_ERROR"));
return ret;
}