Fully rewrite config.

This commit is contained in:
StackZ
2020-06-20 15:22:50 +02:00
parent 7972fd483a
commit 50e4aa99e0
22 changed files with 1372 additions and 1274 deletions
+3 -1
View File
@@ -31,6 +31,8 @@
#include "gui.hpp"
#include "sprites.h"
extern std::unique_ptr<Config> config;
namespace GFX {
// Basic GUI.
void DrawTop(void);
@@ -41,7 +43,7 @@ namespace GFX {
void DrawSprite(int img, int x, int y, float ScaleX = 1, float ScaleY = 1);
void DrawSpriteBlend(int img, int x, int y, float ScaleX = 1, float ScaleY = 1);
void DrawButton(int x, int y, std::string ButtonText = "", u32 color = Config::Button);
void DrawButton(int x, int y, std::string ButtonText = "", u32 color = config->buttonColor());
}
#endif
+97 -12
View File
@@ -24,28 +24,113 @@
* reasonable ways as different from the original version.
*/
#ifndef CONFIG_HPP
#define CONFIG_HPP
#ifndef _UNIVERSAL_UPDATER_CONFIG_HPP
#define _UNIVERSAL_UPDATER_CONFIG_HPP
#include "json.hpp"
#include <3ds.h>
#include <string>
namespace Config {
extern int LangPath, Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor, viewMode, progressbarColor, autoboot, outdated, uptodate, notFound, future, Button, keyDelay;
extern std::string lang, ScriptPath, MusicPath, StorePath, AutobootFile;
extern bool Logging, UseBars, fading, progress;
void load();
class Config {
public:
Config();
void save();
void initializeNewConfig();
void initialize();
// Bar Color.
u32 barColor() { return this->v_barColor; }
void barColor(u32 v) { this->v_barColor = v; if (!this->changesMade) this->changesMade = true; }
// Top BG Color.
u32 topBG() { return this->v_topBG; }
void topBG(u32 v) { this->v_topBG = v; if (!this->changesMade) this->changesMade = true; }
// Bottom BG Color.
u32 bottomBG() { return this->v_bottomBG; }
void bottomBG(u32 v) { this->v_bottomBG = v; if (!this->changesMade) this->changesMade = true; }
// Text Color.
u32 textColor() { return this->v_textColor; }
void textColor(u32 v) { this->v_textColor = v; if (!this->changesMade) this->changesMade = true; }
// Button Color.
u32 buttonColor() { return this->v_buttonColor; }
void buttonColor(u32 v) { this->v_buttonColor = v; if (!this->changesMade) this->changesMade = true; }
// Selected Color.
u32 selectedColor() { return this->v_selectedColor; }
void selectedColor(u32 v) { this->v_selectedColor = v; if (!this->changesMade) this->changesMade = true; }
// Unselected Color.
u32 unselectedColor() { return this->v_unselectedColor; }
void unselectedColor(u32 v) { this->v_unselectedColor = v; if (!this->changesMade) this->changesMade = true; }
// Script Path.
std::string scriptPath() { return this->v_scriptPath; }
void scriptPath(std::string v) { this->v_scriptPath = v; if (!this->changesMade) this->changesMade = true; }
// Lang Path.
int langPath() { return this->v_langPath; }
void langPath(int v) { this->v_langPath = v; if (!this->changesMade) this->changesMade = true; }
// View Mode.
int viewMode() { return this->v_viewMode; }
void viewMode(int v) { this->v_viewMode = v; if (!this->changesMade) this->changesMade = true; }
// Progressbar Color.
u32 progressbarColor() { return this->v_progressbarColor; }
void progressbarColor(u32 v) { this->v_progressbarColor = v; if (!this->changesMade) this->changesMade = true; }
// Music Path.
std::string musicPath() { return this->v_musicPath; }
void musicPath(std::string v) { this->v_musicPath = v; if (!this->changesMade) this->changesMade = true; }
// Logging.
bool logging() { return this->v_logging; }
void logging(bool v) { this->v_logging = v; if (!this->changesMade) this->changesMade = true; }
// Use bars.
bool useBars() { return this->v_useBars; }
void useBars(bool v) { this->v_useBars = v; if (!this->changesMade) this->changesMade = true; }
// Autoboot.
int autoboot() { return this->v_autoboot; }
void autoboot(int v) { this->v_autoboot = v; if (!this->changesMade) this->changesMade = true; }
// Store Path.
std::string storePath() { return this->v_storePath; }
void storePath(std::string v) { this->v_storePath = v; if (!this->changesMade) this->changesMade = true; }
// Autoboto file.
std::string autobootFile() { return this->v_autobootFile; }
void autobootFile(std::string v) { this->v_autobootFile = v; if (!this->changesMade) this->changesMade = true; }
// Outdated Script Color.
u32 outdatedColor() { return this->v_outdatedColor; }
void outdatedColor(u32 v) { this->v_outdatedColor = v; if (!this->changesMade) this->changesMade = true; }
// Uptodate Script Color.
u32 uptodateColor() { return this->v_uptodateColor; }
void uptodateColor(u32 v) { this->v_uptodateColor = v; if (!this->changesMade) this->changesMade = true; }
// Not found Script Color.
u32 notfoundColor() { return this->v_notfoundColor; }
void notfoundColor(u32 v) { this->v_notfoundColor = v; if (!this->changesMade) this->changesMade = true; }
// Future Script Color.
u32 futureColor() { return this->v_futureColor; }
void futureColor(u32 v) { this->v_futureColor = v; if (!this->changesMade) this->changesMade = true; }
// Keydelay.
int keyDelay() { return this->v_keyDelay; }
void keyDelay(int v) { this->v_keyDelay = v; if (!this->changesMade) this->changesMade = true; }
// Screen Fade.
bool screenFade() { return this->v_screenFade; }
void screenFade(bool v) { this->v_screenFade = v; if (!this->changesMade) this->changesMade = true; }
// Progressbar Display.
bool progressDisplay() { return this->v_progressDisplay; }
void progressDisplay(bool v) { this->v_progressDisplay = v; if (!this->changesMade) this->changesMade = true; }
// Language.
std::string language() { return this->v_language; }
void language(std::string v) { this->v_language = v; if (!this->changesMade) this->changesMade = true; }
// Mainly helper.
bool getBool(const std::string &key);
void setBool(const std::string &key, bool v);
int getInt(const std::string &key);
void setInt(const std::string &key, int v);
std::string getString(const std::string &key);
void setString(const std::string &key, const std::string &v);
}
private:
nlohmann::json json; // Our private JSON file.
bool changesMade = false;
// Color variables and more.
u32 v_barColor, v_topBG, v_bottomBG, v_textColor, v_buttonColor, v_selectedColor, v_unselectedColor, v_progressbarColor,
v_outdatedColor, v_uptodateColor, v_notfoundColor, v_futureColor;
std::string v_scriptPath, v_musicPath, v_storePath, v_autobootFile, v_language;
int v_langPath, v_viewMode, v_autoboot, v_keyDelay;
bool v_logging, v_useBars, v_screenFade, v_progressDisplay;
};
#endif
+10 -9
View File
@@ -30,44 +30,45 @@ extern bool isScriptSelected;
extern u32 progressBar;
extern u32 selected;
extern std::unique_ptr<Config> config;
extern C2D_SpriteSheet sprites;
// Draws a Rectangle as the progressbar.
void Animation::DrawProgressBar(float currentProgress, float totalProgress, int mode) {
if (Config::progress) {
if (config->progressDisplay()) {
// Outline of progressbar.
Gui::Draw_Rect(30, 120, 340, 30, BLACK);
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);
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, config->progressbarColor());
}
}
}
void Animation::DrawProgressBarInstall(u64 currentProgress, u64 totalProgress, int mode) {
if (Config::progress) {
if (config->progressDisplay()) {
// Outline of progressbar.
Gui::Draw_Rect(30, 120, 340, 30, BLACK);
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);
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, config->progressbarColor());
}
}
}
void Animation::DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, int mode) {
if (Config::progress) {
if (config->progressDisplay()) {
// Outline of progressbar.
Gui::Draw_Rect(30, 140, 340, 30, BLACK);
if (mode == 1) {
Gui::Draw_Rect(31, 141, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, progressBar);
} else {
Gui::Draw_Rect(31, 141, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, Config::progressbarColor);
Gui::Draw_Rect(31, 141, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, config->progressbarColor());
}
}
}
@@ -81,9 +82,9 @@ void Animation::Button(int x, int y, float speed) {
g = (selected >> 8) & 0xFF;
b = (selected >> 16) & 0xFF;
} else {
r = Config::SelectedColor & 0xFF;
g = (Config::SelectedColor >> 8) & 0xFF;
b = (Config::SelectedColor >> 16) & 0xFF;
r = config->selectedColor() & 0xFF;
g = (config->selectedColor() >> 8) & 0xFF;
b = (config->selectedColor() >> 16) & 0xFF;
}
u32 color = C2D_Color32(r + (255 - r) * highlight_multiplier, g + (255 - g) * highlight_multiplier, b + (255 - b) * highlight_multiplier, 255);
+17 -16
View File
@@ -44,6 +44,7 @@ static size_t result_written = 0;
std::vector<std::string> _topText;
std::string jsonName;
extern std::unique_ptr<Config> config;
extern bool downloadNightlies;
extern int filesExtracted;
extern std::string extractingFile;
@@ -350,7 +351,7 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
if (Config::UseBars == true) {
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, TextColor, Lang::get("VERSION_SELECT"), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, releaseAmount), 239-Gui::GetStringHeight(0.6f, releaseAmount), 0.6f, TextColor, releaseAmount);
} else {
@@ -370,7 +371,7 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)bruh.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, unselected);
line1 = bruh[screenPos + i].TagName;
@@ -382,7 +383,7 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, TextColor, line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, TextColor, line2, 320);
}
} else if (Config::viewMode == 1) {
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)bruh.size(); i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
line1 = bruh[screenPosList + i].TagName;
@@ -403,10 +404,10 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
if (keyRepeatDelay) keyRepeatDelay--;
if (hidKeysDown() & KEY_Y) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
}
@@ -459,7 +460,7 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
}
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)bruh.size(); i++) {
if(touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (bruh.size() != 0) {
@@ -467,7 +468,7 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
}
}
}
} else if (Config::viewMode == 1) {
} else if (config->viewMode() == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)bruh.size(); i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (bruh.size() != 0) {
@@ -478,13 +479,13 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
}
}
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if(selectedRelease < screenPos) {
screenPos = selectedRelease;
} else if (selectedRelease > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = selectedRelease - ENTRIES_PER_SCREEN + 1;
}
} else if (Config::viewMode == 1) {
} else if (config->viewMode() == 1) {
if(selectedRelease < screenPosList) {
screenPosList = selectedRelease;
} else if (selectedRelease > screenPosList + ENTRIES_PER_LIST - 1) {
@@ -881,7 +882,7 @@ void displayProgressBar() {
if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 1, 0.7f, TextColor, progressBarMsg, 400);
} else {
Gui::DrawStringCentered(0, 1, 0.7f, Config::TxtColor, progressBarMsg, 400);
Gui::DrawStringCentered(0, 1, 0.7f, config->textColor(), progressBarMsg, 400);
}
// Only display this by downloading.
@@ -889,7 +890,7 @@ void displayProgressBar() {
if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 80, 0.6f, TextColor, str, 400);
} else {
Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400);
Gui::DrawStringCentered(0, 80, 0.6f, config->textColor(), str, 400);
}
if (isScriptSelected == true) {
@@ -907,9 +908,9 @@ void displayProgressBar() {
Gui::DrawStringCentered(0, 100, 0.6f, TextColor, std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
Gui::DrawStringCentered(0, 40, 0.6f, TextColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
} else {
Gui::DrawStringCentered(0, 180, 0.6f, Config::TxtColor, str, 400);
Gui::DrawStringCentered(0, 100, 0.6f, Config::TxtColor, std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
Gui::DrawStringCentered(0, 40, 0.6f, Config::TxtColor, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
Gui::DrawStringCentered(0, 180, 0.6f, config->textColor(), str, 400);
Gui::DrawStringCentered(0, 100, 0.6f, config->textColor(), std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
Gui::DrawStringCentered(0, 40, 0.6f, config->textColor(), Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
}
// Progressbar.
if (isScriptSelected == true) {
@@ -924,7 +925,7 @@ void displayProgressBar() {
if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 80, 0.6f, TextColor, str, 400);
} else {
Gui::DrawStringCentered(0, 80, 0.6f, Config::TxtColor, str, 400);
Gui::DrawStringCentered(0, 80, 0.6f, config->textColor(), str, 400);
}
if (isScriptSelected == true) {
+20 -19
View File
@@ -27,6 +27,7 @@
#include "common.hpp"
#include "gfx.hpp"
extern std::unique_ptr<Config> config;
extern bool isScriptSelected;
extern u32 barColor;
extern u32 bgTopColor;
@@ -36,10 +37,10 @@ extern u32 TextColor;
void GFX::DrawTop(void) {
Gui::ScreenDraw(Top);
if (isScriptSelected == false) {
Gui::Draw_Rect(0, 0, 400, 25, Config::Color1);
Gui::Draw_Rect(0, 25, 400, 190, Config::Color2);
Gui::Draw_Rect(0, 215, 400, 25, Config::Color1);
if (Config::UseBars == true) {
Gui::Draw_Rect(0, 0, 400, 25, config->barColor());
Gui::Draw_Rect(0, 25, 400, 190, config->topBG());
Gui::Draw_Rect(0, 215, 400, 25, config->barColor());
if (config->useBars() == true) {
DrawSprite(sprites_top_screen_top_idx, 0, 0);
DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
@@ -47,7 +48,7 @@ void GFX::DrawTop(void) {
Gui::Draw_Rect(0, 0, 400, 30, barColor);
Gui::Draw_Rect(0, 25, 400, 190, bgBottomColor);
Gui::Draw_Rect(0, 215, 400, 25, barColor);
if (Config::UseBars == true) {
if (config->useBars() == true) {
DrawSprite(sprites_top_screen_top_idx, 0, 0);
DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
@@ -57,10 +58,10 @@ void GFX::DrawTop(void) {
void GFX::DrawBottom(void) {
Gui::ScreenDraw(Bottom);
if (isScriptSelected == false) {
Gui::Draw_Rect(0, 0, 320, 25, Config::Color1);
Gui::Draw_Rect(0, 25, 320, 190, Config::Color3);
Gui::Draw_Rect(0, 215, 320, 25, Config::Color1);
if (Config::UseBars == true) {
Gui::Draw_Rect(0, 0, 320, 25, config->barColor());
Gui::Draw_Rect(0, 25, 320, 190, config->bottomBG());
Gui::Draw_Rect(0, 215, 320, 25, config->barColor());
if (config->useBars() == true) {
DrawSprite(sprites_bottom_screen_top_idx, 0, 0);
DrawSprite(sprites_bottom_screen_bot_idx, 0, 215);
}
@@ -68,7 +69,7 @@ void GFX::DrawBottom(void) {
Gui::Draw_Rect(0, 0, 320, 30, barColor);
Gui::Draw_Rect(0, 25, 320, 190, bgBottomColor);
Gui::Draw_Rect(0, 215, 320, 25, barColor);
if (Config::UseBars == true) {
if (config->useBars() == true) {
DrawSprite(sprites_bottom_screen_top_idx, 0, 0);
DrawSprite(sprites_bottom_screen_bot_idx, 0, 215);
}
@@ -89,10 +90,10 @@ void GFX::DrawSpriteBlend(int img, int x, int y, float ScaleX, float ScaleY) {
C2D_SetImageTint(&tint, C2D_BotLeft, TextColor, 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, TextColor, 0.5);
} else {
C2D_SetImageTint(&tint, C2D_TopLeft, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_TopLeft, config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, config->textColor(), 0.5);
}
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, img), x, y, 0.5f, &tint, ScaleX, ScaleY);
@@ -107,10 +108,10 @@ void GFX::DrawArrow(int x, int y, float rotation, int arrowSprite) {
C2D_SetImageTint(&tint, C2D_BotLeft, TextColor, 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, TextColor, 0.5);
} else {
C2D_SetImageTint(&tint, C2D_TopLeft, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, Config::TxtColor, 0.5);
C2D_SetImageTint(&tint, C2D_TopLeft, config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, config->textColor(), 0.5);
}
if (arrowSprite == 0) {
@@ -138,6 +139,6 @@ void GFX::DrawButton(int x, int y, std::string ButtonText, u32 color) {
if (isScriptSelected) {
Gui::DrawStringCentered(- (158/2) + x, y + (61/2) - (Gui::GetStringHeight(0.6f, ButtonText) / 2), 0.6f, TextColor, ButtonText, 145, 30);
} else {
Gui::DrawStringCentered(- (158/2) + x, y + (61/2) - (Gui::GetStringHeight(0.6f, ButtonText) / 2), 0.6f, Config::TxtColor, ButtonText, 145, 30);
Gui::DrawStringCentered(- (158/2) + x, y + (61/2) - (Gui::GetStringHeight(0.6f, ButtonText) / 2), 0.6f, config->textColor(), ButtonText, 145, 30);
}
}
+18 -17
View File
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <ctype.h>
extern std::unique_ptr<Config> config;
extern C3D_RenderTarget* Top;
extern C3D_RenderTarget* Bottom;
@@ -80,21 +81,21 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button);
void Input::DrawNumpad() {
for(uint i=0;i<(sizeof(NumpadStruct)/sizeof(NumpadStruct[0]));i++) {
Gui::Draw_Rect(NumpadStruct[i].x, NumpadStruct[i].y, 60, 50, Config::Color1);
Gui::Draw_Rect(NumpadStruct[i].x, NumpadStruct[i].y, 60, 50, config->barColor());
char c[2] = {NumpadStruct[i].character[0]};
Gui::DrawString(NumpadStruct[i].x+25, NumpadStruct[i].y+15, 0.72f, Config::TxtColor, c, 50);
Gui::DrawString(NumpadStruct[i].x+25, NumpadStruct[i].y+15, 0.72f, config->textColor(), c, 50);
}
}
void Input::drawKeyboard() {
for(uint i=0;i<(sizeof(keysQWERTY)/sizeof(keysQWERTY[0]));i++) {
C2D_DrawRectSolid(keysQWERTY[i].x, keysQWERTY[i].y+103, 0.5f, 20, 20, Config::Color1 & C2D_Color32(255, 255, 255, 200));
C2D_DrawRectSolid(keysQWERTY[i].x, keysQWERTY[i].y+103, 0.5f, 20, 20, config->barColor() & C2D_Color32(255, 255, 255, 200));
if (shift) {
char c[2] = {caps ? (char)toupper(keysQWERTYShift[i].character[0]) : keysQWERTYShift[i].character[0]};
Gui::DrawString(keysQWERTYShift[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTYShift[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c);
Gui::DrawString(keysQWERTYShift[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTYShift[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, config->textColor(), c);
} else {
char c[2] = {caps ? (char)toupper(keysQWERTY[i].character[0]) : keysQWERTY[i].character[0]};
Gui::DrawString(keysQWERTY[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTY[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c);
Gui::DrawString(keysQWERTY[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTY[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, config->textColor(), c);
}
}
@@ -104,13 +105,13 @@ void Input::drawKeyboard() {
std::string backSpace = modifierKeys[0].character;
std::string caps = modifierKeys[1].character;
C2D_DrawRectSolid(modifierKeys[i].x, modifierKeys[i].y+103, 0.5f, modifierKeys[i].w, 20, Config::Color1 & C2D_Color32(255, 255, 255, 200));
Gui::DrawString(modifierKeys[2].x+5, modifierKeys[2].y+105, 0.50, Config::TxtColor, enter);
Gui::DrawString(modifierKeys[3].x+7, modifierKeys[3].y+105, 0.45, Config::TxtColor, arrowUp);
Gui::DrawString(modifierKeys[4].x+10, modifierKeys[4].y+105, 0.45, Config::TxtColor, arrowUp);
C2D_DrawRectSolid(modifierKeys[i].x, modifierKeys[i].y+103, 0.5f, modifierKeys[i].w, 20, config->barColor() & C2D_Color32(255, 255, 255, 200));
Gui::DrawString(modifierKeys[2].x+5, modifierKeys[2].y+105, 0.50, config->textColor(), enter);
Gui::DrawString(modifierKeys[3].x+7, modifierKeys[3].y+105, 0.45, config->textColor(), arrowUp);
Gui::DrawString(modifierKeys[4].x+10, modifierKeys[4].y+105, 0.45, config->textColor(), arrowUp);
Gui::DrawString(modifierKeys[0].x+5, modifierKeys[0].y+105, 0.45, Config::TxtColor, backSpace);
Gui::DrawString(modifierKeys[1].x+5, modifierKeys[1].y+105, 0.45, Config::TxtColor, caps);
Gui::DrawString(modifierKeys[0].x+5, modifierKeys[0].y+105, 0.45, config->textColor(), backSpace);
Gui::DrawString(modifierKeys[1].x+5, modifierKeys[1].y+105, 0.45, config->textColor(), caps);
}
}
@@ -130,11 +131,11 @@ std::string Input::Numpad(uint maxLength, std::string Text) {
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, Config::TxtColor, Text, 400);
Gui::DrawString(180, 217, 0.8, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 400);
Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, config->textColor(), Text, 400);
Gui::DrawString(180, 217, 0.8, config->textColor(), (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 400);
if (cursorBlink < -20) cursorBlink = 20;
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 240, Config::Color3);
Gui::Draw_Rect(0, 0, 320, 240, config->bottomBG());
DrawNumpad();
scanKeys();
hDown = keysDown();
@@ -211,11 +212,11 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
GFX::DrawTop();
Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, Config::TxtColor, Text, 400);
Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, config->textColor(), Text, 400);
GFX::DrawBottom();
drawKeyboard();
C2D_DrawRectSolid(0, 81, 0.5f, 320, 20, Config::Color1 & C2D_Color32(200, 200, 200, 200));
Gui::DrawString(2, 82, inputTextSize, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 316);
C2D_DrawRectSolid(0, 81, 0.5f, 320, 20, config->barColor() & C2D_Color32(200, 200, 200, 200));
Gui::DrawString(2, 82, inputTextSize, config->textColor(), (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 316);
if (cursorBlink < -20) cursorBlink = 20;
scanKeys();
hDown = keysDown();
+16 -15
View File
@@ -27,6 +27,7 @@
#include "common.hpp"
#include "msg.hpp"
extern std::unique_ptr<Config> config;
extern bool isScriptSelected;
extern u32 barColor;
@@ -41,15 +42,15 @@ void Msg::DisplayStartMSG() {
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
Gui::ScreenDraw(Top);
Gui::Draw_Rect(0, 0, 400, 25, Config::Color1);
Gui::Draw_Rect(0, 25, 400, 190, Config::Color2);
Gui::Draw_Rect(0, 215, 400, 25, Config::Color1);
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("STARTING_UNIVERSAL_UPDATER"));
Gui::Draw_Rect(0, 0, 400, 25, config->barColor());
Gui::Draw_Rect(0, 25, 400, 190, config->topBG());
Gui::Draw_Rect(0, 215, 400, 25, config->barColor());
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("STARTING_UNIVERSAL_UPDATER"));
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 25, Config::Color1);
Gui::Draw_Rect(0, 25, 320, 190, Config::Color2);
Gui::Draw_Rect(0, 215, 320, 25, Config::Color1);
Gui::Draw_Rect(0, 0, 320, 25, config->barColor());
Gui::Draw_Rect(0, 25, 320, 190, config->topBG());
Gui::Draw_Rect(0, 215, 320, 25, config->barColor());
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
C3D_FrameEnd(0);
}
@@ -61,7 +62,7 @@ void Msg::DisplayMsg(std::string text) {
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
if (isScriptSelected == false) {
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, text))/2, 0.6f, Config::TxtColor, text, 395, 70);
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, text))/2, 0.6f, config->textColor(), text, 395, 70);
} else if (isScriptSelected == true) {
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, text))/2, 0.6f, TextColor, text, 395, 70);
}
@@ -77,7 +78,7 @@ void Msg::DisplayWarnMsg(std::string Text) {
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
if (isScriptSelected == false) {
Gui::DrawStringCentered(0, 1, 0.6f, Config::TxtColor, Text, 400);
Gui::DrawStringCentered(0, 1, 0.6f, config->textColor(), Text, 400);
} else if (isScriptSelected == true) {
Gui::DrawStringCentered(0, 1, 0.6f, TextColor, Text, 400);
}
@@ -106,8 +107,8 @@ bool Msg::promptMsg(std::string promptMsg) {
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
if (isScriptSelected == false) {
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, promptMsg))/2, 0.6f, Config::TxtColor, promptMsg, 395, 70);
Gui::DrawStringCentered(0, 217, 0.72f, Config::TxtColor, Lang::get("CONFIRM_OR_CANCEL"), 400);
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, promptMsg))/2, 0.6f, config->textColor(), promptMsg, 395, 70);
Gui::DrawStringCentered(0, 217, 0.72f, config->textColor(), Lang::get("CONFIRM_OR_CANCEL"), 400);
} else if (isScriptSelected == true) {
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, promptMsg))/2, 0.6f, TextColor, promptMsg, 395, 70);
Gui::DrawStringCentered(0, 217, 0.72f, TextColor, Lang::get("CONFIRM_OR_CANCEL"), 400);
@@ -115,10 +116,10 @@ bool Msg::promptMsg(std::string promptMsg) {
GFX::DrawBottom();
if (isScriptSelected == false) {
Gui::Draw_Rect(10, 100, 140, 35, Config::Color1);
Gui::Draw_Rect(170, 100, 140, 35, Config::Color1);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, Config::TxtColor, Lang::get("YES"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, Config::TxtColor, Lang::get("NO"), 140);
Gui::Draw_Rect(10, 100, 140, 35, config->barColor());
Gui::Draw_Rect(170, 100, 140, 35, config->barColor());
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, config->textColor(), Lang::get("YES"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, config->textColor(), Lang::get("NO"), 140);
} else if (isScriptSelected == true) {
Gui::Draw_Rect(10, 100, 140, 35, barColor);
Gui::Draw_Rect(170, 100, 140, 35, barColor);
+19 -23
View File
@@ -51,6 +51,7 @@ bool changesMade = false;
// Include all spritesheet's.
C2D_SpriteSheet sprites;
std::unique_ptr<Config> config;
// If button Position pressed -> Do something.
bool touching(touchPosition touch, Structs::ButtonPos button) {
@@ -62,8 +63,8 @@ bool touching(touchPosition touch, Structs::ButtonPos button) {
void Init::loadSoundEffects(void) {
if (dspFound == true) {
if( access( Config::MusicPath.c_str(), F_OK ) != -1 ) {
bgm = new sound(Config::MusicPath, 1, true);
if (access(config->musicPath().c_str(), F_OK ) != -1) {
bgm = new sound(config->musicPath(), 1, true);
songIsFound = true;
}
}
@@ -96,52 +97,50 @@ Result Init::Initialize() {
mkdir("sdmc:/3ds/Universal-Updater/stores", 0777);
// We need to make sure, the file exist.
if (access("sdmc:/3ds/Universal-Updater/Settings.json", F_OK) == -1 ) {
Config::initializeNewConfig();
}
config = std::make_unique<Config>();
Config::load();
Lang::load(Config::lang);
Lang::load(config->language());
if (Config::fading) {
if (config->screenFade()) {
fadein = true;
fadealpha = 255;
}
// In case it takes a bit longer to autoboot a script or so.
Msg::DisplayStartMSG();
if (Config::Logging == true) {
if (config->logging() == true) {
Logging::createLogFile();
}
Gui::loadSheet("romfs:/gfx/sprites.t3x", sprites);
AutobootWhat = Config::autoboot;
AutobootWhat = config->autoboot();
if (Config::autoboot == 1) {
if (access(Config::AutobootFile.c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<UniStore>(true, Config::AutobootFile), false, true);
if (config->autoboot() == 1) {
if (access(config->autobootFile().c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<UniStore>(true, config->autobootFile()), false, true);
} else {
AutobootWhat = 0;
Config::autoboot = 0;
config->autoboot(0);
Gui::setScreen(std::make_unique<MainMenu>(), false, true);
}
} else if (Config::autoboot == 2) {
if (access(Config::AutobootFile.c_str(), F_OK) == 0) {
} else if (config->autoboot() == 2) {
if (access(config->autobootFile().c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<ScriptList>(), false, true);
} else {
AutobootWhat = 0;
Config::autoboot = 0;
config->autoboot(0);
Gui::setScreen(std::make_unique<MainMenu>(), false, true);
}
} else {
AutobootWhat = 0;
Config::autoboot = 0;
config->autoboot(0);
Gui::setScreen(std::make_unique<MainMenu>(), false, true);
}
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
if( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) {
if ( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) {
ndspInit();
dspFound = true;
loadSoundEffects();
@@ -188,10 +187,7 @@ Result Init::Exit() {
ndspExit();
}
// Only save config, if *any* changes are made. (To reduce SD Writes.)
if (changesMade) {
Config::save();
}
config->save();
Gui::exit();
Gui::unloadSheet(sprites);
+4 -3
View File
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <unistd.h>
extern std::unique_ptr<Config> config;
nlohmann::json appJson;
std::string Lang::get(const std::string &key) {
@@ -17,9 +18,9 @@ std::string langs[] = {"br", "da", "de", "en", "es", "fr", "it", "lt", "pl", "pt
void Lang::load(const std::string lang) {
FILE* values;
if (Config::LangPath == 1) {
if (config->langPath() == 1) {
// Check if exist.
if(access("sdmc:/3ds/Universal-Updater/app.json", F_OK) == 0 ) {
if (access("sdmc:/3ds/Universal-Updater/app.json", F_OK) == 0 ) {
values = fopen(("sdmc:/3ds/Universal-Updater/app.json"), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
@@ -34,7 +35,7 @@ void Lang::load(const std::string lang) {
} else {
// Check if exist.
if(access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0 ) {
if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0 ) {
values = fopen(std::string(("romfs:/lang/" + lang + "/app.json")).c_str(), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
+4 -3
View File
@@ -24,12 +24,13 @@
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "logging.hpp"
#include "utils/config.hpp"
#include <memory>
extern std::unique_ptr<Config> config;
std::string Logging::format(const std::string& fmt_str, ...) {
va_list ap;
char* fp = NULL;
@@ -57,7 +58,7 @@ void Logging::createLogFile(void) {
// Only write to the Log, if it is enabled in the Settings File!
void Logging::writeToLog(std::string debugText) {
if (Config::getBool("LOGGING")) {
if (config->logging()) {
std::ofstream logFile;
logFile.open(("sdmc:/3ds/Universal-Updater/Log.log"), std::ofstream::app);
std::string writeDebug = "[ ";
+28 -26
View File
@@ -26,6 +26,7 @@
#include "credits.hpp"
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
// Language Page 1.
const std::vector<std::string> Translators = {
@@ -83,22 +84,23 @@ void Credits::Draw(void) const {
title += Lang::get("CREDITS");
GFX::DrawTop();
if (creditsPage != 3) {
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, title, 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), title, 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, title, 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), title, 400);
}
Gui::DrawStringCentered(0, 30, 0.7f, Config::TxtColor, Lang::get("DEVELOPED_BY"), 390);
Gui::DrawStringCentered(0, 60, 0.7f, Config::TxtColor, Lang::get("MAIN_DEV"), 390);
Gui::DrawStringCentered(0, 30, 0.7f, config->textColor(), Lang::get("DEVELOPED_BY"), 390);
Gui::DrawStringCentered(0, 60, 0.7f, config->textColor(), Lang::get("MAIN_DEV"), 390);
GFX::DrawSprite(sprites_stackie_idx, 5, 85);
GFX::DrawSprite(sprites_universal_core_idx, 200, 110);
std::string currentVersion = Lang::get("CURRENT_VERSION");
currentVersion += V_STRING;
Gui::DrawString(395-Gui::GetStringWidth(0.70f, currentVersion), 219, 0.70f, Config::TxtColor, currentVersion, 400);
Gui::DrawString(395-Gui::GetStringWidth(0.70f, currentVersion), 219, 0.70f, config->textColor(), currentVersion, 400);
} else {
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 190));
GFX::DrawSprite(sprites_discord_idx, 115, 35);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
DrawBottom();
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
@@ -110,41 +112,41 @@ void Credits::DrawBottom(void) const {
GFX::DrawBottom();
if (creditsPage == 0) {
Gui::DrawStringCentered(0, -2, 0.7f, Config::TxtColor, Lang::get("TRANSLATORS"), 320);
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), Lang::get("TRANSLATORS"), 320);
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)Translators.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = Translators[screenPos + i];
line2 = Languages[screenPos + i];
if (screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, line2, 320);
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else if (creditsPage == 1) {
Gui::DrawStringCentered(0, -2, 0.7f, Config::TxtColor, "Universal-Team", 320);
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), "Universal-Team", 320);
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)UniversalTeam.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = UniversalTeam[screenPos + i];
if (screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, WHITE, line1, 320);
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), line1, 320);
}
} else if (creditsPage == 2) {
Gui::DrawStringCentered(0, -2, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATORS"), 320);
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), Lang::get("SCRIPTCREATORS"), 320);
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)ScriptCreators.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = ScriptCreators[screenPos + i];
line2 = ScriptAmount[screenPos + i];
if (screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, line2, 320);
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else {
Gui::DrawStringCentered(0, -2, 0.55f, Config::TxtColor, Lang::get("LINK"), 320);
Gui::DrawStringCentered(0, -2, 0.55f, config->textColor(), Lang::get("LINK"), 320);
}
}
@@ -160,7 +162,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
} else if (creditsPage == 1) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
@@ -170,7 +172,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
} else if (creditsPage == 2) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
@@ -180,7 +182,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
}
@@ -196,7 +198,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = (int)ScriptCreators.size()-1;
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
@@ -215,7 +217,7 @@ void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_B) {
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
+10 -9
View File
@@ -34,6 +34,7 @@ extern "C" {
#include "ftp.h"
}
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern touchPosition touch;
@@ -49,10 +50,10 @@ void FTPScreen::Draw(void) const {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawString((400-Gui::GetStringWidth(0.7f, Lang::get("FTP_MODE")))/2, 0, 0.7f, Config::TxtColor, Lang::get("FTP_MODE"), 400);
if (config->useBars() == true) {
Gui::DrawString((400-Gui::GetStringWidth(0.7f, Lang::get("FTP_MODE")))/2, 0, 0.7f, config->textColor(), Lang::get("FTP_MODE"), 400);
} else {
Gui::DrawString((400-Gui::GetStringWidth(0.7f, Lang::get("FTP_MODE")))/2, 2, 0.7f, Config::TxtColor, Lang::get("FTP_MODE"), 400);
Gui::DrawString((400-Gui::GetStringWidth(0.7f, Lang::get("FTP_MODE")))/2, 2, 0.7f, config->textColor(), Lang::get("FTP_MODE"), 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
@@ -60,22 +61,22 @@ void FTPScreen::Draw(void) const {
ret = ACU_GetWifiStatus(&wifiStatus);
if ((wifiStatus != 0) && R_SUCCEEDED(ret)) {
Gui::DrawStringCentered(0, 40, 0.48f, Config::TxtColor, Lang::get("FTP_INITIALIZED"), 320);
Gui::DrawStringCentered(0, 40, 0.48f, config->textColor(), Lang::get("FTP_INITIALIZED"), 320);
snprintf(buf, 137, "IP: %s:5000", R_FAILED(ret)? Lang::get("FAILED_GET_IP").c_str() : hostname);
if (strlen(ftp_accepted_connection) != 0)
Gui::DrawStringCentered(0, 80, 0.45f, Config::TxtColor, ftp_accepted_connection, 320);
Gui::DrawStringCentered(0, 80, 0.45f, config->textColor(), ftp_accepted_connection, 320);
if (strlen(ftp_file_transfer) != 0)
Gui::DrawStringCentered(0, 150, 0.45f, Config::TxtColor, ftp_file_transfer, 320);
Gui::DrawStringCentered(0, 150, 0.45f, config->textColor(), ftp_file_transfer, 320);
}
else {
Gui::DrawStringCentered(0, 40, 0.48f, Config::TxtColor, Lang::get("FAILED_INITIALIZE_FTP"), 320);
Gui::DrawStringCentered(0, 40, 0.48f, config->textColor(), Lang::get("FAILED_INITIALIZE_FTP"), 320);
snprintf(buf, 18, Lang::get("WIFI_NOT_ENABLED").c_str());
}
Gui::DrawStringCentered(0, 60, 0.48, Config::TxtColor, buf, 320);
Gui::DrawStringCentered(0, 222, 0.48f, Config::TxtColor, Lang::get("B_FTP_EXIT"), 320);
Gui::DrawStringCentered(0, 60, 0.48, config->textColor(), buf, 320);
Gui::DrawStringCentered(0, 222, 0.48f, config->textColor(), Lang::get("B_FTP_EXIT"), 320);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
Gui::clearTextBufs();
C3D_FrameEnd(0);
+15 -14
View File
@@ -32,6 +32,7 @@
#include "settings.hpp"
#include "unistore.hpp"
extern std::unique_ptr<Config> config;
extern bool exiting;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern int fadealpha;
@@ -41,12 +42,12 @@ extern u32 TextColor;
void MainMenu::Draw(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), 239-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, Config::TxtColor, V_STRING);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), 239-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, config->textColor(), V_STRING);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), 237-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, Config::TxtColor, V_STRING);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), 237-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, config->textColor(), V_STRING);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
@@ -73,10 +74,10 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
// Navigation.
if(hDown & KEY_UP) {
if (hDown & KEY_UP) {
if(Selection > 1) Selection -= 2;
} else if(hDown & KEY_DOWN) {
if(Selection < 3 && Selection != 2 && Selection != 3) Selection += 2;
} else if (hDown & KEY_DOWN) {
if (Selection < 3 && Selection != 2 && Selection != 3) Selection += 2;
} else if (hDown & KEY_LEFT) {
if (Selection%2) Selection--;
} else if (hDown & KEY_RIGHT) {
@@ -86,13 +87,13 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_A) {
switch(Selection) {
case 0:
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), Config::fading, true);
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), config->screenFade(), true);
break;
case 1:
Gui::setScreen(std::make_unique<ScriptList>(), Config::fading, true);
Gui::setScreen(std::make_unique<ScriptList>(), config->screenFade(), true);
break;
case 2:
Gui::setScreen(std::make_unique<Settings>(), Config::fading, true);
Gui::setScreen(std::make_unique<Settings>(), config->screenFade(), true);
break;
case 3:
Gui::setScreen(std::make_unique<FTPScreen>(), false, true);
@@ -102,11 +103,11 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), Config::fading, true);
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), config->screenFade(), true);
} else if (touching(touch, mainButtons[1])) {
Gui::setScreen(std::make_unique<ScriptList>(), Config::fading, true);
Gui::setScreen(std::make_unique<ScriptList>(), config->screenFade(), true);
} else if (touching(touch, mainButtons[2])) {
Gui::setScreen(std::make_unique<Settings>(), Config::fading, true);
Gui::setScreen(std::make_unique<Settings>(), config->screenFade(), true);
} else if (touching(touch, mainButtons[3])) {
Gui::setScreen(std::make_unique<FTPScreen>(), false, true);
}
+124 -115
View File
@@ -31,17 +31,18 @@
#include <unistd.h>
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern void downloadFailed();
void fixInfo(nlohmann::json &json) {
for(uint i=0;i<json.size();i++) {
if(!json[i].contains("title")) json[i]["title"] = "TITLE";
if(!json[i].contains("author")) json[i]["author"] = "AUTHOR";
if(!json[i].contains("shortDesc")) json[i]["shortDesc"] = "SHORTDESC";
if(!json[i].contains("revision")) json[i]["revision"] = 0;
if(!json[i].contains("curRevision")) json[i]["curRevision"] = -1;
if(!json[i].contains("version")) json[i]["revision"] = -1;
for(uint i = 0; i < json.size(); i++) {
if (!json[i].contains("title")) json[i]["title"] = "TITLE";
if (!json[i].contains("author")) json[i]["author"] = "AUTHOR";
if (!json[i].contains("shortDesc")) json[i]["shortDesc"] = "SHORTDESC";
if (!json[i].contains("revision")) json[i]["revision"] = 0;
if (!json[i].contains("curRevision")) json[i]["curRevision"] = -1;
if (!json[i].contains("version")) json[i]["revision"] = -1;
}
}
@@ -49,18 +50,17 @@ nlohmann::json infoFromScript(const std::string &path) {
nlohmann::json in, out;
FILE* file = fopen(path.c_str(), "r");
if(!file) {
return out;
}
if (!file) return out;
in = nlohmann::json::parse(file, nullptr, false);
fclose(file);
if(in.contains("info")) {
if(in["info"].contains("title") && in["info"]["title"].is_string()) out["title"] = in["info"]["title"];
if(in["info"].contains("author") && in["info"]["author"].is_string()) out["author"] = in["info"]["author"];
if(in["info"].contains("shortDesc") && in["info"]["shortDesc"].is_string()) out["shortDesc"] = in["info"]["shortDesc"];
if(in["info"].contains("version") && in["info"]["version"].is_number()) out["version"] = in["info"]["version"];
if(in["info"].contains("revision") && in["info"]["revision"].is_number()) out["revision"] = in["info"]["revision"];
if (in.contains("info")) {
if (in["info"].contains("title") && in["info"]["title"].is_string()) out["title"] = in["info"]["title"];
if (in["info"].contains("author") && in["info"]["author"].is_string()) out["author"] = in["info"]["author"];
if (in["info"].contains("shortDesc") && in["info"]["shortDesc"].is_string()) out["shortDesc"] = in["info"]["shortDesc"];
if (in["info"].contains("version") && in["info"]["version"].is_number()) out["version"] = in["info"]["version"];
if (in["info"].contains("revision") && in["info"]["revision"].is_number()) out["revision"] = in["info"]["revision"];
}
return out;
@@ -68,17 +68,18 @@ nlohmann::json infoFromScript(const std::string &path) {
void findExistingFiles(nlohmann::json &json) {
nlohmann::json current;
chdir(Config::ScriptPath.c_str());
chdir(config->scriptPath().c_str());
std::vector<DirEntry> dirContents;
getDirectoryContents(dirContents);
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
current[i] = infoFromScript(dirContents[i].name);
}
fixInfo(current);
for(uint i=0;i<json.size();i++) {
for(uint j=0;j<current.size();j++) {
if(current[j]["title"] == json[i]["title"]) {
for(uint i = 0; i < json.size(); i++) {
for(uint j = 0; j < current.size(); j++) {
if (current[j]["title"] == json[i]["title"]) {
json[i]["curRevision"] = current[j]["revision"];
}
}
@@ -96,7 +97,7 @@ ScriptBrowse::ScriptBrowse() {
}
FILE* file = fopen(metaFile, "r");
if(file) {
if (file) {
infoJson = nlohmann::json::parse(file, nullptr, false);
fclose(file);
fixInfo(infoJson);
@@ -118,8 +119,9 @@ void ScriptBrowse::refresh() {
loaded = false;
return;
}
FILE* file = fopen(metaFile, "r");
if(file) {
if (file) {
infoJson = nlohmann::json::parse(file, nullptr, false);
fclose(file);
fixInfo(infoJson);
@@ -135,6 +137,7 @@ void ScriptBrowse::refresh() {
notConnectedMsg();
}
}
void ScriptBrowse::Draw(void) const {
if (mode == 0) {
DrawBrowse();
@@ -150,24 +153,25 @@ void ScriptBrowse::DrawBrowse(void) const {
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);
if (config->useBars() == true) {
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), 239-Gui::GetStringHeight(0.6f, revision), 0.6f, config->textColor(), revision);
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), 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::DrawString(397-Gui::GetStringWidth(0.6f, revision), 237-Gui::GetStringHeight(0.6f, revision), 0.6f, config->textColor(), revision);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), std::string(infoJson[Selection]["title"]), 400);
}
Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(infoJson[Selection]["shortDesc"]), 400);
Gui::DrawStringCentered(0, 120, 0.6f, config->textColor(), 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);
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("SCRIPT_NOT_FOUND"), 370);
} else if(infoJson[Selection]["curRevision"] < infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 370);
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("OUTDATED_SCRIPT"), 370);
} else if(infoJson[Selection]["curRevision"] == infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 370);
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("UP-TO-DATE"), 370);
} else if(infoJson[Selection]["curRevision"] > infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 370);
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("FUTURE_SCRIPT"), 370);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(295, -1);
@@ -176,65 +180,66 @@ void ScriptBrowse::DrawBrowse(void) const {
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
Gui::DrawStringCentered(0, 1, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts));
Gui::DrawStringCentered(0, 1, 0.6f, config->textColor(), 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 (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 (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
}
if (infoJson[screenPos+i]["curRevision"] == -1) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::notFound);
} else if(infoJson[screenPos+i]["curRevision"] < infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::outdated);
} else if(infoJson[screenPos+i]["curRevision"] == infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::uptodate);
} else if(infoJson[screenPos+i]["curRevision"] > infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, Config::future);
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->notfoundColor());
} else if (infoJson[screenPos+i]["curRevision"] < infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->outdatedColor());
} else if (infoJson[screenPos+i]["curRevision"] == infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->uptodateColor());
} else if (infoJson[screenPos+i]["curRevision"] > infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->futureColor());
}
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);
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), infoJson[screenPos+i]["title"], 317);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), 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) {
} 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 (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, config->selectedColor());
}
}
// Script not found.
if (infoJson[screenPosList+i]["curRevision"] == -1) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::notFound);
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->notfoundColor());
// Script outdaed.
} else if(infoJson[screenPosList+i]["curRevision"] < infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::outdated);
} else if (infoJson[screenPosList+i]["curRevision"] < infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->outdatedColor());
// Script up-to-date.
} else if(infoJson[screenPosList+i]["curRevision"] == infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::uptodate);
} else if (infoJson[screenPosList+i]["curRevision"] == infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->uptodateColor());
// Future script.
} else if(infoJson[screenPosList+i]["curRevision"] > infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, Config::future);
} else if (infoJson[screenPosList+i]["curRevision"] > infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->futureColor());
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, Config::TxtColor, infoJson[screenPosList+i]["title"], 317);
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, config->textColor(), infoJson[screenPosList+i]["title"], 317);
}
}
// DropDown Menu.
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 130, Config::Color1);
Gui::Draw_Rect(0, 25, 140, 130, config->barColor());
for (int i = 0; i < 3; i++) {
if (dropSelection == i) {
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, config->selectedColor());
} else {
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, Config::UnselectedColor);
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, config->unselectedColor());
}
}
// Draw Dropdown Icons.
@@ -242,9 +247,9 @@ void ScriptBrowse::DrawBrowse(void) const {
GFX::DrawSpriteBlend(sprites_update_idx, dropPos[1].x, dropPos[1].y);
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[2].x, dropPos[2].y);
// Dropdown Text.
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, Config::TxtColor, Lang::get("DOWNLOAD_ALL_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, Config::TxtColor, Lang::get("REFRESH_BROWSE_DDM"), 100);
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, Config::TxtColor, Lang::get("VIEW_DDM"), 100);
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, config->textColor(), Lang::get("DOWNLOAD_ALL_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, config->textColor(), Lang::get("REFRESH_BROWSE_DDM"), 100);
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, config->textColor(), 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
} else {
@@ -257,42 +262,42 @@ void ScriptBrowse::DrawBrowse(void) const {
void ScriptBrowse::DrawGlossary(void) const {
GFX::DrawTop();
if (loaded) {
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("GLOSSARY"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("GLOSSARY"), 400);
}
Gui::Draw_Rect(20, 30, 30, 30, Config::notFound);
Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("SCRIPT_NOT_FOUND"), 300);
Gui::Draw_Rect(20, 30, 30, 30, config->notfoundColor());
Gui::DrawString(65, 35, 0.7f, config->textColor(), Lang::get("SCRIPT_NOT_FOUND"), 300);
Gui::Draw_Rect(20, 70, 30, 30, Config::outdated);
Gui::DrawString(65, 75, 0.7f, Config::TxtColor, Lang::get("OUTDATED_SCRIPT"), 300);
Gui::Draw_Rect(20, 70, 30, 30, config->outdatedColor());
Gui::DrawString(65, 75, 0.7f, config->textColor(), Lang::get("OUTDATED_SCRIPT"), 300);
Gui::Draw_Rect(20, 110, 30, 30, Config::uptodate);
Gui::DrawString(65, 115, 0.7f, Config::TxtColor, Lang::get("UP-TO-DATE"), 300);
Gui::Draw_Rect(20, 110, 30, 30, config->uptodateColor());
Gui::DrawString(65, 115, 0.7f, config->textColor(), Lang::get("UP-TO-DATE"), 300);
Gui::Draw_Rect(20, 150, 30, 30, Config::future);
Gui::DrawString(65, 155, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 300);
Gui::Draw_Rect(20, 150, 30, 30, config->futureColor());
Gui::DrawString(65, 155, 0.7f, config->textColor(), 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);
Gui::DrawString(15, 185, 0.7f, config->textColor(), std::to_string(int64_t(infoJson[Selection]["curRevision"])) + " | " + std::to_string(int64_t(infoJson[Selection]["revision"])), 40);
Gui::DrawString(65, 185, 0.7f, config->textColor(), Lang::get("REVISION"), 300);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawSpriteBlend(sprites_download_all_idx, 20, 25);
Gui::DrawString(50, 27, 0.6f, Config::TxtColor, Lang::get("DOWNLOAD_ALL"), 260);
Gui::DrawString(50, 27, 0.6f, config->textColor(), Lang::get("DOWNLOAD_ALL"), 260);
GFX::DrawSpriteBlend(sprites_view_idx, 20, 55);
Gui::DrawString(50, 57, 0.6f, Config::TxtColor, Lang::get("CHANGE_VIEW_MODE"), 260);
Gui::DrawString(50, 57, 0.6f, config->textColor(), Lang::get("CHANGE_VIEW_MODE"), 260);
GFX::DrawArrow(20, 85);
Gui::DrawString(50, 87, 0.6f, Config::TxtColor, Lang::get("ENTRY_UP"), 260);
Gui::DrawString(50, 87, 0.6f, config->textColor(), Lang::get("ENTRY_UP"), 260);
GFX::DrawArrow(42, 140, 180.0);
Gui::DrawString(50, 117, 0.6f, Config::TxtColor, Lang::get("ENTRY_DOWN"), 260);
Gui::DrawString(50, 117, 0.6f, config->textColor(), Lang::get("ENTRY_DOWN"), 260);
GFX::DrawArrow(20, 145, 0, 1);
Gui::DrawString(50, 147, 0.6f, Config::TxtColor, Lang::get("GO_BACK"), 260);
Gui::DrawString(10, 177, 0.6f, Config::TxtColor, std::to_string(Selection + 1) + " | " + std::to_string(maxScripts), 35);
Gui::DrawString(50, 177, 0.6f, Config::TxtColor, Lang::get("ENTRY"), 260);
Gui::DrawString(50, 147, 0.6f, config->textColor(), Lang::get("GO_BACK"), 260);
Gui::DrawString(10, 177, 0.6f, config->textColor(), std::to_string(Selection + 1) + " | " + std::to_string(maxScripts), 35);
Gui::DrawString(50, 177, 0.6f, config->textColor(), Lang::get("ENTRY"), 260);
GFX::DrawSpriteBlend(sprites_update_idx, 20, 195);
Gui::DrawString(50, 197, 0.6f, Config::TxtColor, Lang::get("REFRESH_SCRIPTBROWSE"), 260);
Gui::DrawString(50, 197, 0.6f, config->textColor(), Lang::get("REFRESH_SCRIPTBROWSE"), 260);
GFX::DrawArrow(0, 218, 0, 1);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
} else {
@@ -325,10 +330,10 @@ void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
refresh();
break;
case 2:
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
break;
}
@@ -343,10 +348,10 @@ void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
refresh();
dropDownMenu = false;
} else if (touching(touch, dropPos2[2])) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
dropDownMenu = false;
}
@@ -366,8 +371,9 @@ void ScriptBrowse::downloadAll() {
titleFix[l] = '-';
}
}
Msg::DisplayMsg(fileName + " " + std::to_string(current) + " / " + std::to_string(total));
downloadToFile(infoJson[i]["url"], Config::ScriptPath + titleFix + ".json");
downloadToFile(infoJson[i]["url"], config->scriptPath() + titleFix + ".json");
infoJson[i]["curRevision"] = infoJson[i]["revision"];
}
}
@@ -380,9 +386,10 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
DropDownLogic(hDown, hHeld, touch);
} else {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
if (mode == 0) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
if (Selection < (int)infoJson.size()-1) {
@@ -391,11 +398,11 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection < (int)infoJson.size()-1-3) {
Selection += 3;
} else {
@@ -409,11 +416,11 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
} else {
@@ -427,7 +434,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
@@ -441,13 +448,13 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = (int)infoJson.size()-1;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
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 (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"];
@@ -456,15 +463,16 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
titleFix[l] = '-';
}
}
Msg::DisplayMsg(fileName);
downloadToFile(infoJson[screenPos + i]["url"], Config::ScriptPath + titleFix + ".json");
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) {
} 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"];
@@ -473,8 +481,9 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
titleFix[l] = '-';
}
}
Msg::DisplayMsg(fileName);
downloadToFile(infoJson[screenPosList + i]["url"], Config::ScriptPath + titleFix + ".json");
downloadToFile(infoJson[screenPosList + i]["url"], config->scriptPath() + titleFix + ".json");
infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"];
}
}
@@ -492,20 +501,20 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
titleFix[i] = '-';
}
}
Msg::DisplayMsg(fileName);
downloadToFile(infoJson[Selection]["url"], Config::ScriptPath + titleFix + ".json");
Msg::DisplayMsg(fileName);
downloadToFile(infoJson[Selection]["url"], config->scriptPath() + titleFix + ".json");
infoJson[Selection]["curRevision"] = infoJson[Selection]["revision"];
}
}
if (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) {
} else if (config->viewMode() == 1) {
if(Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
@@ -521,7 +530,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
} else {
if (hDown & KEY_B) {
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
}
+42 -32
View File
@@ -24,7 +24,7 @@
* reasonable ways as different from the original version.
*/
#include "utils/fileBrowse.hpp"
#include "fileBrowse.hpp"
#include "keyboard.hpp"
#include "logging.hpp"
#include "scriptCreator.hpp"
@@ -32,14 +32,15 @@
#include <fstream>
#include <unistd.h>
extern std::unique_ptr<Config> config;
// The to editing script.
nlohmann::json editScript;
std::string entryName = ""; // So we can set to *that* entry.
void ScriptCreator::openJson(std::string fileName) {
std::string scriptFile = Config::ScriptPath + fileName;
std::string scriptFile = config->scriptPath() + fileName;
FILE* file = fopen(scriptFile.c_str(), "r");
if(file) editScript = nlohmann::json::parse(file, nullptr, false);
if (file) editScript = nlohmann::json::parse(file, nullptr, false);
fclose(file);
}
@@ -78,71 +79,73 @@ void ScriptCreator::Draw(void) const {
void ScriptCreator::DrawSubMenu(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("SCRIPTCREATOR"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("SCRIPTCREATOR"), 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
for (int i = 0; i < 2; i++) {
if (Selection == i) {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor);
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, config->selectedColor());
} else {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::UnselectedColor);
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, config->unselectedColor());
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "New script"))/2, mainButtons[0].y+10, 0.6f, Config::TxtColor, "New script", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "Existing script"))/2, mainButtons[1].y+10, 0.6f, Config::TxtColor, "Existing script", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "New script"))/2, mainButtons[0].y+10, 0.6f, config->textColor(), "New script", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "Existing script"))/2, mainButtons[1].y+10, 0.6f, config->textColor(), "Existing script", 140);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void ScriptCreator::DrawScriptScreen(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Selected Entry: " + entryName, 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), "Selected Entry: " + entryName, 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Selected Entry: " + entryName, 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), "Selected Entry: " + entryName, 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
// Draw Page.
for (int i = 0; i < 2; i++) {
if (i == page) {
Gui::DrawString(260, 3, 0.6f, Config::TxtColor, std::to_string(i+1) + " / 2", 140);
Gui::DrawString(260, 3, 0.6f, config->textColor(), std::to_string(i+1) + " / 2", 140);
}
}
if (page == 0) {
for (int i = 0; i < 6; i++) {
if (Selection == i) {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::SelectedColor);
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->selectedColor());
} else {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::UnselectedColor);
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->unselectedColor());
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadRelease"))/2-150+70, creatorButtons[0].y+10, 0.6f, Config::TxtColor, "downloadRelease", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadFile"))/2+150-70, creatorButtons[1].y+10, 0.6f, Config::TxtColor, "downloadFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "deleteFile"))/2-150+70, creatorButtons[2].y+10, 0.6f, Config::TxtColor, "deleteFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "extractFile"))/2+150-70, creatorButtons[3].y+10, 0.6f, Config::TxtColor, "extractFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "installCia"))/2-150+70, creatorButtons[4].y+10, 0.6f, Config::TxtColor, "installCia", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkdir"))/2+150-70, creatorButtons[5].y+10, 0.6f, Config::TxtColor, "mkdir", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadRelease"))/2-150+70, creatorButtons[0].y+10, 0.6f, config->textColor(), "downloadRelease", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadFile"))/2+150-70, creatorButtons[1].y+10, 0.6f, config->textColor(), "downloadFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "deleteFile"))/2-150+70, creatorButtons[2].y+10, 0.6f, config->textColor(), "deleteFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "extractFile"))/2+150-70, creatorButtons[3].y+10, 0.6f, config->textColor(), "extractFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "installCia"))/2-150+70, creatorButtons[4].y+10, 0.6f, config->textColor(), "installCia", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkdir"))/2+150-70, creatorButtons[5].y+10, 0.6f, config->textColor(), "mkdir", 140);
} else if (page == 1) {
for (int i = 0; i < 3; i++) {
if (Selection == i) {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::SelectedColor);
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->selectedColor());
} else {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, Config::UnselectedColor);
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->unselectedColor());
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "rmdir"))/2-150+70, creatorButtons[0].y+10, 0.6f, Config::TxtColor, "rmdir", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkfile"))/2+150-70, creatorButtons[1].y+10, 0.6f, Config::TxtColor, "mkfile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "TimeMsg"))/2-150+70, creatorButtons[2].y+10, 0.6f, Config::TxtColor, "TimeMsg", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "rmdir"))/2-150+70, creatorButtons[0].y+10, 0.6f, config->textColor(), "rmdir", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkfile"))/2+150-70, creatorButtons[1].y+10, 0.6f, config->textColor(), "mkfile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "TimeMsg"))/2-150+70, creatorButtons[2].y+10, 0.6f, config->textColor(), "TimeMsg", 140);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
}
@@ -286,14 +289,14 @@ void ScriptCreator::setInfoStuff(void) {
void ScriptCreator::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_B) {
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
if (hDown & KEY_A) {
switch(Selection) {
case 0:
jsonFileName = Config::ScriptPath;
jsonFileName = config->scriptPath();
jsonFileName += Input::getString(20, "Enter the name of the JSON file.");
if (jsonFileName != "") {
jsonFileName += ".json";
@@ -305,7 +308,7 @@ void ScriptCreator::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
break;
case 1:
std::string tempScript = selectFilePath("Select the Script file.", Config::ScriptPath, {"json"}, 2);
std::string tempScript = selectFilePath("Select the Script file.", config->scriptPath(), {"json"}, 2);
if (tempScript != "") {
jsonFileName = tempScript;
if(access(jsonFileName.c_str(), F_OK) != -1 ) {
@@ -339,27 +342,34 @@ void ScriptCreator::scriptLogic(u32 hDown, u32 hHeld, touchPosition touch) {
// Page 1.
if (page == 0) {
if (hDown & KEY_UP) {
if(Selection > 1) Selection -= 2;
if (Selection > 1) Selection -= 2;
}
if (hDown & KEY_DOWN) {
if(Selection < 4) Selection += 2;
if (Selection < 4) Selection += 2;
}
if (hDown & KEY_LEFT) {
if (Selection%2) Selection--;
}
if (hDown & KEY_RIGHT) {
if (!(Selection%2)) Selection++;
}
} else if (page == 1) {
if (hDown & KEY_UP) {
if (Selection == 2) Selection = 0;
}
if (hDown & KEY_RIGHT) {
if (Selection == 0) Selection = 1;
}
if (hDown & KEY_LEFT) {
if (Selection == 1) Selection = 0;
}
if (hDown & KEY_DOWN) {
if (Selection == 0) Selection = 2;
}
+221 -208
View File
@@ -35,6 +35,7 @@
#include <regex>
#include <unistd.h>
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern bool checkWifiStatus(void);
extern void notImplemented(void);
@@ -45,10 +46,11 @@ extern bool changesMade;
// Parse the script for the list.
ScriptInfo parseInfo(std::string fileName) {
FILE* file = fopen(fileName.c_str(), "rt");
if(!file) {
printf("File not found\n");
if (!file) {
printf("File not found.\n");
return {"", ""};
}
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
@@ -74,7 +76,7 @@ void ScriptList::checkForValidate(void) {
nlohmann::json ScriptList::openScriptFile() {
FILE* file = fopen(currentFile.c_str(), "rt");
nlohmann::json jsonFile;
if(file) jsonFile = nlohmann::json::parse(file, nullptr, false);
if (file) jsonFile = nlohmann::json::parse(file, nullptr, false);
fclose(file);
return jsonFile;
}
@@ -82,19 +84,21 @@ nlohmann::json ScriptList::openScriptFile() {
// Parse the objects from a script.
std::vector<std::string> parseObjects(std::string fileName) {
FILE* file = fopen(fileName.c_str(), "rt");
if(!file) {
printf("File not found\n");
if (!file) {
printf("File not found.\n");
return {{""}};
}
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
std::vector<std::string> objs;
for(auto it = json.begin();it != json.end(); it++) {
if(it.key() != "info") {
for(auto it = json.begin(); it != json.end(); it++) {
if (it.key() != "info") {
objs.push_back(it.key());
}
}
return objs;
}
@@ -109,7 +113,7 @@ std::string Description(nlohmann::json &json) {
// Return the color for the script.
u32 getColor(std::string colorString) {
if(colorString.length() < 7 || std::regex_search(colorString.substr(1), std::regex("[^0-9a-f]"))) { // invalid color
if (colorString.length() < 7 || std::regex_search(colorString.substr(1), std::regex("[^0-9a-f]"))) { // invalid color
return 0;
}
@@ -132,34 +136,35 @@ u32 progressBar;
void loadColors(nlohmann::json &json) {
u32 colorTemp;
colorTemp = getColor(ScriptHelper::getString(json, "info", "barColor"));
barColor = colorTemp == 0 ? Config::Color1 : colorTemp;
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgTopColor"));
bgTopColor = colorTemp == 0 ? Config::Color2 : colorTemp;
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(json, "info", "bgBottomColor"));
bgBottomColor = colorTemp == 0 ? Config::Color3 : colorTemp;
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(json, "info", "textColor"));
TextColor = colorTemp == 0 ? Config::TxtColor : colorTemp;
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(json, "info", "selectedColor"));
selected = colorTemp == 0 ? Config::SelectedColor : colorTemp;
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(json, "info", "unselectedColor"));
unselected = colorTemp == 0 ? Config::UnselectedColor : colorTemp;
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(json, "info", "progressbarColor"));
progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp;
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
}
void ScriptList::DrawSubMenu(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("SCRIPTS_SUBMENU"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTS_SUBMENU"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("SCRIPTS_SUBMENU"), 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
@@ -168,6 +173,7 @@ void ScriptList::DrawSubMenu(void) const {
GFX::DrawButton(subPos[1].x, subPos[1].y, Lang::get("GET_SCRIPTS"));
GFX::DrawButton(subPos[2].x, subPos[2].y, Lang::get("SCRIPTCREATOR"));
GFX::DrawButton(subPos[3].x, subPos[3].y, Lang::get("CHANGE_SCRIPTPATH"));
// Selector.
Animation::Button(subPos[Selection].x, subPos[Selection].y, .060);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
@@ -180,6 +186,7 @@ void ScriptList::loadDesc(void) {
lines.push_back(Desc.substr(0, Desc.find('\n')));
Desc = Desc.substr(Desc.find('\n')+1);
}
lines.push_back(Desc.substr(0, Desc.find('\n')));
}
@@ -190,15 +197,15 @@ bool changeBackHandle = false;
ScriptList::ScriptList() {
if (AutobootWhat == 2) {
// If Script isn't found, go to MainMenu.
if (access(Config::AutobootFile.c_str(), F_OK) != 0) {
if (access(config->autobootFile().c_str(), F_OK) != 0) {
AutobootWhat = 0;
changeBackHandle = true;
Gui::setScreen(std::make_unique<MainMenu>(), Config::fading, true);
Gui::setScreen(std::make_unique<MainMenu>(), config->screenFade(), true);
}
if (ScriptHelper::checkIfValid(Config::AutobootFile) == true) {
ScriptInfo fI = parseInfo(Config::AutobootFile);
currentFile = Config::AutobootFile;
if (ScriptHelper::checkIfValid(config->autobootFile()) == true) {
ScriptInfo fI = parseInfo(config->autobootFile());
currentFile = config->autobootFile();
selectedTitle = fI.title;
jsonFile = openScriptFile();
Desc = Description(jsonFile);
@@ -214,7 +221,7 @@ ScriptList::ScriptList() {
} else {
AutobootWhat = 0;
changeBackHandle = true;
Gui::setScreen(std::make_unique<MainMenu>(), Config::fading, true);
Gui::setScreen(std::make_unique<MainMenu>(), config->screenFade(), true);
}
}
}
@@ -224,16 +231,17 @@ void ScriptList::DrawList(void) const {
std::string line2;
std::string scriptAmount = std::to_string(Selection +1) + " | " + std::to_string(fileInfo.size());
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 239-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, Config::TxtColor, scriptAmount);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 239-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, config->textColor(), scriptAmount);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 237-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, Config::TxtColor, scriptAmount);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, scriptAmount), 237-Gui::GetStringHeight(0.6f, scriptAmount), 0.6f, config->textColor(), scriptAmount);
}
Gui::DrawStringCentered(0, 80, 0.7f, Config::TxtColor, Lang::get("TITLE") + std::string(fileInfo[Selection].title), 400);
Gui::DrawStringCentered(0, 100, 0.7f, Config::TxtColor, Lang::get("AUTHOR") + std::string(fileInfo[Selection].author), 400);
Gui::DrawStringCentered(0, 120, 0.6f, Config::TxtColor, std::string(fileInfo[Selection].shortDesc), 400);
Gui::DrawStringCentered(0, 80, 0.7f, config->textColor(), Lang::get("TITLE") + std::string(fileInfo[Selection].title), 400);
Gui::DrawStringCentered(0, 100, 0.7f, config->textColor(), Lang::get("AUTHOR") + std::string(fileInfo[Selection].author), 400);
Gui::DrawStringCentered(0, 120, 0.6f, config->textColor(), std::string(fileInfo[Selection].shortDesc), 400);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(295, -1);
@@ -241,49 +249,49 @@ void ScriptList::DrawList(void) const {
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)fileInfo.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)fileInfo.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = fileInfo[screenPos + i].title;
line2 = fileInfo[screenPos + i].author;
if(screenPos + i == Selection) {
if (screenPos + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, line2, 320);
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)fileInfo.size();i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, Config::UnselectedColor);
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)fileInfo.size();i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, config->unselectedColor());
line1 = fileInfo[screenPosList + i].title;
if(screenPosList + i == Selection) {
if (screenPosList + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
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);
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, config->textColor(), line1, 320);
}
}
// DropDown Menu.
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 87, Config::Color1);
Gui::Draw_Rect(0, 25, 140, 87, config->barColor());
for (int i = 0; i < 2; i++) {
if (dropSelection == i) {
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, config->selectedColor());
} else {
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, Config::UnselectedColor);
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, config->unselectedColor());
}
}
// Draw Dropdown Icons.
GFX::DrawSpriteBlend(sprites_delete_idx, dropPos[0].x, dropPos[0].y);
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[1].x, dropPos[1].y);
// Dropdown Text.
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, Config::TxtColor, Lang::get("DELETE_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, Config::TxtColor, Lang::get("VIEW_DDM"), 100);
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, config->textColor(), Lang::get("DELETE_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, config->textColor(), 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
}
@@ -304,16 +312,19 @@ void ScriptList::DrawSingleObject(void) const {
std::string info;
std::string entryAmount = std::to_string(Selection+1) + " | " + std::to_string(fileInfo2.size());
GFX::DrawTop();
if (Config::UseBars == true) {
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, TextColor, selectedTitle, 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 239-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, Config::TxtColor, entryAmount);
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, selectedTitle, 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 237-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, Config::TxtColor, entryAmount);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 237-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, TextColor, entryAmount);
}
for(uint i=0;i<lines.size();i++) {
for(uint i = 0; i < lines.size(); i++) {
Gui::DrawStringCentered(0, 120-((lines.size()*20)/2)+i*20, 0.6f, TextColor, lines[i], 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(295, -1);
@@ -321,11 +332,11 @@ void ScriptList::DrawSingleObject(void) const {
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)fileInfo2.size();i++) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)fileInfo2.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, unselected);
info = fileInfo2[screenPos + i];
if(screenPos + i == Selection) {
if (screenPos + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, selected);
}
@@ -333,11 +344,11 @@ void ScriptList::DrawSingleObject(void) const {
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)fileInfo2.size();i++) {
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)fileInfo2.size(); i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
info = fileInfo2[screenPosList + i];
if(screenPosList + i == Selection) {
if (screenPosList + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, selected);
}
@@ -350,25 +361,27 @@ void ScriptList::DrawSingleObject(void) const {
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 44, barColor);
Gui::drawAnimatedSelector(dropPos2[0].x, dropPos2[0].y, dropPos2[0].w, dropPos2[0].h, .090, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(dropPos2[0].x, dropPos2[0].y, dropPos2[0].w, dropPos2[0].h, .090, TRANSPARENT, selected);
// 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);
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, TextColor, 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 ScriptList::refreshList() {
if (returnIfExist(Config::ScriptPath, {"json"}) == true) {
if (returnIfExist(config->scriptPath(), {"json"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
fileInfo.clear();
chdir(Config::ScriptPath.c_str());
chdir(config->scriptPath().c_str());
getDirectoryContents(dirContents, {"json"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
fileInfo.push_back(parseInfo(dirContents[i].name));
}
Selection = 0;
mode = 1;
} else {
@@ -381,18 +394,18 @@ void ScriptList::refreshList() {
void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
if (changeBackHandle) {
Gui::setScreen(std::make_unique<MainMenu>(), Config::fading, true);
Gui::setScreen(std::make_unique<MainMenu>(), config->screenFade(), true);
} else {
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
}
// Navigation.
if(hDown & KEY_UP) {
if(Selection > 1) Selection -= 2;
} else if(hDown & KEY_DOWN) {
if(Selection < 3 && Selection != 2 && Selection != 3) Selection += 2;
if (hDown & KEY_UP) {
if (Selection > 1) Selection -= 2;
} else if (hDown & KEY_DOWN) {
if (Selection < 3 && Selection != 2 && Selection != 3) Selection += 2;
} else if (hDown & KEY_LEFT) {
if (Selection%2) Selection--;
} else if (hDown & KEY_RIGHT) {
@@ -402,10 +415,10 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_A) {
switch(Selection) {
case 0:
if (returnIfExist(Config::ScriptPath, {"json"}) == true) {
if (returnIfExist(config->scriptPath(), {"json"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
chdir(Config::ScriptPath.c_str());
chdir(config->scriptPath().c_str());
getDirectoryContents(dirContents, {"json"});
for(uint i=0;i<dirContents.size();i++) {
fileInfo.push_back(parseInfo(dirContents[i].name));
@@ -417,22 +430,22 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
break;
case 1:
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<ScriptBrowse>(), Config::fading, true);
Gui::setScreen(std::make_unique<ScriptBrowse>(), config->screenFade(), true);
} else {
notConnectedMsg();
}
break;
case 2:
if (isTesting == true) {
Gui::setScreen(std::make_unique<ScriptCreator>(), Config::fading, true);
Gui::setScreen(std::make_unique<ScriptCreator>(), config->screenFade(), true);
} else {
notImplemented();
}
break;
case 3:
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), Config::ScriptPath, {});
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), config->scriptPath(), {});
if (tempScript != "") {
Config::ScriptPath = tempScript;
config->scriptPath(tempScript);
changesMade = true;
}
break;
@@ -441,12 +454,12 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (touching(touch, subPos[0])) {
if (returnIfExist(Config::ScriptPath, {"json"}) == true) {
if (returnIfExist(config->scriptPath(), {"json"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
chdir(Config::ScriptPath.c_str());
chdir(config->scriptPath().c_str());
getDirectoryContents(dirContents, {"json"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
fileInfo.push_back(parseInfo(dirContents[i].name));
}
mode = 1;
@@ -455,20 +468,20 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
} else if (touching(touch, subPos[1])) {
if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<ScriptBrowse>(), Config::fading, true);
Gui::setScreen(std::make_unique<ScriptBrowse>(), config->screenFade(), true);
} else {
notConnectedMsg();
}
} else if (touching(touch, subPos[2])) {
if (isTesting == true) {
Gui::setScreen(std::make_unique<ScriptCreator>(), Config::fading, true);
Gui::setScreen(std::make_unique<ScriptCreator>(), config->screenFade(), true);
} else {
notImplemented();
}
} else if (touching(touch, subPos[3])) {
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), Config::ScriptPath, {});
std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), config->scriptPath(), {});
if (tempScript != "") {
Config::ScriptPath = tempScript;
config->scriptPath(tempScript);
changesMade = true;
}
}
@@ -476,7 +489,7 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
void ScriptList::deleteScript(int selectedScript) {
std::string path = Config::ScriptPath;
std::string path = config->scriptPath();
path += dirContents[selectedScript].name;
deleteFile(path.c_str());
// Refresh the list.
@@ -484,11 +497,12 @@ void ScriptList::deleteScript(int selectedScript) {
Selection = 0;
dirContents.clear();
fileInfo.clear();
chdir(Config::ScriptPath.c_str());
chdir(config->scriptPath().c_str());
getDirectoryContents(dirContents, {"json"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
fileInfo.push_back(parseInfo(dirContents[i].name));
}
if (dirContents.size() == 0) {
dirContents.clear();
fileInfo.clear();
@@ -518,10 +532,10 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
break;
case 1:
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
break;
}
@@ -535,10 +549,10 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
dropDownMenu = false;
} else if (touching(touch, dropPos2[1])) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
dropDownMenu = false;
}
@@ -556,10 +570,10 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_START) {
if (Config::autoboot == 2) {
if (config->autoboot() == 2) {
if (Msg::promptMsg(Lang::get("DISABLE_AUTOBOOT"))) {
Config::autoboot = 0;
Config::AutobootFile = "";
config->autoboot(0);
config->autobootFile("");
changesMade = true;
}
} else {
@@ -567,8 +581,8 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
} else if (fileInfo.size() != 0) {
if (ScriptHelper::checkIfValid(dirContents[Selection].name) == true) {
if (Msg::promptMsg(Lang::get("AUTOBOOT_SCRIPT"))) {
Config::AutobootFile = Config::ScriptPath + dirContents[Selection].name;
Config::autoboot = 2;
config->autobootFile(config->scriptPath() + dirContents[Selection].name);
config->autoboot(2);
changesMade = true;
}
}
@@ -583,7 +597,7 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
@@ -593,11 +607,11 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = (int)fileInfo.size()-1;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection < (int)fileInfo.size()-1-3) {
Selection += 3;
} else {
@@ -611,11 +625,11 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
} else {
@@ -629,15 +643,14 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo.size(); i++) {
if(touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (dirContents[screenPos + i].isDirectory) {
} else if (fileInfo.size() != 0) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)fileInfo.size(); i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (!dirContents[screenPos + i].isDirectory && fileInfo.size() != 0) {
if (ScriptHelper::checkIfValid(dirContents[screenPos + i].name) == true) {
currentFile = dirContents[screenPos + i].name;
selectedTitle = fileInfo[screenPos + i].title;
@@ -654,11 +667,10 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)fileInfo.size(); i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (dirContents[screenPosList + i].isDirectory) {
} else if (fileInfo.size() != 0) {
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)fileInfo.size(); i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (!dirContents[screenPosList + i].isDirectory && fileInfo.size() != 0) {
if (ScriptHelper::checkIfValid(dirContents[screenPosList + i].name) == true) {
currentFile = dirContents[screenPosList + i].name;
selectedTitle = fileInfo[screenPosList + i].title;
@@ -697,14 +709,14 @@ void ScriptList::ListSelection(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
if (Config::viewMode == 0) {
if(Selection < screenPos) {
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) {
} else if (config->viewMode() == 1) {
if (Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = Selection - ENTRIES_PER_LIST + 1;
@@ -723,20 +735,20 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_A) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
dropDownMenu = false;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, dropPos2[0])) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
dropDownMenu = false;
}
@@ -761,7 +773,7 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
@@ -771,12 +783,12 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = (int)fileInfo2.size()-1;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection < (int)fileInfo2.size()-1-3) {
Selection += 3;
} else {
@@ -790,11 +802,11 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
} else {
@@ -808,13 +820,13 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo2.size(); i++) {
if(touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)fileInfo2.size(); i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (fileInfo2.size() != 0) {
choice = fileInfo2[screenPos + i];
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n\n" + choice)) {
@@ -823,9 +835,9 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)fileInfo2.size(); i++) {
if(touch.py > (i+1)*27 && touch.py < (i+2)*27) {
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)fileInfo2.size(); i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (fileInfo2.size() != 0) {
choice = fileInfo2[screenPosList + i];
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n\n" + choice)) {
@@ -847,23 +859,23 @@ void ScriptList::SelectFunction(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_SELECT) {
Config::Color1 = barColor;
Config::Color2 = bgTopColor;
Config::Color3 = bgBottomColor;
Config::TxtColor = TextColor;
Config::SelectedColor = selected;
Config::UnselectedColor = unselected;
config->barColor(barColor);
config->topBG(bgTopColor);
config->bottomBG(bgBottomColor);
config->textColor(TextColor);
config->selectedColor(selected);
config->unselectedColor(unselected);
changesMade = true;
}
if (Config::viewMode == 0) {
if(Selection < screenPos) {
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) {
} else if (config->viewMode() == 1) {
if (Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = Selection - ENTRIES_PER_LIST + 1;
@@ -896,121 +908,122 @@ void ScriptList::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
void ScriptList::DrawGlossary(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("GLOSSARY"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GLOSSARY"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("GLOSSARY"), 400);
}
if (lastMode == 1) {
Gui::DrawString(15, 35, 0.7f, Config::TxtColor, std::to_string(Selection +1) + " | " + std::to_string(fileInfo.size()), 40);
Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("ENTRY"), 300);
Gui::DrawString(15, 35, 0.7f, config->textColor(), std::to_string(Selection +1) + " | " + std::to_string(fileInfo.size()), 40);
Gui::DrawString(65, 35, 0.7f, config->textColor(), Lang::get("ENTRY"), 300);
} else if (lastMode == 2) {
Gui::DrawString(15, 35, 0.7f, Config::TxtColor, std::to_string(Selection+1) + " | " + std::to_string(fileInfo2.size()), 40);
Gui::DrawString(65, 35, 0.7f, Config::TxtColor, Lang::get("ENTRY"), 300);
Gui::DrawString(15, 35, 0.7f, config->textColor(), std::to_string(Selection+1) + " | " + std::to_string(fileInfo2.size()), 40);
Gui::DrawString(65, 35, 0.7f, config->textColor(), 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);
Gui::DrawString(50, 42, 0.6f, config->textColor(), Lang::get("CHANGE_VIEW_MODE"), 260);
GFX::DrawArrow(20, 70);
Gui::DrawString(50, 72, 0.6f, Config::TxtColor, Lang::get("ENTRY_UP"), 260);
Gui::DrawString(50, 72, 0.6f, config->textColor(), Lang::get("ENTRY_UP"), 260);
GFX::DrawArrow(42, 125, 180.0);
Gui::DrawString(50, 102, 0.6f, Config::TxtColor, Lang::get("ENTRY_DOWN"), 260);
Gui::DrawString(50, 102, 0.6f, config->textColor(), Lang::get("ENTRY_DOWN"), 260);
GFX::DrawArrow(20, 130, 0, 1);
Gui::DrawString(50, 132, 0.6f, Config::TxtColor, Lang::get("GO_BACK"), 260);
Gui::DrawString(50, 132, 0.6f, config->textColor(), Lang::get("GO_BACK"), 260);
if (lastMode == 1) {
GFX::DrawSpriteBlend(sprites_delete_idx, 20, 160);
Gui::DrawString(50, 162, 0.6f, Config::TxtColor, Lang::get("DELETE_SCRIPT2"), 260);
Gui::DrawString(50, 162, 0.6f, config->textColor(), Lang::get("DELETE_SCRIPT2"), 260);
}
GFX::DrawArrow(0, 218, 0, 1);
}
// Execute | run the script.
Result ScriptList::runFunctions(nlohmann::json &json) {
Result ret = NONE; // No Error as of yet.
for(int i=0;i<(int)json.at(choice).size();i++) {
for(int i = 0; i < (int)json.at(choice).size(); i++) {
if (ret == NONE) {
std::string type = json.at(choice).at(i).at("type");
if(type == "deleteFile") {
if (type == "deleteFile") {
bool missing = false;
std::string file, message;
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
if (json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
else missing = true;
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if(!missing) ret = ScriptHelper::removeFile(file, message);
if (json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if (!missing) ret = ScriptHelper::removeFile(file, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadFile") {
} else if (type == "downloadFile") {
bool missing = false;
std::string file, output, message;
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
if (json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
else missing = true;
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
if (json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
else missing = true;
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if(!missing) ret = ScriptHelper::downloadFile(file, output, message);
if (json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if (!missing) ret = ScriptHelper::downloadFile(file, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "downloadRelease") {
} else if (type == "downloadRelease") {
bool missing = false, includePrereleases = false, showVersions = false;
std::string repo, file, output, message;
if(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
if (json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
else missing = true;
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
if (json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
else missing = true;
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
if (json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
else missing = true;
if(json.at(choice).at(i).contains("includePrereleases") && json.at(choice).at(i).at("includePrereleases").is_boolean())
if (json.at(choice).at(i).contains("includePrereleases") && json.at(choice).at(i).at("includePrereleases").is_boolean())
includePrereleases = json.at(choice).at(i).at("includePrereleases");
if(json.at(choice).at(i).contains("showVersions") && json.at(choice).at(i).at("showVersions").is_boolean())
if (json.at(choice).at(i).contains("showVersions") && json.at(choice).at(i).at("showVersions").is_boolean())
showVersions = json.at(choice).at(i).at("showVersions");
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if(!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
if (json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if (!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
} else if(type == "extractFile") {
} else if (type == "extractFile") {
bool missing = false;
std::string file, input, output, message;
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
if (json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
else missing = true;
if(json.at(choice).at(i).contains("input")) input = json.at(choice).at(i).at("input");
if (json.at(choice).at(i).contains("input")) input = json.at(choice).at(i).at("input");
else missing = true;
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
if (json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
else missing = true;
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if(!missing) ScriptHelper::extractFile(file, input, output, message);
if (json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if (!missing) ScriptHelper::extractFile(file, input, output, message);
else ret = SYNTAX_ERROR;
} else if(type == "installCia") {
} else if (type == "installCia") {
bool missing = false, updateSelf = false;
std::string file, message;
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
if (json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
else missing = true;
if(json.at(choice).at(i).contains("updateSelf") && json.at(choice).at(i).at("updateSelf").is_boolean()) {
if (json.at(choice).at(i).contains("updateSelf") && json.at(choice).at(i).at("updateSelf").is_boolean()) {
updateSelf = json.at(choice).at(i).at("updateSelf");
}
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if(!missing) ScriptHelper::installFile(file, updateSelf, message);
if (json.at(choice).at(i).contains("message")) message = json.at(choice).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(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
if (json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
else missing = true;
if(!missing) makeDirs(directory.c_str());
if (!missing) makeDirs(directory.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "rmdir") {
bool missing = false;
std::string directory, message, promptmsg;
if(json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
if (json.at(choice).at(i).contains("directory")) directory = json.at(choice).at(i).at("directory");
else missing = true;
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
if(!missing) {
if(access(directory.c_str(), F_OK) != 0 ) {
if (!missing) {
if (access(directory.c_str(), F_OK) != 0 ) {
ret = DELETE_ERROR;
} else {
if (Msg::promptMsg(promptmsg)) {
@@ -1023,63 +1036,63 @@ Result ScriptList::runFunctions(nlohmann::json &json) {
} else if (type == "mkfile") {
bool missing = false;
std::string file;
if(json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
if (json.at(choice).at(i).contains("file")) file = json.at(choice).at(i).at("file");
else missing = true;
if(!missing) ScriptHelper::createFile(file.c_str());
if (!missing) ScriptHelper::createFile(file.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "timeMsg") {
bool missing = false;
std::string message;
int seconds;
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if (json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
else missing = true;
if(json.at(choice).at(i).contains("seconds") && json.at(choice).at(i).at("seconds").is_number())
if (json.at(choice).at(i).contains("seconds") && json.at(choice).at(i).at("seconds").is_number())
seconds = json.at(choice).at(i).at("seconds");
else missing = true;
if(!missing) ScriptHelper::displayTimeMsg(message, seconds);
if (!missing) ScriptHelper::displayTimeMsg(message, seconds);
else ret = SYNTAX_ERROR;
} else if (type == "saveConfig") {
Config::save();
config->save();
} else if (type == "bootTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if(json.at(choice).at(i).contains("TitleID")) TitleID = json.at(choice).at(i).at("TitleID");
if (json.at(choice).at(i).contains("TitleID")) TitleID = json.at(choice).at(i).at("TitleID");
else missing = true;
if (json.at(choice).at(i).contains("NAND") && json.at(choice).at(i).at("NAND").is_boolean()) isNAND = json.at(choice).at(i).at("NAND");
else missing = true;
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
if (json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
else missing = true;
if(!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
if (!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
else ret = SYNTAX_ERROR;
} else if (type == "promptMessage") {
std::string Message = "";
if(json.at(choice).at(i).contains("message")) Message = json.at(choice).at(i).at("message");
if (json.at(choice).at(i).contains("message")) Message = json.at(choice).at(i).at("message");
ret = ScriptHelper::prompt(Message);
} else if (type == "copy") {
std::string Message = "", source = "", destination = "";
bool missing = false;
if(json.at(choice).at(i).contains("source")) source = json.at(choice).at(i).at("source");
if (json.at(choice).at(i).contains("source")) source = json.at(choice).at(i).at("source");
else missing = true;
if(json.at(choice).at(i).contains("destination")) destination = json.at(choice).at(i).at("destination");
if (json.at(choice).at(i).contains("destination")) destination = json.at(choice).at(i).at("destination");
else missing = true;
if(json.at(choice).at(i).contains("message")) Message = json.at(choice).at(i).at("message");
if (json.at(choice).at(i).contains("message")) Message = json.at(choice).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(json.at(choice).at(i).contains("old")) oldFile = json.at(choice).at(i).at("old");
if (json.at(choice).at(i).contains("old")) oldFile = json.at(choice).at(i).at("old");
else missing = true;
if(json.at(choice).at(i).contains("new")) newFile = json.at(choice).at(i).at("new");
if (json.at(choice).at(i).contains("new")) newFile = json.at(choice).at(i).at("new");
else missing = true;
if(json.at(choice).at(i).contains("message")) Message = json.at(choice).at(i).at("message");
if (json.at(choice).at(i).contains("message")) Message = json.at(choice).at(i).at("message");
if (!missing) ret = ScriptHelper::renameFile(oldFile, newFile, Message);
else ret = SYNTAX_ERROR;
}
+141 -137
View File
@@ -29,13 +29,12 @@
#include "settings.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern std::unique_ptr<Config> config;
int selectedLang;
extern bool changesMade;
Settings::Settings() {
selectedLang = 0;
}
Settings::Settings() { selectedLang = 0; }
void Settings::Draw(void) const {
if (mode == 0) {
@@ -52,11 +51,12 @@ void Settings::Draw(void) const {
void Settings::DrawSubMenu(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), "Universal-Updater", 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), "Universal-Updater", 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
@@ -88,21 +88,23 @@ const std::vector<std::string> languages = {
void Settings::DrawLanguageSelection(void) const {
std::string line1;
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("SELECT_LANG"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("SELECT_LANG"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SELECT_LANG"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("SELECT_LANG"), 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)languages.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)languages.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = languages[screenPos + i];
if (screenPos + i == selectedLang) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, WHITE, line1, 320);
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), line1, 320);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
@@ -126,32 +128,32 @@ const std::vector<std::string> colorList = {
void Settings::DrawColorChanging(void) const {
std::string line1;
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), "Universal-Updater", 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), "Universal-Updater", 400);
}
if (!dropDownMenu) {
if (colorMode == 3) {
Gui::Draw_Rect(0, 40, 400, 45, Config::SelectedColor);
Gui::DrawStringCentered(0, 45, 0.7f, Config::TxtColor, Lang::get("TEXT_COLOR"), 320);
Gui::Draw_Rect(0, 40, 400, 45, config->selectedColor());
Gui::DrawStringCentered(0, 45, 0.7f, config->textColor(), Lang::get("TEXT_COLOR"), 320);
} else if (colorMode == 4) {
Gui::Draw_Rect(0, 40, 400, 45, Config::SelectedColor);
Gui::DrawStringCentered(0, 45, 0.7f, Config::TxtColor, Lang::get("SELECTED_COLOR"), 320);
Gui::Draw_Rect(0, 40, 400, 45, config->selectedColor());
Gui::DrawStringCentered(0, 45, 0.7f, config->textColor(), Lang::get("SELECTED_COLOR"), 320);
} else if (colorMode == 5) {
Gui::Draw_Rect(0, 40, 400, 45, Config::UnselectedColor);
Gui::DrawStringCentered(0, 45, 0.7f, Config::TxtColor, Lang::get("UNSELECTED_COLOR"), 320);
Gui::Draw_Rect(0, 40, 400, 45, config->unselectedColor());
Gui::DrawStringCentered(0, 45, 0.7f, config->textColor(), Lang::get("UNSELECTED_COLOR"), 320);
} else if (colorMode == 6) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, Config::progressbarColor);
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->progressbarColor());
} else if (colorMode == 7) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, Config::notFound);
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->notfoundColor());
} else if (colorMode == 8) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, Config::outdated);
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->outdatedColor());
} else if (colorMode == 9) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, Config::uptodate);
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->uptodateColor());
} else if (colorMode == 10) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, Config::future);
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->futureColor());
} else if (colorMode == 11) {
GFX::DrawButton(100, 100, "");
}
@@ -167,63 +169,63 @@ void Settings::DrawColorChanging(void) const {
}
if (dropDownMenu) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)colorList.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)colorList.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = Lang::get(colorList[screenPos + i]);
if(screenPos + i == colorSelection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
if (screenPos + i == colorSelection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, Config::TxtColor, line1, 320);
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), line1, 320);
}
} else {
if (colorMode == 0) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::Color1, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::Color1, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::Color1, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->barColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->barColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->barColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 1) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::Color2, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::Color2, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::Color2, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->topBG(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->topBG(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->topBG(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 2) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::Color3, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::Color3, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::Color3, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->bottomBG(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->bottomBG(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->bottomBG(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 3) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::TxtColor, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::TxtColor, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::TxtColor, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->textColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->textColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->textColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 4) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::SelectedColor, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::SelectedColor, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::SelectedColor, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->selectedColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->selectedColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->selectedColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 5) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::UnselectedColor, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::UnselectedColor, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::UnselectedColor, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->unselectedColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->unselectedColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->unselectedColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 6) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::progressbarColor, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::progressbarColor, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::progressbarColor, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->progressbarColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->progressbarColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->progressbarColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 7) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::notFound, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::notFound, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::notFound, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->notfoundColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->notfoundColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->notfoundColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 8) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::outdated, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::outdated, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::outdated, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->outdatedColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->outdatedColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->outdatedColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 9) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::uptodate, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::uptodate, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::uptodate, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->uptodateColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->uptodateColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->uptodateColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 10) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::future, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::future, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::future, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->futureColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->futureColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->futureColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 11) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(Config::Button, 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(Config::Button, 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(Config::Button, 0).c_str(), C2D_Color32(0, 0, 255, 255));
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->buttonColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->buttonColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->buttonColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
}
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
@@ -231,11 +233,12 @@ void Settings::DrawColorChanging(void) const {
void Settings::DrawMiscSettings(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, "Universal-Updater", 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), "Universal-Updater", 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "Universal-Updater", 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), "Universal-Updater", 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
@@ -255,26 +258,26 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (Selection == 0) {
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2);
if (tempMusic != "") {
Config::MusicPath = tempMusic;
config->musicPath(tempMusic);
changesMade = true;
}
} else if (Selection == 1) {
if (Config::UseBars == true) Config::UseBars = false;
else if (Config::UseBars == false) Config::UseBars = true;
if (config->useBars() == true) config->useBars(false);
else if (config->useBars() == false) config->useBars(true);
changesMade = true;
} else if (Selection == 2) {
Config::keyDelay = Input::getUint(255, Lang::get("ENTER_KEY_DELAY"));
config->keyDelay(Input::getUint(255, Lang::get("ENTER_KEY_DELAY")));
changesMade = true;
} else if (Selection == 3) {
if (Config::fading) {
if (config->screenFade()) {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) {
Config::fading = false;
config->screenFade(false);
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
changesMade = true;
}
} else {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) {
Config::fading = true;
config->screenFade(true);
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
changesMade = true;
}
@@ -286,26 +289,26 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (touching(touch, mainButtons2[0])) {
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2);
if (tempMusic != "") {
Config::MusicPath = tempMusic;
config->musicPath(tempMusic);
changesMade = true;
}
} else if (touching(touch, mainButtons2[1])) {
if (Config::UseBars == true) Config::UseBars = false;
else if (Config::UseBars == false) Config::UseBars = true;
if (config->useBars() == true) config->useBars(false);
else if (config->useBars() == false) config->useBars(true);
changesMade = true;
} else if (touching(touch, mainButtons2[2])) {
Config::keyDelay = Input::getUint(255, Lang::get("ENTER_KEY_DELAY"));
config->keyDelay(Input::getUint(255, Lang::get("ENTER_KEY_DELAY")));
changesMade = true;
} else if (touching(touch, mainButtons2[3])) {
if (Config::fading) {
if (config->screenFade()) {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) {
Config::fading = false;
config->screenFade(false);
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
changesMade = true;
}
} else {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) {
Config::fading = true;
config->screenFade(true);
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
changesMade = true;
}
@@ -320,15 +323,15 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) {
// No idea where to place the button for it, so do it here for now.
if (hDown & KEY_SELECT) {
if (Config::progress) {
if (config->progressDisplay()) {
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) {
Config::progress = false;
config->progressDisplay(false);
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
changesMade = true;
}
} else {
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) {
Config::progress = true;
config->progressDisplay(true);
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
changesMade = true;
}
@@ -350,11 +353,11 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) {
void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_UP) {
if(Selection > 0) Selection--;
if (Selection > 0) Selection--;
}
if (hDown & KEY_DOWN) {
if(Selection < 2) Selection++;
if (Selection < 2) Selection++;
}
if (hDown & KEY_A) {
@@ -369,7 +372,7 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
mode = 2;
break;
case 2:
Gui::setScreen(std::make_unique<Credits>(), Config::fading, true);
Gui::setScreen(std::make_unique<Credits>(), config->screenFade(), true);
break;
}
}
@@ -383,12 +386,12 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
screenPos = 0;
mode = 2;
} else if (touching(touch, mainButtons[2])) {
Gui::setScreen(std::make_unique<Credits>(), Config::fading, true);
Gui::setScreen(std::make_unique<Credits>(), config->screenFade(), true);
}
}
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
@@ -409,7 +412,7 @@ void Settings::LanguageSelection(u32 hDown, u32 hHeld, touchPosition touch) {
selectedLang = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
@@ -419,12 +422,12 @@ void Settings::LanguageSelection(u32 hDown, u32 hHeld, touchPosition touch) {
selectedLang = (int)languages.size()-1;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if (hDown & KEY_A) {
Config::lang = langsTemp[selectedLang];
Lang::load(Config::lang);
config->language(langsTemp[selectedLang]);
Lang::load(config->language());
changesMade = true;
mode = 0;
}
@@ -432,6 +435,7 @@ void Settings::LanguageSelection(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B)) {
mode = 0;
}
if (selectedLang < screenPos) {
screenPos = selectedLang;
} else if (selectedLang > screenPos + ENTRIES_PER_SCREEN - 1) {
@@ -459,7 +463,7 @@ void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
colorSelection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
@@ -469,7 +473,7 @@ void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
colorSelection = (int)colorList.size()-1;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
} else {
@@ -484,11 +488,11 @@ void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
}
if ((hDown & KEY_L || hDown & KEY_LEFT)) {
if(colorMode > 0) colorMode--;
if (colorMode > 0) colorMode--;
}
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
if(colorMode < 11) colorMode++;
if (colorMode < 11) colorMode++;
}
if (hDown & KEY_TOUCH) {
@@ -497,29 +501,29 @@ void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
if(temp != -1) {
red = temp;
if (colorMode == 0) {
Config::Color1 = RGBA8(red, ColorHelper::getColorValue(Config::Color1, 1), ColorHelper::getColorValue(Config::Color1, 0), 255);
config->barColor(RGBA8(red, ColorHelper::getColorValue(config->barColor(), 1), ColorHelper::getColorValue(config->barColor(), 0), 255));
} else if (colorMode == 1) {
Config::Color2 = RGBA8(red, ColorHelper::getColorValue(Config::Color2, 1), ColorHelper::getColorValue(Config::Color2, 0), 255);
config->topBG(RGBA8(red, ColorHelper::getColorValue(config->topBG(), 1), ColorHelper::getColorValue(config->topBG(), 0), 255));
} else if (colorMode == 2) {
Config::Color3 = RGBA8(red, ColorHelper::getColorValue(Config::Color3, 1), ColorHelper::getColorValue(Config::Color3, 0), 255);
config->bottomBG(RGBA8(red, ColorHelper::getColorValue(config->bottomBG(), 1), ColorHelper::getColorValue(config->bottomBG(), 0), 255));
} else if (colorMode == 3) {
Config::TxtColor = RGBA8(red, ColorHelper::getColorValue(Config::TxtColor, 1), ColorHelper::getColorValue(Config::TxtColor, 0), 255);
config->textColor(RGBA8(red, ColorHelper::getColorValue(config->textColor(), 1), ColorHelper::getColorValue(config->textColor(), 0), 255));
} else if (colorMode == 4) {
Config::SelectedColor = RGBA8(red, ColorHelper::getColorValue(Config::SelectedColor, 1), ColorHelper::getColorValue(Config::SelectedColor, 0), 255);
config->selectedColor(RGBA8(red, ColorHelper::getColorValue(config->selectedColor(), 1), ColorHelper::getColorValue(config->selectedColor(), 0), 255));
} else if (colorMode == 5) {
Config::UnselectedColor = RGBA8(red, ColorHelper::getColorValue(Config::UnselectedColor, 1), ColorHelper::getColorValue(Config::UnselectedColor, 0), 255);
config->unselectedColor(RGBA8(red, ColorHelper::getColorValue(config->unselectedColor(), 1), ColorHelper::getColorValue(config->unselectedColor(), 0), 255));
} else if (colorMode == 6) {
Config::progressbarColor = RGBA8(red, ColorHelper::getColorValue(Config::progressbarColor, 1), ColorHelper::getColorValue(Config::progressbarColor, 0), 255);
config->progressbarColor(RGBA8(red, ColorHelper::getColorValue(config->progressbarColor(), 1), ColorHelper::getColorValue(config->progressbarColor(), 0), 255));
} else if (colorMode == 7) {
Config::notFound = RGBA8(red, ColorHelper::getColorValue(Config::notFound, 1), ColorHelper::getColorValue(Config::notFound, 0), 255);
config->notfoundColor(RGBA8(red, ColorHelper::getColorValue(config->notfoundColor(), 1), ColorHelper::getColorValue(config->notfoundColor(), 0), 255));
} else if (colorMode == 8) {
Config::outdated = RGBA8(red, ColorHelper::getColorValue(Config::outdated, 1), ColorHelper::getColorValue(Config::outdated, 0), 255);
config->outdatedColor(RGBA8(red, ColorHelper::getColorValue(config->outdatedColor(), 1), ColorHelper::getColorValue(config->outdatedColor(), 0), 255));
} else if (colorMode == 9) {
Config::uptodate = RGBA8(red, ColorHelper::getColorValue(Config::uptodate, 1), ColorHelper::getColorValue(Config::uptodate, 0), 255);
config->uptodateColor(RGBA8(red, ColorHelper::getColorValue(config->uptodateColor(), 1), ColorHelper::getColorValue(config->uptodateColor(), 0), 255));
} else if (colorMode == 10) {
Config::future = RGBA8(red, ColorHelper::getColorValue(Config::future, 1), ColorHelper::getColorValue(Config::future, 0), 255);
config->futureColor(RGBA8(red, ColorHelper::getColorValue(config->futureColor(), 1), ColorHelper::getColorValue(config->futureColor(), 0), 255));
} else if (colorMode == 11) {
Config::Button = RGBA8(red, ColorHelper::getColorValue(Config::Button, 1), ColorHelper::getColorValue(Config::Button, 0), 255);
config->buttonColor(RGBA8(red, ColorHelper::getColorValue(config->buttonColor(), 1), ColorHelper::getColorValue(config->buttonColor(), 0), 255));
}
changesMade = true;
}
@@ -528,29 +532,29 @@ void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
if(temp != -1) {
green = temp;
if (colorMode == 0) {
Config::Color1 = RGBA8(ColorHelper::getColorValue(Config::Color1, 2), green, ColorHelper::getColorValue(Config::Color1, 0), 255);
config->barColor(RGBA8(ColorHelper::getColorValue(config->barColor(), 2), green, ColorHelper::getColorValue(config->barColor(), 0), 255));
} else if (colorMode == 1) {
Config::Color2 = RGBA8(ColorHelper::getColorValue(Config::Color2, 2), green, ColorHelper::getColorValue(Config::Color2, 0), 255);
config->topBG(RGBA8(ColorHelper::getColorValue(config->topBG(), 2), green, ColorHelper::getColorValue(config->topBG(), 0), 255));
} else if (colorMode == 2) {
Config::Color3 = RGBA8(ColorHelper::getColorValue(Config::Color3, 2), green, ColorHelper::getColorValue(Config::Color3, 0), 255);
config->bottomBG(RGBA8(ColorHelper::getColorValue(config->bottomBG(), 2), green, ColorHelper::getColorValue(config->bottomBG(), 0), 255));
} else if (colorMode == 3) {
Config::TxtColor = RGBA8(ColorHelper::getColorValue(Config::TxtColor, 2), green, ColorHelper::getColorValue(Config::TxtColor, 0), 255);
config->textColor(RGBA8(ColorHelper::getColorValue(config->textColor(), 2), green, ColorHelper::getColorValue(config->textColor(), 0), 255));
} else if (colorMode == 4) {
Config::SelectedColor = RGBA8(ColorHelper::getColorValue(Config::SelectedColor, 2), green, ColorHelper::getColorValue(Config::SelectedColor, 0), 255);
config->selectedColor(RGBA8(ColorHelper::getColorValue(config->selectedColor(), 2), green, ColorHelper::getColorValue(config->selectedColor(), 0), 255));
} else if (colorMode == 5) {
Config::UnselectedColor = RGBA8(ColorHelper::getColorValue(Config::UnselectedColor, 2), green, ColorHelper::getColorValue(Config::UnselectedColor, 0), 255);
config->unselectedColor(RGBA8(ColorHelper::getColorValue(config->unselectedColor(), 2), green, ColorHelper::getColorValue(config->unselectedColor(), 0), 255));
} else if (colorMode == 6) {
Config::progressbarColor = RGBA8(ColorHelper::getColorValue(Config::progressbarColor, 2), green, ColorHelper::getColorValue(Config::progressbarColor, 0), 255);
config->progressbarColor(RGBA8(ColorHelper::getColorValue(config->progressbarColor(), 2), green, ColorHelper::getColorValue(config->progressbarColor(), 0), 255));
} else if (colorMode == 7) {
Config::notFound = RGBA8(ColorHelper::getColorValue(Config::notFound, 2), green, ColorHelper::getColorValue(Config::notFound, 0), 255);
config->notfoundColor(RGBA8(ColorHelper::getColorValue(config->notfoundColor(), 2), green, ColorHelper::getColorValue(config->notfoundColor(), 0), 255));
} else if (colorMode == 8) {
Config::outdated = RGBA8(ColorHelper::getColorValue(Config::outdated, 2), green, ColorHelper::getColorValue(Config::outdated, 0), 255);
config->outdatedColor(RGBA8(ColorHelper::getColorValue(config->outdatedColor(), 2), green, ColorHelper::getColorValue(config->outdatedColor(), 0), 255));
} else if (colorMode == 9) {
Config::uptodate = RGBA8(ColorHelper::getColorValue(Config::uptodate, 2), green, ColorHelper::getColorValue(Config::uptodate, 0), 255);
config->uptodateColor(RGBA8(ColorHelper::getColorValue(config->uptodateColor(), 2), green, ColorHelper::getColorValue(config->uptodateColor(), 0), 255));
} else if (colorMode == 10) {
Config::future = RGBA8(ColorHelper::getColorValue(Config::future, 2), green, ColorHelper::getColorValue(Config::future, 0), 255);
config->futureColor(RGBA8(ColorHelper::getColorValue(config->futureColor(), 2), green, ColorHelper::getColorValue(config->futureColor(), 0), 255));
} else if (colorMode == 11) {
Config::Button = RGBA8(ColorHelper::getColorValue(Config::Button, 2), green, ColorHelper::getColorValue(Config::Button, 0), 255);
config->buttonColor(RGBA8(ColorHelper::getColorValue(config->buttonColor(), 2), green, ColorHelper::getColorValue(config->buttonColor(), 0), 255));
}
changesMade = true;
}
@@ -559,29 +563,29 @@ void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
if(temp != -1) {
blue = temp;
if (colorMode == 0) {
Config::Color1 = RGBA8(ColorHelper::getColorValue(Config::Color1, 2), ColorHelper::getColorValue(Config::Color1, 1), blue, 255);
config->barColor(RGBA8(ColorHelper::getColorValue(config->barColor(), 2), ColorHelper::getColorValue(config->barColor(), 1), blue, 255));
} else if (colorMode == 1) {
Config::Color2 = RGBA8(ColorHelper::getColorValue(Config::Color2, 2), ColorHelper::getColorValue(Config::Color2, 1), blue, 255);
config->topBG(RGBA8(ColorHelper::getColorValue(config->topBG(), 2), ColorHelper::getColorValue(config->topBG(), 1), blue, 255));
} else if (colorMode == 2) {
Config::Color3 = RGBA8(ColorHelper::getColorValue(Config::Color3, 2), ColorHelper::getColorValue(Config::Color3, 1), blue, 255);
config->bottomBG(RGBA8(ColorHelper::getColorValue(config->bottomBG(), 2), ColorHelper::getColorValue(config->bottomBG(), 1), blue, 255));
} else if (colorMode == 3) {
Config::TxtColor = RGBA8(ColorHelper::getColorValue(Config::TxtColor, 2), ColorHelper::getColorValue(Config::TxtColor, 1), blue, 255);
config->textColor(RGBA8(ColorHelper::getColorValue(config->textColor(), 2), ColorHelper::getColorValue(config->textColor(), 1), blue, 255));
} else if (colorMode == 4) {
Config::SelectedColor = RGBA8(ColorHelper::getColorValue(Config::SelectedColor, 2), ColorHelper::getColorValue(Config::SelectedColor, 1), blue, 255);
config->selectedColor(RGBA8(ColorHelper::getColorValue(config->selectedColor(), 2), ColorHelper::getColorValue(config->selectedColor(), 1), blue, 255));
} else if (colorMode == 5) {
Config::UnselectedColor = RGBA8(ColorHelper::getColorValue(Config::UnselectedColor, 2), ColorHelper::getColorValue(Config::UnselectedColor, 1), blue, 255);
config->unselectedColor(RGBA8(ColorHelper::getColorValue(config->unselectedColor(), 2), ColorHelper::getColorValue(config->unselectedColor(), 1), blue, 255));
} else if (colorMode == 6) {
Config::progressbarColor = RGBA8(ColorHelper::getColorValue(Config::progressbarColor, 2), ColorHelper::getColorValue(Config::progressbarColor, 1), blue, 255);
config->progressbarColor(RGBA8(ColorHelper::getColorValue(config->progressbarColor(), 2), ColorHelper::getColorValue(config->progressbarColor(), 1), blue, 255));
} else if (colorMode == 7) {
Config::notFound = RGBA8(ColorHelper::getColorValue(Config::notFound, 2), ColorHelper::getColorValue(Config::notFound, 1), blue, 255);
config->notfoundColor(RGBA8(ColorHelper::getColorValue(config->notfoundColor(), 2), ColorHelper::getColorValue(config->notfoundColor(), 1), blue, 255));
} else if (colorMode == 8) {
Config::outdated = RGBA8(ColorHelper::getColorValue(Config::outdated, 2), ColorHelper::getColorValue(Config::outdated, 1), blue, 255);
config->outdatedColor(RGBA8(ColorHelper::getColorValue(config->outdatedColor(), 2), ColorHelper::getColorValue(config->outdatedColor(), 1), blue, 255));
} else if (colorMode == 9) {
Config::uptodate = RGBA8(ColorHelper::getColorValue(Config::uptodate, 2), ColorHelper::getColorValue(Config::uptodate, 1), blue, 255);
config->uptodateColor(RGBA8(ColorHelper::getColorValue(config->uptodateColor(), 2), ColorHelper::getColorValue(config->uptodateColor(), 1), blue, 255));
} else if (colorMode == 10) {
Config::future = RGBA8(ColorHelper::getColorValue(Config::future, 2), ColorHelper::getColorValue(Config::future, 1), blue, 255);
config->futureColor(RGBA8(ColorHelper::getColorValue(config->futureColor(), 2), ColorHelper::getColorValue(config->futureColor(), 1), blue, 255));
} else if (colorMode == 11) {
Config::Button = RGBA8(ColorHelper::getColorValue(Config::Button, 2), ColorHelper::getColorValue(Config::Button, 1), blue, 255);
config->buttonColor(RGBA8(ColorHelper::getColorValue(config->buttonColor(), 2), ColorHelper::getColorValue(config->buttonColor(), 1), blue, 255));
}
changesMade = true;
}
+119 -116
View File
@@ -40,6 +40,7 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern bool changesMade;
bool specialHandling = false;
bool didAutoboot = false;
extern std::unique_ptr<Config> config;
UniStore::UniStore(bool doAutoboot, std::string file) {
this->doAutoboot = doAutoboot;
@@ -75,9 +76,9 @@ void UniStore::autobootLogic() {
displayInformations = handleIfDisplayText();
const std::string sheetURL = storeInfo[0].storeSheet;
if (storeInfo[0].version == 0) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[0].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
@@ -93,7 +94,7 @@ void UniStore::autobootLogic() {
StoreInfo UniStore::parseStoreInfo(std::string fileName) {
FILE* file = fopen(fileName.c_str(), "rt");
if (!file) {
printf("File not found\n");
printf("File not found.\n");
return {"", ""};
}
@@ -141,10 +142,10 @@ void UniStore::loadStoreDesc(void) {
void UniStore::DrawSubMenu(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("UNISTORE_SUBMENU"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("UNISTORE_SUBMENU"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("UNISTORE_SUBMENU"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("UNISTORE_SUBMENU"), 400);
}
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
@@ -155,6 +156,7 @@ void UniStore::DrawSubMenu(void) const {
GFX::DrawButton(subPos[0].x, subPos[0].y,Lang::get("STORE_LIST"));
GFX::DrawButton(subPos[1].x, subPos[1].y, Lang::get("STORE_SEARCH"));
GFX::DrawButton(subPos[2].x, subPos[2].y, Lang::get("CHANGE_STOREPATH"));
// Selector.
Animation::Button(subPos[Selection].x, subPos[Selection].y, .060);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
@@ -167,18 +169,18 @@ void UniStore::DrawStoreList(void) const {
std::string line2;
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::DrawString(5, 220, 0.6f, Config::TxtColor, Lang::get("UNISTORE_VERSION") + std::to_string(storeInfo[Selection].version + 1), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), 239-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, Config::TxtColor, storeAmount);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), storeInfo[Selection].title, 400);
Gui::DrawString(5, 220, 0.6f, config->textColor(), Lang::get("UNISTORE_VERSION") + std::to_string(storeInfo[Selection].version + 1), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), 239-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, config->textColor(), storeAmount);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, storeInfo[Selection].title, 400);
Gui::DrawString(5, 218, 0.6f, Config::TxtColor, Lang::get("UNISTORE_VERSION") + std::to_string(storeInfo[Selection].version + 1), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), 237-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, Config::TxtColor, storeAmount);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), storeInfo[Selection].title, 400);
Gui::DrawString(5, 218, 0.6f, config->textColor(), Lang::get("UNISTORE_VERSION") + std::to_string(storeInfo[Selection].version + 1), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), 237-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, config->textColor(), storeAmount);
}
for(uint i = 0; i < descLines.size(); i++) {
Gui::DrawStringCentered(0, 120-((descLines.size()*20)/2)+i*20, 0.6f, Config::TxtColor, descLines[i], 400);
Gui::DrawStringCentered(0, 120-((descLines.size()*20)/2)+i*20, 0.6f, config->textColor(), descLines[i], 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
@@ -188,43 +190,43 @@ void UniStore::DrawStoreList(void) const {
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)storeInfo.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)storeInfo.size(); i++) {
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 (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, Config::TxtColor, line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, Config::TxtColor, line2, 320);
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)storeInfo.size();i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, Config::UnselectedColor);
} else if (config->viewMode() == 1) {
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 (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
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);
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, config->textColor(), line1, 320);
}
}
// DropDown Menu.
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 130, Config::Color1);
Gui::Draw_Rect(0, 25, 140, 130, config->barColor());
for (int i = 0; i < 3; i++) {
if (dropSelection == i) {
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, Config::SelectedColor);
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, config->selectedColor());
} else {
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, Config::UnselectedColor);
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, config->unselectedColor());
}
}
@@ -233,9 +235,9 @@ void UniStore::DrawStoreList(void) const {
GFX::DrawSpriteBlend(sprites_update_idx, dropPos[1].x, dropPos[1].y);
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[2].x, dropPos[2].y);
// Dropdown Text.
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, Config::TxtColor, Lang::get("DELETE_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, Config::TxtColor, Lang::get("UPDATE_DDM"), 100);
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, Config::TxtColor, Lang::get("VIEW_DDM"), 100);
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, config->textColor(), Lang::get("DELETE_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, config->textColor(), Lang::get("UPDATE_DDM"), 100);
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, config->textColor(), 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
@@ -272,9 +274,9 @@ void UniStore::updateStore(int selectedStore) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
@@ -284,13 +286,13 @@ void UniStore::updateStore(int selectedStore) {
}
void UniStore::refreshList() {
if (returnIfExist(Config::StorePath, {"unistore"}) == true) {
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
@@ -306,9 +308,9 @@ void UniStore::refreshList() {
void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
if (specialHandling) {
Gui::setScreen(std::make_unique<MainMenu>(), true, true);
Gui::setScreen(std::make_unique<MainMenu>(), config->screenFade(), true);
} else {
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
}
@@ -323,17 +325,18 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_A) {
switch(Selection) {
case 0:
if (returnIfExist(Config::StorePath, {"unistore"}) == true) {
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
Selection = 0;
mode = 1;
} else {
@@ -349,9 +352,9 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
break;
case 2:
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), Config::StorePath, {});
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), config->storePath(), {});
if (tempStore != "") {
Config::StorePath = tempStore;
config->storePath(tempStore);
changesMade = true;
}
break;
@@ -360,17 +363,18 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH) {
if (touching(touch, subPos[0])) {
if (returnIfExist(Config::StorePath, {"unistore"}) == true) {
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
Selection = 0;
mode = 1;
} else {
@@ -384,9 +388,9 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
notConnectedMsg();
}
} else if (touching(touch, subPos[2])) {
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), Config::StorePath, {});
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), config->storePath(), {});
if (tempStore != "") {
Config::StorePath = tempStore;
config->storePath(tempStore);
changesMade = true;
}
}
@@ -394,7 +398,7 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
void UniStore::deleteStore(int selectedStore) {
std::string path = Config::StorePath;
std::string path = config->storePath();
path += dirContents[selectedStore].name;
deleteFile(path.c_str());
// Refresh the list.
@@ -402,9 +406,9 @@ void UniStore::deleteStore(int selectedStore) {
Selection = 0;
dirContents.clear();
storeInfo.clear();
chdir(Config::StorePath.c_str());
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i=0;i<dirContents.size();i++) {
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
@@ -459,10 +463,10 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
updateStore(Selection);
break;
case 2:
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
break;
}
@@ -479,10 +483,10 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
updateStore(Selection);
dropDownMenu = false;
} else if (touching(touch, dropPos2[2])) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
dropDownMenu = false;
}
@@ -510,7 +514,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
loadStoreDesc();
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
@@ -524,11 +528,11 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
loadStoreDesc();
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection < (int)storeInfo.size()-1-3) {
Selection += 3;
descript();
@@ -550,11 +554,11 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
descript();
@@ -576,12 +580,11 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if (hDown & KEY_A) {
if (dirContents[Selection].isDirectory) {
} else if (storeInfo.size() != 0) {
if (!dirContents[Selection].isDirectory && storeInfo.size() != 0) {
if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) {
updateStore(Selection);
currentStoreFile = dirContents[Selection].name;
@@ -591,9 +594,9 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
const std::string sheetURL = storeInfo[Selection].storeSheet;
if (storeInfo[Selection].version == 0) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[Selection].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
@@ -601,13 +604,13 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
if (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) {
} else if (config->viewMode() == 1) {
if(Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
@@ -616,9 +619,9 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_TOUCH) {
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)storeInfo.size();i++) {
if(touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)storeInfo.size(); i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (ScriptHelper::checkIfValid(dirContents[screenPos + i].name, 1) == true) {
updateStore(screenPos + i);
currentStoreFile = dirContents[screenPos + i].name;
@@ -627,17 +630,17 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
displayInformations = handleIfDisplayText();
const std::string sheetURL = storeInfo[screenPos + i].storeSheet;
if (storeInfo[screenPos + i].version == 0) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[screenPos + i].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
}
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)storeInfo.size();i++) {
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)storeInfo.size(); i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (ScriptHelper::checkIfValid(dirContents[screenPosList + i].name, 1) == true) {
updateStore(screenPosList + i);
@@ -648,9 +651,9 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
displayInformations = handleIfDisplayText();
const std::string sheetURL = storeInfo[screenPosList + i].storeSheet;
if (storeInfo[screenPosList + i].version == 0) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[screenPosList + i].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), Config::fading, true);
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
@@ -661,19 +664,18 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
}
if (hDown & KEY_START) {
if (Config::autoboot == 1) {
if (config->autoboot() == 1) {
if (Msg::promptMsg(Lang::get("DISABLE_AUTOBOOT"))) {
Config::autoboot = 0;
Config::AutobootFile = "";
config->autoboot(0);
config->autobootFile("");
changesMade = true;
}
} else {
if (dirContents[Selection].isDirectory) {
} else if (storeInfo.size() != 0) {
if (!dirContents[Selection].isDirectory && storeInfo.size() != 0) {
if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) {
if (Msg::promptMsg(Lang::get("AUTOBOOT_STORE"))) {
Config::AutobootFile = Config::StorePath + dirContents[Selection].name;
Config::autoboot = 1;
config->autoboot(1);
config->autobootFile(config->storePath() + dirContents[Selection].name);
changesMade = true;
}
}
@@ -701,10 +703,10 @@ void UniStore::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
void UniStore::DrawSearch(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("UNISTORE_SEARCH"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("UNISTORE_SEARCH"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("UNISTORE_SEARCH"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("UNISTORE_SEARCH"), 400);
}
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
@@ -715,6 +717,7 @@ void UniStore::DrawSearch(void) const {
GFX::DrawButton(URLBtn[1].x, URLBtn[1].y, Lang::get("GITHUB"));
GFX::DrawButton(URLBtn[2].x, URLBtn[2].y, "TinyDB");
GFX::DrawButton(URLBtn[3].x, URLBtn[3].y, "Universal DB");
// Selector.
Animation::Button(URLBtn[Selection].x, URLBtn[Selection].y, .060);
}
@@ -752,9 +755,9 @@ void UniStore::SearchLogic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
mode = 4;
} else if (Selection == 2) {
ScriptHelper::downloadFile("https://tinydb.eiphax.tech/api/tinydb.unistore", Config::StorePath + "TinyDB.unistore", Lang::get("DOWNLOADING") + "TinyDB");
ScriptHelper::downloadFile("https://tinydb.eiphax.tech/api/tinydb.unistore", config->storePath() + "TinyDB.unistore", Lang::get("DOWNLOADING") + "TinyDB");
} else if (Selection == 3) {
ScriptHelper::downloadFile("https://db.universal-team.net/unistore/universal-db.unistore", Config::StorePath + "Universal-DB.unistore", Lang::get("DOWNLOADING") + "Universal DB");
ScriptHelper::downloadFile("https://db.universal-team.net/unistore/universal-db.unistore", config->storePath() + "Universal-DB.unistore", Lang::get("DOWNLOADING") + "Universal DB");
}
}
@@ -765,35 +768,35 @@ void UniStore::SearchLogic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
mode = 4;
} 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");
ScriptHelper::downloadFile("https://tinydb.eiphax.tech/api/tinydb.unistore", config->storePath() + "TinyDB.unistore", Lang::get("DOWNLOADING") + "TinyDB");
} else if (hDown & KEY_TOUCH && touching(touch, URLBtn[3])) {
ScriptHelper::downloadFile("https://db.universal-team.net/unistore/universal-db.unistore", Config::StorePath + "Universal-DB.unistore", Lang::get("DOWNLOADING") + "Universal DB");
ScriptHelper::downloadFile("https://db.universal-team.net/unistore/universal-db.unistore", config->storePath() + "Universal-DB.unistore", Lang::get("DOWNLOADING") + "Universal DB");
}
}
void UniStore::DrawGitHubScreen(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("GITHUB"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("GITHUB"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("GITHUB"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("GITHUB"), 400);
}
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
Gui::DrawStringCentered(0, 28, 0.7f, Config::TxtColor, Lang::get("OWNER_AND_REPO"), 300);
Gui::DrawStringCentered(0, 108, 0.7f, Config::TxtColor, Lang::get("FILENAME"), 300);
Gui::DrawStringCentered(0, 28, 0.7f, config->textColor(), Lang::get("OWNER_AND_REPO"), 300);
Gui::DrawStringCentered(0, 108, 0.7f, config->textColor(), Lang::get("FILENAME"), 300);
Gui::Draw_Rect(GitHubPos[0].x, GitHubPos[0].y, GitHubPos[0].w, GitHubPos[0].h, Config::Color1);
Gui::Draw_Rect(GitHubPos[1].x, GitHubPos[1].y, GitHubPos[1].w, GitHubPos[1].h, Config::Color1);
Gui::Draw_Rect(GitHubPos[2].x, GitHubPos[2].y, GitHubPos[2].w, GitHubPos[2].h, Config::Color1);
Gui::Draw_Rect(GitHubPos[0].x, GitHubPos[0].y, GitHubPos[0].w, GitHubPos[0].h, config->barColor());
Gui::Draw_Rect(GitHubPos[1].x, GitHubPos[1].y, GitHubPos[1].w, GitHubPos[1].h, config->barColor());
Gui::Draw_Rect(GitHubPos[2].x, GitHubPos[2].y, GitHubPos[2].w, GitHubPos[2].h, config->barColor());
Gui::DrawStringCentered(0, 185, 0.7f, Config::TxtColor, Lang::get("OK"), 40);
Gui::DrawStringCentered(0, 185, 0.7f, config->textColor(), Lang::get("OK"), 40);
Gui::DrawStringCentered(0, 57, 0.5f, Config::TxtColor, OwnerAndRepo, 250);
Gui::DrawStringCentered(0, 137, 0.5f, Config::TxtColor, fileName, 250);
Gui::DrawStringCentered(0, 57, 0.5f, config->textColor(), OwnerAndRepo, 250);
Gui::DrawStringCentered(0, 137, 0.5f, config->textColor(), fileName, 250);
}
void UniStore::GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch) {
@@ -811,7 +814,7 @@ void UniStore::GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch) {
URL += OwnerAndRepo;
URL += "/raw/master/unistore/";
URL += fileName;
ScriptHelper::downloadFile(URL, Config::StorePath + fileName, Lang::get("DOWNLOADING") + fileName);
ScriptHelper::downloadFile(URL, config->storePath() + fileName, Lang::get("DOWNLOADING") + fileName);
} else {
notConnectedMsg();
}
@@ -828,27 +831,27 @@ void UniStore::GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch) {
void UniStore::DrawFullURLScreen(void) const {
GFX::DrawTop();
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.7f, Config::TxtColor, Lang::get("FULL_URL"), 400);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("FULL_URL"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("FULL_URL"), 400);
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("FULL_URL"), 400);
}
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
Gui::DrawStringCentered(0, 28, 0.7f, Config::TxtColor, Lang::get("FULL_URL"), 320);
Gui::DrawStringCentered(0, 108, 0.7f, Config::TxtColor, Lang::get("FILENAME"), 320);
Gui::DrawStringCentered(0, 28, 0.7f, config->textColor(), Lang::get("FULL_URL"), 320);
Gui::DrawStringCentered(0, 108, 0.7f, config->textColor(), Lang::get("FILENAME"), 320);
Gui::Draw_Rect(GitHubPos[0].x, GitHubPos[0].y, GitHubPos[0].w, GitHubPos[0].h, Config::Color1);
Gui::Draw_Rect(GitHubPos[1].x, GitHubPos[1].y, GitHubPos[1].w, GitHubPos[1].h, Config::Color1);
Gui::Draw_Rect(GitHubPos[2].x, GitHubPos[2].y, GitHubPos[2].w, GitHubPos[2].h, Config::Color1);
Gui::Draw_Rect(GitHubPos[0].x, GitHubPos[0].y, GitHubPos[0].w, GitHubPos[0].h, config->barColor());
Gui::Draw_Rect(GitHubPos[1].x, GitHubPos[1].y, GitHubPos[1].w, GitHubPos[1].h, config->barColor());
Gui::Draw_Rect(GitHubPos[2].x, GitHubPos[2].y, GitHubPos[2].w, GitHubPos[2].h, config->barColor());
Gui::DrawStringCentered(0, 185, 0.7f, Config::TxtColor, Lang::get("OK"), 40);
Gui::DrawStringCentered(0, 185, 0.7f, config->textColor(), Lang::get("OK"), 40);
Gui::DrawStringCentered(0, 57, 0.45f, Config::TxtColor, FullURL, 250);
Gui::DrawStringCentered(0, 137, 0.45f, Config::TxtColor, fileName, 250);
Gui::DrawStringCentered(0, 57, 0.45f, config->textColor(), FullURL, 250);
Gui::DrawStringCentered(0, 137, 0.45f, config->textColor(), fileName, 250);
}
void UniStore::FullURLLogic(u32 hDown, u32 hHeld, touchPosition touch) {
@@ -862,7 +865,7 @@ void UniStore::FullURLLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[2])) {
if (checkWifiStatus() == true) {
ScriptHelper::downloadFile(FullURL, Config::StorePath + fileName, Lang::get("DOWNLOADING") + fileName);
ScriptHelper::downloadFile(FullURL, config->storePath() + fileName, Lang::get("DOWNLOADING") + fileName);
} else {
notConnectedMsg();
}
+86 -84
View File
@@ -31,6 +31,7 @@
#include "unistore_v1.hpp"
#include <unistd.h>
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern u32 getColor(std::string colorString);
extern bool isScriptSelected;
@@ -57,25 +58,25 @@ UniStoreV1::UniStoreV1(nlohmann::json &JSON, const std::string sheetPath, bool d
u32 colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
barColor = colorTemp == 0 ? Config::Color1 : colorTemp;
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
bgTopColor = colorTemp == 0 ? Config::Color2 : colorTemp;
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
bgBottomColor = colorTemp == 0 ? Config::Color3 : colorTemp;
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
TextColor = colorTemp == 0 ? Config::TxtColor : colorTemp;
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
selected = colorTemp == 0 ? Config::SelectedColor : colorTemp;
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
unselected = colorTemp == 0 ? Config::UnselectedColor : colorTemp;
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
progressBar = colorTemp == 0 ? Config::progressbarColor : colorTemp;
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
}
void UniStoreV1::drawBlend(int key, int x, int y) const {
@@ -122,7 +123,7 @@ void UniStoreV1::Draw(void) const {
}
if (displayInformations != false) {
if (Config::UseBars == true) {
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 {
@@ -160,7 +161,7 @@ void UniStoreV1::Draw(void) const {
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
if (Config::viewMode == 0) {
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) {
@@ -180,10 +181,10 @@ void UniStoreV1::Draw(void) const {
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, TextColor, info, 320);
}
} else if (Config::viewMode == 1) {
} 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 (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 {
@@ -206,11 +207,11 @@ void UniStoreV1::Draw(void) const {
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);
Gui::drawAnimatedSelector(dropPos[0].x, dropPos[0].y, dropPos[0].w, dropPos[0].h, .090, TRANSPARENT, selected);
// 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);
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, TextColor, 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
@@ -230,21 +231,22 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_UP) {
if (dropSelection > 0) dropSelection--;
}
if (hDown & KEY_A) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
dropDownMenu = false;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, dropPos[0])) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
dropDownMenu = false;
}
@@ -257,7 +259,7 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
if (!didAutoboot) didAutoboot = true;
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
@@ -269,7 +271,7 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = (int)this->storeJson.at("storeContent").size()-1;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
// Go one entry down.
@@ -280,11 +282,11 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
Selection = 0;
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection < (int)this->storeJson.at("storeContent").size()-1-3) {
Selection += 3;
} else {
@@ -298,11 +300,11 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (Config::viewMode == 0) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
} else {
@@ -316,13 +318,13 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
keyRepeatDelay = Config::keyDelay;
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 (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"];
@@ -331,8 +333,8 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)this->storeJson.at("storeContent").size();i++) {
} 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"];
@@ -351,14 +353,14 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
if (Config::viewMode == 0) {
if(Selection < screenPos) {
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) {
} else if (config->viewMode() == 1) {
if (Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = Selection - ENTRIES_PER_LIST + 1;
@@ -371,87 +373,87 @@ void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
// 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++) {
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") {
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");
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);
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") {
} 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");
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");
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);
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") {
} 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");
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");
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");
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())
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())
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);
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") {
} 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");
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");
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");
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);
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") {
} 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");
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()) {
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);
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");
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());
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");
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 ) {
if (!missing) {
if (access(directory.c_str(), F_OK) != 0 ) {
ret = DELETE_ERROR;
} else {
if (Msg::promptMsg(promptmsg)) {
@@ -464,25 +466,25 @@ Result UniStoreV1::execute() {
} 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");
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());
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");
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())
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);
if (!missing) ScriptHelper::displayTimeMsg(message, seconds);
else ret = SYNTAX_ERROR;
} else if (type == "saveConfig") {
Config::save();
config->save();
} else if (type == "notImplemented") {
notImplemented();
@@ -491,39 +493,39 @@ Result UniStoreV1::execute() {
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");
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");
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);
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");
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");
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");
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 (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");
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");
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 (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;
}
+59 -58
View File
@@ -32,6 +32,7 @@
#include <unistd.h>
extern std::unique_ptr<Config> config;
extern u32 getColor(std::string colorString);
extern bool touching(touchPosition touch, Structs::ButtonPos button);
#define STORE_ENTRIES 15
@@ -92,7 +93,7 @@ void UniStoreV2::DrawBaseTop(void) const {
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) {
if (config->useBars() == true) {
GFX::DrawSprite(sprites_top_screen_top_idx, 0, 0);
GFX::DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
@@ -103,7 +104,7 @@ void UniStoreV2::DrawBaseBottom(void) const {
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) {
if (config->useBars() == true) {
GFX::DrawSprite(sprites_top_screen_top_idx, 0, 0);
GFX::DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
@@ -230,7 +231,7 @@ void UniStoreV2::parseObjects(int selection) {
void UniStoreV2::DrawSearchMenu(void) const {
this->DrawBaseTop();
if (Config::UseBars == true) {
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, this->returnTextColor(), Lang::get("SEARCH_MENU"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, this->returnTextColor(), Lang::get("SEARCH_MENU"), 400);
@@ -279,13 +280,13 @@ void UniStoreV2::displaySelectedEntry(int selection) const {
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) {
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) {
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, this->returnTextColor(), "?", 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, this->returnTextColor(), "?", 400);
@@ -350,7 +351,7 @@ void UniStoreV2::Draw(void) const {
if (this->mode == 0) {
this->DrawBaseTop();
if (Config::UseBars == true) {
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);
@@ -368,7 +369,7 @@ void UniStoreV2::Draw(void) const {
} else if (this->mode == 1) {
this->DrawBaseTop();
if (Config::UseBars == true) {
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);
@@ -470,7 +471,7 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->mode == 0) {
if (hDown & KEY_B) {
if (!didAutoboot) didAutoboot = true;
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
@@ -554,7 +555,7 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
} else if (this->mode == 1) {
if (hDown & KEY_B) {
if (!didAutoboot) didAutoboot = true;
Gui::screenBack(Config::fading);
Gui::screenBack(config->screenFade());
return;
}
@@ -827,87 +828,87 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
// 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++) {
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");
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);
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") {
} 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");
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");
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);
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") {
} 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");
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");
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");
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())
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())
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);
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") {
} 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");
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");
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");
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);
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") {
} 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");
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()) {
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);
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");
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());
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");
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 ) {
if (!missing) {
if (access(directory.c_str(), F_OK) != 0 ) {
ret = DELETE_ERROR;
} else {
if (Msg::promptMsg(promptmsg)) {
@@ -920,63 +921,63 @@ Result UniStoreV2::runFunctions(std::string entry) {
} 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");
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());
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");
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())
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);
if (!missing) ScriptHelper::displayTimeMsg(message, seconds);
else ret = SYNTAX_ERROR;
} else if (type == "saveConfig") {
Config::save();
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");
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");
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);
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");
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");
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");
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 (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");
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");
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 (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;
}
+244 -290
View File
@@ -26,323 +26,277 @@
#include "common.hpp"
#include "config.hpp"
#include "gui.hpp"
#include "json.hpp"
#include <string>
#include "colorHelper.hpp"
#include <citro2d.h>
#include <unistd.h>
std::string Config::lang; // Current Language.
int Config::Color1;
int Config::Color2;
int Config::Color3;
int Config::TxtColor;
int Config::SelectedColor;
int Config::UnselectedColor;
int Config::viewMode;
int Config::progressbarColor;
std::string Config::ScriptPath;
std::string Config::MusicPath;
bool Config::Logging;
bool Config::UseBars;
std::string Config::StorePath;
int Config::LangPath;
int Config::autoboot = 0;
std::string Config::AutobootFile = "";
int Config::outdated;
int Config::uptodate;
int Config::notFound;
int Config::future;
int Config::Button;
int Config::keyDelay = 5;
bool Config::fading = false;
bool Config::progress = true;
nlohmann::json configJson;
extern bool changesMade;
// In case it doesn't exist.
void Config::initialize() {
// Create through fopen "Write".
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
void Config::load() {
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "r");
if(file) {
configJson = nlohmann::json::parse(file, nullptr, false);
// Set default values.
this->setInt("BARCOLOR", BarColor);
this->setInt("TOPBGCOLOR", TopBGColor);
this->setInt("BOTTOMBGCOLOR", BottomBGColor);
this->setInt("TEXTCOLOR", WHITE);
this->setInt("BUTTON", C2D_Color32(0, 0, 50, 255));
this->setInt("SELECTEDCOLOR", SelectedColordefault);
this->setInt("UNSELECTEDCOLOR", UnselectedColordefault);
this->setString("SCRIPTPATH", SCRIPTS_PATH);
this->setInt("LANGPATH", 0);
this->setInt("VIEWMODE", 0);
this->setInt("PROGRESSBARCOLOR", WHITE);
this->setString("MUSICPATH", MUSIC_PATH);
this->setBool("LOGGING", false);
this->setBool("BARS", true);
this->setInt("AUTOBOOT", 0);
this->setString("STOREPATH", STORE_PATH);
this->setString("AUTOBOOT_FILE", "");
this->setInt("OUTDATED", C2D_Color32(0xfb, 0x5b, 0x5b, 255));
this->setInt("UPTODATE", C2D_Color32(0xa5, 0xdd, 0x81, 255));
this->setInt("NOTFOUND", C2D_Color32(255, 128, 0, 255));
this->setInt("FUTURE", C2D_Color32(255, 255, 0, 255));
this->setInt("KEY_DELAY", 5);
this->setBool("SCREEN_FADE", false);
this->setBool("PROGRESS_DISPLAY", true);
this->setString("LANGUAGE", "en");
if(!configJson.contains("BARCOLOR")) {
Color1 = BarColor;
} else {
Color1 = getInt("BARCOLOR");
}
if(!configJson.contains("TOPBGCOLOR")) {
Color2 = TopBGColor;
} else {
Color2 = getInt("TOPBGCOLOR");
}
if(!configJson.contains("BOTTOMBGCOLOR")) {
Color3 = BottomBGColor;
} else {
Color3 = getInt("BOTTOMBGCOLOR");
}
if(!configJson.contains("TEXTCOLOR")) {
TxtColor = WHITE;
} else {
TxtColor = getInt("TEXTCOLOR");
}
if(!configJson.contains("UNSELECTEDCOLOR")) {
UnselectedColor = UnselectedColordefault;
} else {
UnselectedColor = getInt("UNSELECTEDCOLOR");
}
if(!configJson.contains("SELECTEDCOLOR")) {
SelectedColor = SelectedColordefault;
} else {
SelectedColor = getInt("SELECTEDCOLOR");
}
if(!configJson.contains("SCRIPTPATH")) {
ScriptPath = SCRIPTS_PATH;
} else {
ScriptPath = getString("SCRIPTPATH");
}
if(!configJson.contains("LANGPATH")) {
LangPath = 0;
} else {
LangPath = getInt("LANGPATH");
}
// Conversion to string.
if (configJson.contains("LANGUAGE") && configJson.at("LANGUAGE").is_number()) {
setString("LANGUAGE", "en");
changesMade = true;
}
if(!configJson.contains("LANGUAGE")) {
lang = "en";
} else {
lang = getString("LANGUAGE");
}
if(!configJson.contains("VIEWMODE")) {
viewMode = 0;
} else {
viewMode = getInt("VIEWMODE");
}
if(!configJson.contains("PROGRESSBARCOLOR")) {
progressbarColor = WHITE;
} else {
progressbarColor = getInt("PROGRESSBARCOLOR");
}
if(!configJson.contains("MUSICPATH")) {
MusicPath = MUSIC_PATH;
} else {
MusicPath = getString("MUSICPATH");
}
if(!configJson.contains("LOGGING")) {
Logging = false;
} else {
Logging = getBool("LOGGING");
}
if(!configJson.contains("BARS")) {
UseBars = true;
} else {
UseBars = getBool("BARS");
}
if(!configJson.contains("STOREPATH")) {
StorePath = STORE_PATH;
} else {
StorePath = getString("STOREPATH");
}
if(!configJson.contains("AUTOBOOT")) {
autoboot = 0;
} else {
autoboot = getInt("AUTOBOOT");
}
if(!configJson.contains("AUTOBOOT_FILE")) {
AutobootFile = "";
} else {
AutobootFile = getString("AUTOBOOT_FILE");
}
if(!configJson.contains("OUTDATED")) {
outdated = C2D_Color32(0xfb, 0x5b, 0x5b, 255);
} else {
outdated = getInt("OUTDATED");
}
if(!configJson.contains("UPTODATE")) {
uptodate = C2D_Color32(0xa5, 0xdd, 0x81, 255);
} else {
uptodate = getInt("UPTODATE");
}
if(!configJson.contains("NOTFOUND")) {
notFound = C2D_Color32(255, 128, 0, 255);
} else {
notFound = getInt("NOTFOUND");
}
if(!configJson.contains("FUTURE")) {
future = C2D_Color32(255, 255, 0, 255);
} else {
future = getInt("FUTURE");
}
if(!configJson.contains("BUTTON")) {
Button = C2D_Color32(0, 0, 50, 255);
} else {
Button = getInt("BUTTON");
}
if(!configJson.contains("KEY_DELAY")) {
keyDelay = 5;
} else {
keyDelay = getInt("KEY_DELAY");
}
if(!configJson.contains("SCREEN_FADE")) {
fading = false;
} else {
fading = getBool("SCREEN_FADE");
}
if(!configJson.contains("PROGRESS_DISPLAY")) {
progress = true;
} else {
progress = getBool("PROGRESS_DISPLAY");
}
fclose(file);
} else {
Color1 = BarColor;
Color2 = TopBGColor;
Color3 = BottomBGColor;
TxtColor = WHITE;
SelectedColor = SelectedColordefault;
UnselectedColor = UnselectedColordefault;
ScriptPath = SCRIPTS_PATH;
LangPath = 0;
lang = "en";
viewMode = 0;
progressbarColor = WHITE;
MusicPath = MUSIC_PATH;
Logging = false;
UseBars = true;
StorePath = STORE_PATH;
autoboot = 0;
AutobootFile = "";
outdated = C2D_Color32(0xfb, 0x5b, 0x5b, 255);
uptodate = C2D_Color32(0xa5, 0xdd, 0x81, 255);
notFound = C2D_Color32(255, 128, 0, 255);
future = C2D_Color32(255, 255, 0, 255);
Button = C2D_Color32(0, 0, 50, 255);
keyDelay = 5;
fading = false;
progress = true;
}
// Write to file.
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), file);
fclose(file); // Now we have the file and can properly access it.
}
Config::Config() {
if (access("sdmc:/3ds/Universal-Updater/Settings.json", F_OK) != 0 ) {
this->initialize();
}
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "r");
this->json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
// Here we get the initial settings.
if (!this->json.contains("Bar_Color")) {
this->barColor(BarColor);
} else {
this->barColor(this->getInt("BARCOLOR"));
}
if (!this->json.contains("TOPBGCOLOR")) {
this->topBG(TopBGColor);
} else {
this->topBG(this->getInt("TOPBGCOLOR"));
}
if (!this->json.contains("BOTTOMBGCOLOR")) {
this->bottomBG(BottomBGColor);
} else {
this->bottomBG(this->getInt("BOTTOMBGCOLOR"));
}
if (!this->json.contains("TEXTCOLOR")) {
this->textColor(WHITE);
} else {
this->textColor(this->getInt("TEXTCOLOR"));
}
if (!this->json.contains("BUTTON")) {
this->buttonColor(C2D_Color32(0, 0, 50, 255));
} else {
this->buttonColor(this->getInt("BUTTON"));
}
if (!this->json.contains("SELECTEDCOLOR")) {
this->selectedColor(SelectedColordefault);
} else {
this->selectedColor(this->getInt("SELECTEDCOLOR"));
}
if (!this->json.contains("UNSELECTEDCOLOR")) {
this->unselectedColor(UnselectedColordefault);
} else {
this->unselectedColor(this->getInt("UNSELECTEDCOLOR"));
}
if (!this->json.contains("SCRIPTPATH")) {
this->scriptPath(SCRIPTS_PATH);
} else {
this->scriptPath(this->getString("SCRIPTPATH"));
}
if (!this->json.contains("LANGPATH")) {
this->langPath(0);
} else {
this->langPath(this->getInt("LANGPATH"));
}
if (!this->json.contains("VIEWMODE")) {
this->viewMode(0);
} else {
this->viewMode(this->getInt("VIEWMODE"));
}
if (!this->json.contains("PROGRESSBARCOLOR")) {
this->progressbarColor(WHITE);
} else {
this->progressbarColor(this->getInt("PROGRESSBARCOLOR"));
}
if (!this->json.contains("MUSICPATH")) {
this->musicPath(MUSIC_PATH);
} else {
this->musicPath(this->getString("MUSICPATH"));
}
if (!this->json.contains("LOGGING")) {
this->logging(false);
} else {
this->logging(this->getBool("LOGGING"));
}
if (!this->json.contains("BARS")) {
this->useBars(true);
} else {
this->useBars(this->getBool("BARS"));
}
if (!this->json.contains("AUTOBOOT")) {
this->autoboot(0);
} else {
this->viewMode(this->getInt("AUTOBOOT"));
}
if (!this->json.contains("STOREPATH")) {
this->storePath(STORE_PATH);
} else {
this->storePath(this->getString("STOREPATH"));
}
if (!this->json.contains("AUTOBOOT_FILE")) {
this->autobootFile("");
} else {
this->autobootFile(this->getString("AUTOBOOT_FILE"));
}
if (!this->json.contains("OUTDATED")) {
this->outdatedColor(C2D_Color32(0xfb, 0x5b, 0x5b, 255));
} else {
this->outdatedColor(this->getInt("OUTDATED"));
}
if (!this->json.contains("UPTODATE")) {
this->uptodateColor(C2D_Color32(0xa5, 0xdd, 0x81, 255));
} else {
this->uptodateColor(this->getInt("UPTODATE"));
}
if (!this->json.contains("NOTFOUND")) {
this->notfoundColor(C2D_Color32(255, 128, 0, 255));
} else {
this->notfoundColor(this->getInt("NOTFOUND"));
}
if (!this->json.contains("FUTURE")) {
this->futureColor(C2D_Color32(255, 255, 0, 255));
} else {
this->futureColor(this->getInt("FUTURE"));
}
if (!this->json.contains("KEY_DELAY")) {
this->keyDelay(5);
} else {
this->keyDelay(this->getInt("KEY_DELAY"));
}
if (!this->json.contains("SCREEN_FADE")) {
this->screenFade(false);
} else {
this->screenFade(this->getBool("SCREEN_FADE"));
}
if (!this->json.contains("PROGRESS_DISPLAY")) {
this->progressDisplay(true);
} else {
this->progressDisplay(this->getBool("PROGRESS_DISPLAY"));
}
if (!this->json.contains("LANGUAGE")) {
this->language("en");
} else {
this->language(this->getString("LANGUAGE"));
}
this->changesMade = false; // No changes made yet.
}
// Write to config if changesMade.
void Config::save() {
setInt("BARCOLOR", Color1);
setInt("TOPBGCOLOR", Color2);
setInt("BOTTOMBGCOLOR", Color3);
setInt("TEXTCOLOR", TxtColor);
setInt("SELECTEDCOLOR", SelectedColor);
setInt("UNSELECTEDCOLOR", UnselectedColor);
setString("SCRIPTPATH", ScriptPath);
setInt("LANGPATH", LangPath);
setString("LANGUAGE", lang);
setInt("VIEWMODE", viewMode);
setInt("PROGRESSBARCOLOR", progressbarColor);
setString("MUSICPATH", MusicPath);
setBool("LOGGING", Logging);
setBool("BARS", UseBars);
setString("STOREPATH", StorePath);
setInt("AUTOBOOT", autoboot);
setString("AUTOBOOT_FILE", AutobootFile);
setInt("OUTDATED", outdated);
setInt("UPTODATE", uptodate);
setInt("NOTFOUND", notFound);
setInt("FUTURE", future);
setInt("BUTTON", Button);
setInt("KEY_DELAY", keyDelay);
setBool("SCREEN_FADE", fading);
setBool("PROGRESS_DISPLAY", progress);
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file);
fclose(file);
}
void Config::initializeNewConfig() {
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "r");
if(file) configJson = nlohmann::json::parse(file, nullptr, false);
setInt("BARCOLOR", BarColor);
setInt("TOPBGCOLOR", TopBGColor);
setInt("BOTTOMBGCOLOR", BottomBGColor);
setInt("TEXTCOLOR", WHITE);
setInt("SELECTEDCOLOR", SelectedColordefault);
setInt("UNSELECTEDCOLOR", UnselectedColordefault);
setString("SCRIPTPATH", SCRIPTS_PATH);
setInt("LANGPATH", 0);
setString("LANGUAGE", "en");
setInt("VIEWMODE", 0);
setInt("PROGRESSBARCOLOR", WHITE);
setString("MUSICPATH", MUSIC_PATH);
setBool("LOGGING", false);
setBool("BARS", true);
setString("STOREPATH", STORE_PATH);
setInt("AUTOBOOT", 0);
setString("AUTOBOOT_FILE", "");
setInt("OUTDATED", C2D_Color32(0xfb, 0x5b, 0x5b, 255));
setInt("UPTODATE", C2D_Color32(0xa5, 0xdd, 0x81, 255));
setInt("NOTFOUND", C2D_Color32(255, 128, 0, 255));
setInt("FUTURE", C2D_Color32(255, 255, 0, 255));
setInt("BUTTON", C2D_Color32(0, 0, 50, 255));
setInt("KEY_DELAY", 5);
setBool("SCREEN_FADE", false);
setBool("PROGRESS_DISPLAY", true);
if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file);
if (this->changesMade) {
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
// Set values.
this->setInt("BARCOLOR", this->barColor());
this->setInt("TOPBGCOLOR", this->topBG());
this->setInt("BOTTOMBGCOLOR", this->bottomBG());
this->setInt("TEXTCOLOR", this->textColor());
this->setInt("BUTTON", this->buttonColor());
this->setInt("SELECTEDCOLOR", this->selectedColor());
this->setInt("UNSELECTEDCOLOR", this->unselectedColor());
this->setString("SCRIPTPATH", this->scriptPath());
this->setInt("LANGPATH", this->langPath());
this->setInt("VIEWMODE", this->viewMode());
this->setInt("PROGRESSBARCOLOR", this->progressbarColor());
this->setString("MUSICPATH", this->musicPath());
this->setBool("LOGGING", this->logging());
this->setBool("BARS", this->useBars());
this->setInt("AUTOBOOT", this->autoboot());
this->setString("STOREPATH", this->storePath());
this->setString("AUTOBOOT_FILE", this->autobootFile());
this->setInt("OUTDATED", this->outdatedColor());
this->setInt("UPTODATE", this->uptodateColor());
this->setInt("NOTFOUND", this->notfoundColor());
this->setInt("FUTURE", this->futureColor());
this->setInt("KEY_DELAY", this->keyDelay());
this->setBool("SCREEN_FADE", this->screenFade());
this->setBool("PROGRESS_DISPLAY", this->progressDisplay());
this->setString("LANGUAGE", this->language());
// Write changes to file.
fwrite(this->json.dump(1, '\t').c_str(), 1, this->json.dump(1, '\t').size(), file);
fclose(file);
}
}
// Helper functions.
bool Config::getBool(const std::string &key) {
if(!configJson.contains(key)) {
if (!this->json.contains(key)) {
return false;
}
return configJson.at(key).get_ref<const bool&>();
return this->json.at(key).get_ref<const bool&>();
}
void Config::setBool(const std::string &key, bool v) {
configJson[key] = v;
this->json[key] = v;
}
int Config::getInt(const std::string &key) {
if(!configJson.contains(key)) {
if (!this->json.contains(key)) {
return 0;
}
return configJson.at(key).get_ref<const int64_t&>();
return this->json.at(key).get_ref<const int64_t&>();
}
void Config::setInt(const std::string &key, int v) {
configJson[key] = v;
this->json[key] = v;
}
std::string Config::getString(const std::string &key) {
if(!configJson.contains(key)) {
if (!this->json.contains(key)) {
return "";
}
return configJson.at(key).get_ref<const std::string&>();
return this->json.at(key).get_ref<const std::string&>();
}
void Config::setString(const std::string &key, const std::string &v) {
configJson[key] = v;
this->json[key] = v;
}
+69 -61
View File
@@ -20,7 +20,7 @@
int file_count = 0;
extern bool continueNdsScan;
extern std::unique_ptr<Config> config;
extern uint selectedFile;
extern int keyRepeatDelay;
extern bool dirChanged;
@@ -36,11 +36,10 @@ std::vector<Structs::ButtonPos> buttonPositions = {
{80, 220, 50, 15}, // Select.
{145, 220, 50, 15}, // Refresh.
{210, 220, 50, 15}, // Back.
{0, 0, 25, 25}, // ViewMode Change.
{0, 0, 25, 25} // ViewMode Change.
};
off_t getFileSize(const char *fileName)
{
off_t getFileSize(const char *fileName) {
FILE* fp = fopen(fileName, "rb");
off_t fsize = 0;
if (fp) {
@@ -48,32 +47,36 @@ off_t getFileSize(const char *fileName)
fsize = ftell(fp); // Get source file's size
fseek(fp, 0, SEEK_SET);
}
fclose(fp);
return fsize;
}
bool nameEndsWith(const std::string& name, const std::vector<std::string> extensionList) {
if(name.substr(0, 2) == "._") return false;
if (name.substr(0, 2) == "._") return false;
if(name.size() == 0) return false;
if (name.size() == 0) return false;
if(extensionList.size() == 0) return true;
if (extensionList.size() == 0) return true;
for(int i = 0; i <(int)extensionList.size(); i++) {
for(int i = 0; i < (int)extensionList.size(); i++) {
const std::string ext = extensionList.at(i);
if(strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
}
return false;
}
bool dirEntryPredicate(const DirEntry& lhs, const DirEntry& rhs) {
if(!lhs.isDirectory && rhs.isDirectory) {
if (!lhs.isDirectory && rhs.isDirectory) {
return false;
}
if(lhs.isDirectory && !rhs.isDirectory) {
if (lhs.isDirectory && !rhs.isDirectory) {
return true;
}
return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0;
}
@@ -84,26 +87,28 @@ void getDirectoryContents(std::vector<DirEntry>& dirContents, const std::vector<
DIR *pdir = opendir(".");
if(pdir == NULL) {
if (pdir == NULL) {
Msg::DisplayMsg("Unable to open the directory.");
for(int i=0;i<120;i++) gspWaitForVBlank();
for(int i = 0; i < 120; i++) gspWaitForVBlank();
} else {
while(true) {
DirEntry dirEntry;
struct dirent* pent = readdir(pdir);
if(pent == NULL) break;
if (pent == NULL) break;
stat(pent->d_name, &st);
dirEntry.name = pent->d_name;
dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false;
if(dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) {
if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) {
dirContents.push_back(dirEntry);
}
}
closedir(pdir);
}
sort(dirContents.begin(), dirContents.end(), dirEntryPredicate);
}
@@ -116,9 +121,10 @@ std::vector<std::string> getContents(const std::string &name, const std::vector<
DIR* pdir = opendir(name.c_str());
struct dirent *pent;
while ((pent = readdir(pdir)) != NULL) {
if(nameEndsWith(pent->d_name, extensionList))
if (nameEndsWith(pent->d_name, extensionList))
dirContents.push_back(pent->d_name);
}
closedir(pdir);
return dirContents;
}
@@ -129,12 +135,14 @@ bool returnIfExist(const std::string &path, const std::vector<std::string> &exte
chdir(path.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, extensionList);
for(uint i=0;i<dirContentsTemp.size();i++) {
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
if (dirContents.size() == 0) {
return false;
}
return true;
}
@@ -157,7 +165,7 @@ std::string selectFilePath(std::string selectText, std::string initialPath, cons
chdir(initialPath.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, extensionList);
for(uint i=0;i<dirContentsTemp.size();i++) {
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
selectedFile = 0;
@@ -170,38 +178,38 @@ std::string selectFilePath(std::string selectText, std::string initialPath, cons
GFX::DrawTop();
char path[PATH_MAX];
getcwd(path, PATH_MAX);
if (Config::UseBars == true) {
Gui::DrawString((400-(Gui::GetStringWidth(0.60f, path)))/2, 2, 0.60f, Config::TxtColor, path, 390);
Gui::DrawStringCentered(0, 220, 0.60f, Config::TxtColor, selectText, 390);
if (config->useBars() == true) {
Gui::DrawString((400-(Gui::GetStringWidth(0.60f, path)))/2, 2, 0.60f, config->textColor(), path, 390);
Gui::DrawStringCentered(0, 220, 0.60f, config->textColor(), selectText, 390);
} else {
Gui::DrawString((400-(Gui::GetStringWidth(0.60f, path)))/2, 0, 0.60f, Config::TxtColor, path, 390);
Gui::DrawStringCentered(0, 218, 0.60f, Config::TxtColor, selectText, 390);
Gui::DrawString((400-(Gui::GetStringWidth(0.60f, path)))/2, 0, 0.60f, config->textColor(), path, 390);
Gui::DrawStringCentered(0, 218, 0.60f, config->textColor(), selectText, 390);
}
GFX::DrawBottom();
if (Config::viewMode == 0) {
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)dirContents.size();i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, Config::UnselectedColor);
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)dirContents.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
dirs = dirContents[screenPos + i].name;
if(screenPos + i == selectedFile) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, Config::SelectedColor);
if (screenPos + i == selectedFile) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, WHITE, dirs, 320);
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), dirs, 320);
}
} else if (Config::viewMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)dirContents.size();i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, Config::UnselectedColor);
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)dirContents.size(); i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, config->unselectedColor());
dirs = dirContents[screenPosList + i].name;
if(screenPosList + i == selectedFile) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, Config::SelectedColor);
if (screenPosList + i == selectedFile) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, Config::TxtColor, dirs, 320);
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, config->textColor(), dirs, 320);
}
}
if (Config::UseBars == true) {
Gui::DrawStringCentered(0, 0, 0.45f, Config::TxtColor, Lang::get("FILEBROWSE_MSG"), 260);
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.45f, config->textColor(), Lang::get("FILEBROWSE_MSG"), 260);
} else {
Gui::DrawStringCentered(0, 2, 0.45f, Config::TxtColor, Lang::get("FILEBROWSE_MSG"), 260);
Gui::DrawStringCentered(0, 2, 0.45f, config->textColor(), Lang::get("FILEBROWSE_MSG"), 260);
}
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
@@ -212,10 +220,10 @@ std::string selectFilePath(std::string selectText, std::string initialPath, cons
Gui::Draw_Rect(buttonPositions[4].x, buttonPositions[4].y, buttonPositions[4].w, buttonPositions[4].h, C2D_Color32(0, 0, 0, 190));
Gui::Draw_Rect(buttonPositions[5].x, buttonPositions[5].y, buttonPositions[5].w, buttonPositions[5].h, C2D_Color32(0, 0, 0, 190));
Gui::DrawStringCentered(-120, 222, 0.4, Config::TxtColor, Lang::get("OPEN"), 40);
Gui::DrawStringCentered(-55, 222, 0.4, Config::TxtColor, Lang::get("SELECT"), 40);
Gui::DrawStringCentered(10, 222, 0.4, Config::TxtColor, Lang::get("REFRESH"), 40);
Gui::DrawStringCentered(75, 222, 0.4, Config::TxtColor, Lang::get("BACK"), 40);
Gui::DrawStringCentered(-120, 222, 0.4, config->textColor(), Lang::get("OPEN"), 40);
Gui::DrawStringCentered(-55, 222, 0.4, config->textColor(), Lang::get("SELECT"), 40);
Gui::DrawStringCentered(10, 222, 0.4, config->textColor(), Lang::get("REFRESH"), 40);
Gui::DrawStringCentered(75, 222, 0.4, config->textColor(), Lang::get("BACK"), 40);
C3D_FrameEnd(0);
// The input part.
@@ -228,7 +236,7 @@ std::string selectFilePath(std::string selectText, std::string initialPath, cons
dirContents.clear();
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, extensionList);
for(uint i=0;i<dirContentsTemp.size();i++) {
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
dirChanged = false;
@@ -280,7 +288,7 @@ std::string selectFilePath(std::string selectText, std::string initialPath, cons
if ((hidKeysDown() & KEY_B) || (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[5]))) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
if(strcmp(path, "sdmc:/") == 0 || strcmp(path, "/") == 0) {
if (strcmp(path, "sdmc:/") == 0 || strcmp(path, "/") == 0) {
return "";
} else {
chdir("..");
@@ -308,21 +316,21 @@ std::string selectFilePath(std::string selectText, std::string initialPath, cons
}
// Switch ViewMode.
if ((hidKeysDown() & KEY_Y) || (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[6]))) {
if (Config::viewMode == 0) {
Config::viewMode = 1;
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
Config::viewMode = 0;
config->viewMode(0);
}
}
if (Config::viewMode == 0) {
if(selectedFile < screenPos) {
if (config->viewMode() == 0) {
if (selectedFile < screenPos) {
screenPos = selectedFile;
} else if (selectedFile > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = selectedFile - ENTRIES_PER_SCREEN + 1;
}
} else if (Config::viewMode == 1) {
if(selectedFile < screenPosList) {
} else if (config->viewMode() == 1) {
if (selectedFile < screenPosList) {
screenPosList = selectedFile;
} else if (selectedFile > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = selectedFile - ENTRIES_PER_LIST + 1;
@@ -338,16 +346,16 @@ u32 copyBuf[copyBufSize];
void dirCopy(DirEntry* entry, int i, const char *destinationPath, const char *sourcePath) {
std::vector<DirEntry> dirContents;
dirContents.clear();
if(entry->isDirectory) chdir((sourcePath + ("/" + entry->name)).c_str());
if (entry->isDirectory) chdir((sourcePath + ("/" + entry->name)).c_str());
getDirectoryContents(dirContents);
if(((int)dirContents.size()) == 1) mkdir((destinationPath + ("/" + entry->name)).c_str(), 0777);
if(((int)dirContents.size()) != 1) fcopy((sourcePath + ("/" + entry->name)).c_str(), (destinationPath + ("/" + entry->name)).c_str());
if (((int)dirContents.size()) == 1) mkdir((destinationPath + ("/" + entry->name)).c_str(), 0777);
if (((int)dirContents.size()) != 1) fcopy((sourcePath + ("/" + entry->name)).c_str(), (destinationPath + ("/" + entry->name)).c_str());
}
int fcopy(const char *sourcePath, const char *destinationPath) {
DIR *isDir = opendir(sourcePath);
if(isDir != NULL) {
if (isDir != NULL) {
closedir(isDir);
// Source path is a directory
@@ -372,7 +380,7 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
// Source path is a file
FILE* sourceFile = fopen(sourcePath, "rb");
off_t fsize = 0;
if(sourceFile) {
if (sourceFile) {
fseek(sourceFile, 0, SEEK_END);
fsize = ftell(sourceFile); // Get source file's size
fseek(sourceFile, 0, SEEK_SET);
@@ -382,7 +390,7 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
}
FILE* destinationFile = fopen(destinationPath, "wb");
//if(destinationFile) {
//if (destinationFile) {
fseek(destinationFile, 0, SEEK_SET);
/*} else {
fclose(sourceFile);
@@ -392,16 +400,16 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
off_t offset = 0;
int numr;
while(1)
{
while(1) {
scanKeys();
if(keysHeld() & KEY_B) {
if (keysHeld() & KEY_B) {
// Cancel copying
fclose(sourceFile);
fclose(destinationFile);
return -1;
break;
}
printf("\x1b[16;0H");
printf("Progress:\n");
printf("%i/%i Bytes ", (int)offset, (int)fsize);
@@ -411,7 +419,7 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
fwrite(copyBuf, 2, numr, destinationFile);
offset += copyBufSize;
if(offset > fsize) {
if (offset > fsize) {
fclose(sourceFile);
fclose(destinationFile);