mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
Universal-Updater Full Rewrite based of UniStore v3.0.0. (#51)
* No Nightlies for the Full-Rewrite. * Initial push, i guess. * Forgot to push the Test UniStore + T3X... * Use C2D flags for wrapping and centering * gitignore t3x correctly * Remove Test Store and hardcode to `sdmc:/3ds/Universal-Updater/stores/Universal-DB.unistore` for now. * Is functional now. * *More special checks and work.* * const <typename T> &. * Universal-DB, not Universal DB. * Derp. * Make 3DSX, NDS & Archive path configurable. * Last fixes + Fade out screen on exit. * See Desc. for more. - Add QR Code scan for downloading UniStores. - Add new Graphics. - Some fixes + improvements. * Fix search filtering, re-sort after search * Fix update check * Clear search items with X, not just reset results * The next progress. * PLEASE tell me, this is the only error.. Co-authored-by: Pk11 <epicpkmn11@outlook.com>
This commit is contained in:
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "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 = {
|
||||
"_mapple²",
|
||||
"AlbertCoolGuy",
|
||||
"antoine62",
|
||||
"Chips",
|
||||
"cooolgamer",
|
||||
"David Pires",
|
||||
"FlameKat53",
|
||||
"lemonnade0",
|
||||
"LinuxCat",
|
||||
"Pavel",
|
||||
"Pk11",
|
||||
"Roby Spia",
|
||||
"SuperSaiyajinStackZ",
|
||||
"XDgierman",
|
||||
"YoSoy",
|
||||
"XxPhoenix1996xX"
|
||||
};
|
||||
|
||||
const std::vector<std::string> Languages = {
|
||||
"Русский",
|
||||
"Dansk",
|
||||
"Français",
|
||||
"Português",
|
||||
"Français",
|
||||
"Português",
|
||||
"Bruh",
|
||||
"Lietuvių",
|
||||
"Français",
|
||||
"Русский",
|
||||
"日本語",
|
||||
"Italiano",
|
||||
"Deutsch, English",
|
||||
"Polski",
|
||||
"Español",
|
||||
"Español, Italian, Portuguese"
|
||||
};
|
||||
|
||||
// Universal-Team Page 2.
|
||||
const std::vector<std::string> UniversalTeam = {
|
||||
"DeadPhoenix",
|
||||
"FlameKat53",
|
||||
"NightScript",
|
||||
"Pk11",
|
||||
"RocketRobz",
|
||||
"SuperSaiyajinStackZ",
|
||||
"TotallyNotGuy"
|
||||
};
|
||||
|
||||
// Script Page 3.
|
||||
const std::vector<std::string> ScriptCreators = {
|
||||
"cooolgamer", "DualBladedKirito", "Glazed_Belmont", "Pk11", "SuperSaiyajinStackZ", "The Conceptionist", "YoSoy"
|
||||
};
|
||||
const std::vector<std::string> ScriptAmount = {"1", "1", "1", "1", "5", "10", "1 | 2"};
|
||||
|
||||
const std::vector<std::string> specialNames = {
|
||||
"devkitPro", "NightScript"
|
||||
};
|
||||
const std::vector<std::string> specialDescriptions = {
|
||||
"For devkitARM, Libctru, Citro2D, Citro3D and the portlibs.",
|
||||
"For posting updates on Reddit."
|
||||
};
|
||||
|
||||
void Credits::Draw(void) const {
|
||||
std::string title = "Universal-Updater - ";
|
||||
title += Lang::get("CREDITS");
|
||||
GFX::DrawTop();
|
||||
if (creditsPage != 4) {
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), title, 400);
|
||||
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_stackZ_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->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
|
||||
}
|
||||
|
||||
void Credits::DrawBottom(void) const {
|
||||
std::string line1;
|
||||
std::string line2;
|
||||
|
||||
GFX::DrawBottom();
|
||||
if (creditsPage == 0) {
|
||||
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());
|
||||
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::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->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());
|
||||
line1 = UniversalTeam[screenPos + i];
|
||||
if (screenPos + i == Selection) {
|
||||
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
|
||||
}
|
||||
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), line1, 320);
|
||||
}
|
||||
} else if (creditsPage == 2) {
|
||||
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());
|
||||
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::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 == 3) {
|
||||
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), "Special Thanks", 320);
|
||||
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)specialNames.size(); i++) {
|
||||
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
|
||||
line1 = specialNames[screenPos + i];
|
||||
line2 = specialDescriptions[screenPos + i];
|
||||
if (screenPos + i == Selection) {
|
||||
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
|
||||
}
|
||||
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
|
||||
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
|
||||
}
|
||||
} else {
|
||||
Gui::DrawStringCentered(0, -2, 0.55f, config->textColor(), Lang::get("LINK"), 320);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (keyRepeatDelay) keyRepeatDelay--;
|
||||
// KEY_DOWN Logic. (SIZE)
|
||||
if (creditsPage == 0) {
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
|
||||
if (Selection < (int)Translators.size()-1) {
|
||||
Selection++;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
} else if (creditsPage == 1) {
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
|
||||
if (Selection < (int)UniversalTeam.size()-1) {
|
||||
Selection++;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
} else if (creditsPage == 2) {
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
|
||||
if (Selection < (int)ScriptCreators.size()-1) {
|
||||
Selection++;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
} else if (creditsPage == 3) {
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
|
||||
if (Selection < (int)specialNames.size()-1) {
|
||||
Selection++;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
|
||||
if (Selection > 0) {
|
||||
Selection--;
|
||||
} else {
|
||||
if (creditsPage == 0) {
|
||||
Selection = (int)Translators.size()-1;
|
||||
} else if (creditsPage == 1) {
|
||||
Selection = (int)UniversalTeam.size()-1;
|
||||
} else if (creditsPage == 2) {
|
||||
Selection = (int)ScriptCreators.size()-1;
|
||||
} else if (creditsPage == 3) {
|
||||
Selection = (int)specialNames.size()-1;
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
|
||||
if ((hDown & KEY_L || hDown & KEY_LEFT)) {
|
||||
if (creditsPage > 0) {
|
||||
Selection = 0;
|
||||
creditsPage--;
|
||||
}
|
||||
}
|
||||
|
||||
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
|
||||
if (creditsPage < 4) {
|
||||
Selection = 0;
|
||||
creditsPage++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_B) {
|
||||
Gui::screenBack(config->screenFade());
|
||||
return;
|
||||
}
|
||||
|
||||
if (Selection < screenPos) {
|
||||
screenPos = Selection;
|
||||
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
|
||||
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "config.hpp"
|
||||
#include "credits.hpp"
|
||||
#include "mainMenu.hpp"
|
||||
#include "scriptHelper.hpp"
|
||||
#include "scriptlist.hpp"
|
||||
#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;
|
||||
extern bool fadein;
|
||||
extern u32 TextColor;
|
||||
|
||||
void MainMenu::Draw(void) const {
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), "Universal-Updater", 400);
|
||||
Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, config->textColor(), V_STRING);
|
||||
GFX::DrawSprite(sprites_universal_updater_idx, 110, 30);
|
||||
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);
|
||||
|
||||
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, "UniStore");
|
||||
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("SCRIPTS"));
|
||||
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("SETTINGS"));
|
||||
GFX::DrawButton(mainButtons[3].x, mainButtons[3].y, Lang::get("CREDITS"));
|
||||
// Selector.
|
||||
Animation::Button(mainButtons[Selection].x, mainButtons[Selection].y, .060);
|
||||
|
||||
// Draw UniStore Icon. ;P
|
||||
//GFX::DrawSprite(sprites_uniStore_idx, 10, 65);
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
}
|
||||
|
||||
void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if ((hDown & KEY_START) || (hDown & KEY_TOUCH && touching(touch, mainButtons[4]))) {
|
||||
fadeout = true;
|
||||
fadecolor = 0;
|
||||
exiting = true;
|
||||
}
|
||||
|
||||
// Navigation.
|
||||
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) {
|
||||
if (!(Selection%2)) Selection++;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
switch(Selection) {
|
||||
case 0:
|
||||
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), config->screenFade(), true);
|
||||
break;
|
||||
case 1:
|
||||
Gui::setScreen(std::make_unique<ScriptList>(), config->screenFade(), true);
|
||||
break;
|
||||
case 2:
|
||||
Gui::setScreen(std::make_unique<Settings>(), config->screenFade(), true);
|
||||
break;
|
||||
case 3:
|
||||
Gui::setScreen(std::make_unique<Credits>(), config->screenFade(), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, mainButtons[0])) {
|
||||
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->screenFade(), true);
|
||||
} else if (touching(touch, mainButtons[2])) {
|
||||
Gui::setScreen(std::make_unique<Settings>(), config->screenFade(), true);
|
||||
} else if (touching(touch, mainButtons[3])) {
|
||||
Gui::setScreen(std::make_unique<Credits>(), config->screenFade(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "download.hpp"
|
||||
#include "mainScreen.hpp"
|
||||
#include "storeUtils.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
extern int fadeAlpha;
|
||||
extern u32 hRepeat;
|
||||
|
||||
/*
|
||||
MainScreen Constructor.
|
||||
|
||||
Initialized Meta, Store and StoreEntry class and:
|
||||
|
||||
- Downloads Universal-DB.. in case nothing exist.
|
||||
*/
|
||||
MainScreen::MainScreen() {
|
||||
this->meta = std::make_unique<Meta>();
|
||||
|
||||
/* Check if lastStore is accessible. */
|
||||
if (config->lastStore() != "universal-db-beta.unistore" || config->lastStore() != "") {
|
||||
if (access((std::string(_STORE_PATH) + config->lastStore()).c_str(), F_OK) != 0) {
|
||||
config->lastStore("universal-db-beta.unistore");
|
||||
}
|
||||
}
|
||||
|
||||
/* If Universal DB --> Get! */
|
||||
if (config->lastStore() == "universal-db-beta.unistore" || config->lastStore() == "") {
|
||||
if (access("sdmc:/3ds/Universal-Updater/stores/universal-db-beta.unistore", F_OK) != 0) {
|
||||
std::string tmp = "";
|
||||
DownloadUniStore("https://db.universal-team.net/unistore/universal-db-beta.unistore", -1, tmp, true, true);
|
||||
DownloadSpriteSheet("https://db.universal-team.net/unistore/universal-db.t3x", "universal-db.t3x");
|
||||
}
|
||||
}
|
||||
|
||||
this->store = std::make_unique<Store>(_STORE_PATH + config->lastStore());
|
||||
StoreUtils::ResetAll(this->store, this->meta, this->entries);
|
||||
StoreUtils::SortEntries(false, SortType::LAST_UPDATED, this->entries);
|
||||
};
|
||||
|
||||
/*
|
||||
MainScreen Main Draw.
|
||||
*/
|
||||
void MainScreen::Draw(void) const {
|
||||
GFX::DrawTop();
|
||||
if (this->store && this->store->GetValid()) Gui::DrawStringCentered(0, 1, 0.7, TEXT_COLOR, this->store->GetUniStoreTitle());
|
||||
else Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, Lang::get("INVALID_UNISTORE"), 370);
|
||||
config->list() ? StoreUtils::DrawList(this->store, this->entries) : StoreUtils::DrawGrid(this->store, this->entries);
|
||||
|
||||
if (fadeAlpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, fadeAlpha));
|
||||
GFX::DrawBottom();
|
||||
|
||||
switch(this->storeMode) {
|
||||
case 0:
|
||||
/* Entry Info. */
|
||||
if (this->store && this->store->GetValid() && this->entries.size() > 0) StoreUtils::DrawEntryInfo(this->store, this->entries[this->store->GetEntry()]);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* Download List. */
|
||||
StoreUtils::DrawDownList(this->store, this->dwnldList, this->fetchDown);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* Search + Favorites. */
|
||||
StoreUtils::DrawSearchMenu(this->searchIncludes, this->searchResult, this->marks, this->updateFilter);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
/* Sorting. */
|
||||
StoreUtils::DrawSorting(this->ascending, this->sorttype);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
/* Settings. */
|
||||
StoreUtils::DrawSettings(this->sPage, this->sSelection);
|
||||
break;
|
||||
}
|
||||
|
||||
StoreUtils::DrawSideMenu(this->storeMode);
|
||||
if (this->showMarks && this->store && this->store->GetValid()) StoreUtils::DisplayMarkBox(this->entries[this->store->GetEntry()]->GetMarks());
|
||||
if (fadeAlpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, fadeAlpha));
|
||||
}
|
||||
|
||||
/*
|
||||
MainScreen Logic.
|
||||
*/
|
||||
void MainScreen::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (this->showMarks) StoreUtils::MarkHandle(hDown, hHeld, touch, this->entries[this->store->GetEntry()], this->store, this->showMarks, this->meta);
|
||||
|
||||
if (!this->showMarks) {
|
||||
if (this->storeMode == 0 || this->storeMode == 2 || this->storeMode == 3) {
|
||||
config->list() ? StoreUtils::ListLogic(hDown, hHeld, touch, this->store, this->entries, this->storeMode, this->lastMode, this->fetchDown, this->smallDelay) : StoreUtils::GridLogic(hDown, hHeld, touch, this->store, this->entries, this->storeMode, this->lastMode, this->fetchDown, this->smallDelay);
|
||||
}
|
||||
|
||||
StoreUtils::SideMenuHandle(hDown, touch, this->storeMode, this->fetchDown);
|
||||
|
||||
/* Fetch Download list. */
|
||||
if (this->fetchDown) {
|
||||
this->dwnldList.clear();
|
||||
|
||||
if (this->store && this->store->GetValid()) {
|
||||
this->store->SetDownloadIndex(0); // Reset to 0.
|
||||
this->store->SetDownloadSIndex(0);
|
||||
|
||||
if ((int)this->entries.size() > this->store->GetEntry()) {
|
||||
this->dwnldList = this->store->GetDownloadList(this->entries[this->store->GetEntry()]->GetEntryIndex());
|
||||
}
|
||||
}
|
||||
|
||||
this->fetchDown = false;
|
||||
}
|
||||
|
||||
switch(this->storeMode) {
|
||||
case 0:
|
||||
if (this->store && this->store->GetValid()) StoreUtils::EntryHandle(hDown, hHeld, touch, this->showMarks, this->fetchDown);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (this->store && this->store->GetValid()) StoreUtils::DownloadHandle(hDown, hHeld, touch, this->store, this->entries[this->store->GetEntry()], this->dwnldList, this->storeMode, this->meta, this->lastMode, this->smallDelay);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
StoreUtils::SearchHandle(hDown, hHeld, touch, this->store, this->entries, this->searchIncludes, this->meta, this->searchResult, this->marks, this->updateFilter, this->ascending, this->sorttype);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
StoreUtils::SortHandle(hDown, hHeld, touch, this->store, this->entries, this->ascending, this->sorttype);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
StoreUtils::SettingsHandle(hDown, hHeld, touch, this->sPage, this->showSettings, this->storeMode, this->sSelection, this->store, this->entries, this->meta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,527 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "download.hpp"
|
||||
#include "fileBrowse.hpp"
|
||||
#include "json.hpp"
|
||||
#include "scriptBrowse.hpp"
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json infoFromScript(const std::string &path) {
|
||||
nlohmann::json in, out;
|
||||
|
||||
FILE* file = fopen(path.c_str(), "r");
|
||||
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"];
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void findExistingFiles(nlohmann::json &json) {
|
||||
nlohmann::json current;
|
||||
chdir(config->scriptPath().c_str());
|
||||
std::vector<DirEntry> dirContents;
|
||||
getDirectoryContents(dirContents);
|
||||
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"]) {
|
||||
json[i]["curRevision"] = current[j]["revision"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScriptBrowse::ScriptBrowse() {
|
||||
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
|
||||
|
||||
// Get repo info
|
||||
if (downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile) != 0) {
|
||||
downloadFailed();
|
||||
loaded = false;
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* file = fopen(metaFile, "r");
|
||||
if (file) {
|
||||
infoJson = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
fixInfo(infoJson);
|
||||
findExistingFiles(infoJson);
|
||||
maxScripts = infoJson.size();
|
||||
loaded = true;
|
||||
// File is not able to be parsed, go screen back.
|
||||
} else {
|
||||
loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptBrowse::refresh() {
|
||||
if (checkWifiStatus() == true) {
|
||||
if (Msg::promptMsg(Lang::get("REFRESH_SCRIPTBROWSE_PROMPT"))) {
|
||||
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
|
||||
if (downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile) != 0) {
|
||||
downloadFailed();
|
||||
loaded = false;
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* file = fopen(metaFile, "r");
|
||||
if (file) {
|
||||
infoJson = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
fixInfo(infoJson);
|
||||
findExistingFiles(infoJson);
|
||||
maxScripts = infoJson.size();
|
||||
Selection = 0;
|
||||
loaded = true;
|
||||
} else {
|
||||
loaded = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
notConnectedMsg();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptBrowse::Draw(void) const {
|
||||
if (mode == 0) {
|
||||
DrawBrowse();
|
||||
} else {
|
||||
DrawGlossary();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptBrowse::DrawBrowse(void) const {
|
||||
GFX::DrawTop();
|
||||
if (loaded) {
|
||||
std::string revision = std::to_string(int64_t(infoJson[Selection]["curRevision"]));
|
||||
revision += " | ";
|
||||
revision += std::to_string(int64_t(infoJson[Selection]["revision"]));
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), std::string(infoJson[Selection]["title"]), 400);
|
||||
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.6f, revision), 0.6f, config->textColor(), revision);
|
||||
|
||||
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->textColor(), Lang::get("SCRIPT_NOT_FOUND"), 370);
|
||||
} else if(infoJson[Selection]["curRevision"] < infoJson[Selection]["revision"]) {
|
||||
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->textColor(), Lang::get("UP-TO-DATE"), 370);
|
||||
} else if(infoJson[Selection]["curRevision"] > infoJson[Selection]["revision"]) {
|
||||
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);
|
||||
GFX::DrawArrow(315, 240, 180.0);
|
||||
GFX::DrawArrow(0, 218, 0, 1);
|
||||
|
||||
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
|
||||
|
||||
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 (!dropDownMenu) {
|
||||
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->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->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) {
|
||||
if (!dropDownMenu) {
|
||||
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->notfoundColor());
|
||||
// Script outdaed.
|
||||
} 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->uptodateColor());
|
||||
// Future script.
|
||||
} 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->textColor(), infoJson[screenPosList+i]["title"], 317);
|
||||
}
|
||||
}
|
||||
|
||||
// DropDown Menu.
|
||||
if (dropDownMenu) {
|
||||
// Draw Operation Box.
|
||||
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());
|
||||
} else {
|
||||
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, config->unselectedColor());
|
||||
}
|
||||
}
|
||||
// Draw Dropdown Icons.
|
||||
GFX::DrawSpriteBlend(sprites_download_all_idx, dropPos[0].x, dropPos[0].y);
|
||||
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->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 {
|
||||
GFX::DrawBottom();
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScriptBrowse::DrawGlossary(void) const {
|
||||
GFX::DrawTop();
|
||||
if (loaded) {
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("GLOSSARY"), 400);
|
||||
|
||||
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->outdatedColor());
|
||||
Gui::DrawString(65, 75, 0.7f, config->textColor(), Lang::get("OUTDATED_SCRIPT"), 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->futureColor());
|
||||
Gui::DrawString(65, 155, 0.7f, config->textColor(), Lang::get("FUTURE_SCRIPT"), 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->textColor(), Lang::get("DOWNLOAD_ALL"), 260);
|
||||
GFX::DrawSpriteBlend(sprites_view_idx, 20, 55);
|
||||
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->textColor(), Lang::get("ENTRY_UP"), 260);
|
||||
GFX::DrawArrow(42, 140, 180.0);
|
||||
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->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->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 {
|
||||
GFX::DrawBottom();
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (loaded) {
|
||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||
dropDownMenu = false;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (dropSelection < 2) dropSelection++;
|
||||
}
|
||||
|
||||
if (hDown & KEY_UP) {
|
||||
if (dropSelection > 0) dropSelection--;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
switch(dropSelection) {
|
||||
case 0:
|
||||
downloadAll();
|
||||
break;
|
||||
case 1:
|
||||
refresh();
|
||||
break;
|
||||
case 2:
|
||||
if (config->viewMode() == 0) {
|
||||
config->viewMode(1);
|
||||
} else {
|
||||
config->viewMode(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
dropDownMenu = false;
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, dropPos2[0])) {
|
||||
downloadAll();
|
||||
dropDownMenu = false;
|
||||
} else if (touching(touch, dropPos2[1])) {
|
||||
refresh();
|
||||
dropDownMenu = false;
|
||||
} else if (touching(touch, dropPos2[2])) {
|
||||
if (config->viewMode() == 0) {
|
||||
config->viewMode(1);
|
||||
} else {
|
||||
config->viewMode(0);
|
||||
}
|
||||
dropDownMenu = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptBrowse::downloadAll() {
|
||||
if (infoJson.size() > 0) {
|
||||
for (int i = 0; i < (int)infoJson.size(); i++) {
|
||||
int current = i+1;
|
||||
int total = infoJson.size();
|
||||
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[i]["title"]);
|
||||
std::string titleFix = infoJson[i]["title"];
|
||||
for (int l = 0; l < (int)titleFix.size(); l++) {
|
||||
if (titleFix[l] == '/') {
|
||||
titleFix[l] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(fileName + " " + std::to_string(current) + " / " + std::to_string(total));
|
||||
downloadToFile(infoJson[i]["url"], config->scriptPath() + titleFix + ".json");
|
||||
infoJson[i]["curRevision"] = infoJson[i]["revision"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (loaded) {
|
||||
if (keyRepeatDelay) keyRepeatDelay--;
|
||||
if (dropDownMenu) {
|
||||
DropDownLogic(hDown, hHeld, touch);
|
||||
} else {
|
||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
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) {
|
||||
Selection++;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
|
||||
if (config->viewMode() == 0) {
|
||||
if (Selection < (int)infoJson.size()-1-3) {
|
||||
Selection += 3;
|
||||
} else {
|
||||
Selection = (int)infoJson.size()-1;
|
||||
}
|
||||
} else {
|
||||
if (Selection < (int)infoJson.size()-1-6) {
|
||||
Selection += 7;
|
||||
} else {
|
||||
Selection = (int)infoJson.size()-1;
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
|
||||
if (config->viewMode() == 0) {
|
||||
if (Selection > 2) {
|
||||
Selection -= 3;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
} else {
|
||||
if (Selection > 6) {
|
||||
Selection -= 7;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||
dropDownMenu = true;
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
|
||||
if (Selection > 0) {
|
||||
Selection--;
|
||||
} else {
|
||||
Selection = (int)infoJson.size()-1;
|
||||
}
|
||||
|
||||
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 (infoJson.size() != 0) {
|
||||
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPos + i]["title"]);
|
||||
std::string titleFix = infoJson[screenPos + i]["title"];
|
||||
for (int l = 0; l < (int)titleFix.size(); l++) {
|
||||
if (titleFix[l] == '/') {
|
||||
titleFix[l] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(fileName);
|
||||
downloadToFile(infoJson[screenPos + i]["url"], config->scriptPath() + titleFix + ".json");
|
||||
infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (config->viewMode() == 1) {
|
||||
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)infoJson.size(); i++) {
|
||||
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
|
||||
if (infoJson.size() != 0) {
|
||||
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPosList + i]["title"]);
|
||||
std::string titleFix = infoJson[screenPosList + i]["title"];
|
||||
for (int l = 0; l < (int)titleFix.size(); l++) {
|
||||
if (titleFix[l] == '/') {
|
||||
titleFix[l] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(fileName);
|
||||
downloadToFile(infoJson[screenPosList + i]["url"], config->scriptPath() + titleFix + ".json");
|
||||
infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
if (infoJson.size() != 0) {
|
||||
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[Selection]["title"]);
|
||||
|
||||
std::string titleFix = infoJson[Selection]["title"];
|
||||
for (int i = 0; i < (int)titleFix.size(); i++) {
|
||||
if (titleFix[i] == '/') {
|
||||
titleFix[i] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(fileName);
|
||||
downloadToFile(infoJson[Selection]["url"], config->scriptPath() + titleFix + ".json");
|
||||
infoJson[Selection]["curRevision"] = infoJson[Selection]["revision"];
|
||||
}
|
||||
}
|
||||
|
||||
if (config->viewMode() == 0) {
|
||||
if(Selection < screenPos) {
|
||||
screenPos = Selection;
|
||||
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
|
||||
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
|
||||
}
|
||||
} else if (config->viewMode() == 1) {
|
||||
if(Selection < screenPosList) {
|
||||
screenPosList = Selection;
|
||||
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
|
||||
screenPosList = Selection - ENTRIES_PER_LIST + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Switch to Glossary and back.
|
||||
if (hDown & KEY_R || hDown & KEY_L) {
|
||||
if (mode == 0) mode = 1;
|
||||
else mode = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hDown & KEY_B) {
|
||||
Gui::screenBack(config->screenFade());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,592 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "fileBrowse.hpp"
|
||||
#include "keyboard.hpp"
|
||||
#include "logging.hpp"
|
||||
#include "scriptCreator.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
|
||||
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||
extern std::unique_ptr<Config> config;
|
||||
|
||||
void ScriptCreator::openJson(std::string fileName) {
|
||||
std::string scriptFile = fileName;
|
||||
FILE* file = fopen(scriptFile.c_str(), "r");
|
||||
fseek(file, 0, SEEK_END);
|
||||
size_t size = ftell(file);
|
||||
fseek (file, 0, SEEK_SET);
|
||||
char data[size + 1];
|
||||
fread(data, 1, size, file);
|
||||
data[size] = '\0';
|
||||
fclose(file);
|
||||
this->editScript = nlohmann::json::parse((char*)data, nullptr, false);
|
||||
}
|
||||
|
||||
// BOOL.
|
||||
void ScriptCreator::setBool(const std::string &object, const std::string &key, bool v) {
|
||||
this->editScript[object][key] = v;
|
||||
}
|
||||
void ScriptCreator::setBool2(const std::string &object, const std::string &key, const std::string &key2, bool v) {
|
||||
this->editScript[object][key][key2] = v;
|
||||
}
|
||||
|
||||
|
||||
// INT.
|
||||
void ScriptCreator::setInt(const std::string &object, const std::string &key, int v) {
|
||||
this->editScript[object][key] = v;
|
||||
}
|
||||
void ScriptCreator::setInt2(const std::string &object, const std::string &key, const std::string &key2, int v) {
|
||||
this->editScript[object][key][key2] = v;
|
||||
}
|
||||
|
||||
// STRING
|
||||
void ScriptCreator::setString(const std::string &object, const std::string &key, const std::string &v) {
|
||||
this->editScript[object][key] = v;
|
||||
}
|
||||
void ScriptCreator::setString2(const std::string &object, const std::string &key, const std::string &key2, const std::string &v) {
|
||||
this->editScript[object][key][key2] = v;
|
||||
}
|
||||
|
||||
void ScriptCreator::Draw(void) const {
|
||||
if (this->mode == 0) {
|
||||
this->DrawSubMenu();
|
||||
} else if (this->mode == 1) {
|
||||
this->DrawScriptScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptCreator::DrawSubMenu(void) const {
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 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 (this->Selection == i) {
|
||||
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::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();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 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 < 3; i++) {
|
||||
if (i == this->page) {
|
||||
Gui::DrawStringCentered(0, 3, 0.6f, config->textColor(), std::to_string(i+1) + " | 3", 140);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->page == 0) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (this->Selection == i) {
|
||||
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::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 (this->page == 1) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (this->Selection == i) {
|
||||
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::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);
|
||||
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "saveConfig"))/2+150-70, creatorButtons[3].y+10, 0.6f, config->textColor(), "saveConfig", 140);
|
||||
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "bootTitle"))/2-150+70, creatorButtons[4].y+10, 0.6f, config->textColor(), "bootTitle", 140);
|
||||
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "promptMsg"))/2+150-70, creatorButtons[5].y+10, 0.6f, config->textColor(), "promptMsg", 140);
|
||||
|
||||
} else if (this->page == 2) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (this->Selection == i) {
|
||||
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::DrawString((320-Gui::GetStringWidth(0.6f, "copy"))/2-150+70, creatorButtons[0].y+10, 0.6f, config->textColor(), "copy", 140);
|
||||
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "move"))/2+150-70, creatorButtons[1].y+10, 0.6f, config->textColor(), "move", 140);
|
||||
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "change Entry"))/2-150+70, creatorButtons[2].y+10, 0.6f, config->textColor(), "change Entry", 140);
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptCreator::createNewJson(std::string fileName) {
|
||||
std::ofstream ofstream;
|
||||
ofstream.open(fileName.c_str(), std::ofstream::out | std::ofstream::app);
|
||||
ofstream << "{ }";
|
||||
ofstream.close();
|
||||
}
|
||||
|
||||
// Test.
|
||||
void ScriptCreator::createDownloadRelease() {
|
||||
// Repo.
|
||||
std::string repo = Input::setkbdString(50, "Enter the name of the Owner.");
|
||||
repo += "/";
|
||||
repo += Input::setkbdString(50, "Enter the name of the repo.");
|
||||
// File.
|
||||
std::string file = Input::setkbdString(50, "Enter the name of the file.");
|
||||
// Output.
|
||||
std::string output = Input::setkbdString(50, "Enter the name of the Output path.");
|
||||
// Prerelease.
|
||||
bool prerelease = true;
|
||||
// Message.
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "downloadRelease"}, {"repo", repo}, {"file", file}, {"output", output}, {"includePrerelease", prerelease}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createDownloadRelease();'.");
|
||||
}
|
||||
|
||||
// To-Do.
|
||||
|
||||
void ScriptCreator::createDownloadFile() {
|
||||
// URL of the file.
|
||||
std::string file = Input::setkbdString(50, "Enter the URL of the file.");
|
||||
// Output.
|
||||
std::string output = Input::setkbdString(50, "Enter the name of the Output path.");
|
||||
// Message.
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "downloadFile"}, {"file", file}, {"output", output}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createDownloadFile();'.");
|
||||
}
|
||||
|
||||
|
||||
void ScriptCreator::createDeleteFile() {
|
||||
// URL of the file.
|
||||
std::string file = Input::setkbdString(50, "Enter the path to the file.");
|
||||
// Message.
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "deleteFile"}, {"file", file}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createDeleteFile();'.");
|
||||
}
|
||||
|
||||
|
||||
void ScriptCreator::createExtractFile() {
|
||||
// File path.
|
||||
std::string file = Input::setkbdString(50, "Enter the path to the file.");
|
||||
// Input of the archive.
|
||||
std::string input = Input::setkbdString(50, "Enter the Input of what should be extracted.");
|
||||
// Output path.
|
||||
std::string output = Input::setkbdString(50, "Enter the output path.");
|
||||
// Message.
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "extractFile"}, {"file", file}, {"input", input}, {"output", output}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createExtractFile();'.");
|
||||
}
|
||||
|
||||
|
||||
void ScriptCreator::createInstallCia() {
|
||||
// File path.
|
||||
std::string file = Input::setkbdString(50, "Enter the path to the CIA File.");
|
||||
// Message.
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "installCia"}, {"file", file}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createInstallCia();'.");
|
||||
}
|
||||
|
||||
|
||||
void ScriptCreator::createMkDir() {
|
||||
// Directory path.
|
||||
std::string directory = Input::setkbdString(50, "Enter the directory path.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "mkdir"}, {"directory", directory}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createMkDir();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createRmDir() {
|
||||
// Directory path.
|
||||
std::string directory = Input::setkbdString(50, "Enter the directory path.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "rmdir"}, {"directory", directory}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createRmDir();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createMkFile() {
|
||||
// File path.
|
||||
std::string file = Input::setkbdString(50, "Enter the path to the new File.");
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "mkfile"}, {"file", file}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createMkFile();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createTimeMsg() {
|
||||
int seconds = 0;
|
||||
// Message.
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
// Seconds.
|
||||
int temp = Input::setInt(999, "Enter the Seconds for the Message to display.");
|
||||
if (temp != -1) seconds = temp;
|
||||
|
||||
this->editScript[this->entryName].push_back({{"type", "timeMsg"}, {"message", message}, {"seconds", seconds}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createTimeMsg();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createSaveConfig() {
|
||||
this->editScript[this->entryName].push_back({{"type", "saveConfig"}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createSaveConfig();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createBootTitle() {
|
||||
std::string titleID = Input::setkbdString(50, "Enter the TitleID.");
|
||||
bool isNAND = Msg::promptMsg("Is the current title a NAND title?");
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
this->editScript[this->entryName].push_back({{"type", "bootTitle"}, {"TitleID", titleID}, {"NAND", isNAND}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createBootTitle();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createPromptMessage() {
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
this->editScript[this->entryName].push_back({{"type", "promptMessage"}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createPromptMessage();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createCopy() {
|
||||
std::string source = Input::setkbdString(50, "Enter the source location.");
|
||||
std::string destination = Input::setkbdString(50, "Enter the destination location.");
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
this->editScript[this->entryName].push_back({{"type", "copy"}, {"source", source}, {"destination", destination}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createCopy();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::createMove() {
|
||||
std::string oldLocation = Input::setkbdString(50, "Enter the old location.");
|
||||
std::string newLocation = Input::setkbdString(50, "Enter the new location.");
|
||||
std::string message = Input::setkbdString(50, "Enter the Message.");
|
||||
this->editScript[this->entryName].push_back({{"type", "move"}, {"old", oldLocation}, {"new", newLocation}, {"message", message}});
|
||||
Logging::writeToLog("Execute 'ScriptCreator::createMove();'.");
|
||||
}
|
||||
|
||||
void ScriptCreator::save() {
|
||||
FILE* file = fopen(this->jsonFileName.c_str(), "w");
|
||||
std::string result = this->editScript.dump(1, '\t');
|
||||
if (file) fwrite(result.c_str(), 1, this->editScript.dump(1, '\t').size(), file);
|
||||
fclose(file);
|
||||
Logging::writeToLog("Execute 'ScriptCreator::save();'.");
|
||||
}
|
||||
|
||||
// Important to make Scripts valid.
|
||||
void ScriptCreator::setInfoStuff(void) {
|
||||
// Get needed things.
|
||||
const std::string test = Input::setkbdString(50, "Enter the Title of the script.");
|
||||
const std::string test2 = Input::setkbdString(50, "Enter the Author name of the script.");
|
||||
const std::string test3 = Input::setkbdString(80, "Enter the short description of the script.");
|
||||
const std::string test4 = Input::setkbdString(300, "Enter the long description of the script.");
|
||||
int scriptRevision = Input::setInt(99, "Enter the script revision.");
|
||||
// Set the real JSON stuff.
|
||||
this->setString("info", "title", test);
|
||||
this->setString("info", "author", test2);
|
||||
this->setString("info", "shortDesc", test3);
|
||||
this->setString("info", "description", test4);
|
||||
this->setInt("info", "version", SCRIPT_VERSION);
|
||||
if (scriptRevision != -1) {
|
||||
this->setInt("info", "revision", scriptRevision);
|
||||
} else {
|
||||
this->setInt("info", "revision", 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScriptCreator::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (hDown & KEY_B) {
|
||||
Gui::screenBack(config->screenFade());
|
||||
return;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
switch(Selection) {
|
||||
case 0:
|
||||
this->jsonFileName = config->scriptPath();
|
||||
this->jsonFileName += Input::setkbdString(20, "Enter the name of the JSON file.");
|
||||
if (this->jsonFileName != "") {
|
||||
this->jsonFileName += ".json";
|
||||
this->createNewJson(this->jsonFileName);
|
||||
this->openJson(this->jsonFileName);
|
||||
// If not included, create.
|
||||
if (!this->editScript.contains("info")) {
|
||||
this->setInfoStuff();
|
||||
}
|
||||
|
||||
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
|
||||
this->Selection = 0;
|
||||
this->mode = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
std::string tempScript = selectFilePath("Select the Script file.", config->scriptPath(), {"json"}, 2);
|
||||
if (tempScript != "") {
|
||||
this->jsonFileName = tempScript;
|
||||
if (access(this->jsonFileName.c_str(), F_OK) == 0) {
|
||||
this->openJson(this->jsonFileName);
|
||||
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
|
||||
this->Selection = 0;
|
||||
this->mode = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (hDown & KEY_UP) {
|
||||
if (this->Selection == 1) this->Selection = 0;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (this->Selection == 0) this->Selection = 1;
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, mainButtons[0])) {
|
||||
this->jsonFileName = config->scriptPath();
|
||||
this->jsonFileName += Input::setkbdString(20, "Enter the name of the JSON file.");
|
||||
if (this->jsonFileName != "") {
|
||||
this->jsonFileName += ".json";
|
||||
this->createNewJson(this->jsonFileName);
|
||||
this->openJson(this->jsonFileName);
|
||||
// If not included, create.
|
||||
if (!this->editScript.contains("info")) {
|
||||
this->setInfoStuff();
|
||||
}
|
||||
|
||||
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
|
||||
this->Selection = 0;
|
||||
this->mode = 1;
|
||||
}
|
||||
} else if (touching(touch, mainButtons[1])) {
|
||||
std::string tempScript = selectFilePath("Select the Script file.", config->scriptPath(), {"json"}, 2);
|
||||
if (tempScript != "") {
|
||||
this->jsonFileName = tempScript;
|
||||
if (access(this->jsonFileName.c_str(), F_OK) == 0) {
|
||||
this->openJson(this->jsonFileName);
|
||||
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
|
||||
this->Selection = 0;
|
||||
this->mode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptCreator::scriptLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (hDown & KEY_B) {
|
||||
this->save();
|
||||
this->Selection = 0;
|
||||
this->mode = 0;
|
||||
}
|
||||
|
||||
// Page 1.
|
||||
if (this->page == 0 || this->page == 1) {
|
||||
if (hDown & KEY_UP) {
|
||||
if (this->Selection > 1) this->Selection -= 2;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (this->Selection < 4) this->Selection += 2;
|
||||
}
|
||||
|
||||
if (hDown & KEY_LEFT) {
|
||||
if (this->Selection%2) this->Selection--;
|
||||
}
|
||||
|
||||
if (hDown & KEY_RIGHT) {
|
||||
if (!(this->Selection%2)) this->Selection++;
|
||||
}
|
||||
|
||||
} else if (this->page == 2) {
|
||||
if (hDown & KEY_RIGHT) {
|
||||
if (this->Selection == 0) this->Selection = 1;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (this->Selection == 0) this->Selection = 2;
|
||||
}
|
||||
|
||||
if (hDown & KEY_UP) {
|
||||
if (this->Selection == 2) this->Selection = 0;
|
||||
}
|
||||
|
||||
if (hDown & KEY_LEFT) {
|
||||
if (this->Selection == 1) this->Selection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (hDown & KEY_R) {
|
||||
if (this->page < 2) {
|
||||
this->page++;
|
||||
this->Selection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_L) {
|
||||
if (this->page > 0) {
|
||||
this->page--;
|
||||
this->Selection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
if (this->page == 0) {
|
||||
switch(this->Selection) {
|
||||
case 0:
|
||||
this->createDownloadRelease();
|
||||
break;
|
||||
case 1:
|
||||
this->createDownloadFile();
|
||||
break;
|
||||
case 2:
|
||||
this->createDeleteFile();
|
||||
break;
|
||||
case 3:
|
||||
this->createExtractFile();
|
||||
break;
|
||||
case 4:
|
||||
this->createInstallCia();
|
||||
break;
|
||||
case 5:
|
||||
this->createMkDir();
|
||||
break;
|
||||
}
|
||||
} else if (this->page == 1) {
|
||||
switch(this->Selection) {
|
||||
case 0:
|
||||
this->createRmDir();
|
||||
break;
|
||||
case 1:
|
||||
this->createMkFile();
|
||||
break;
|
||||
case 2:
|
||||
this->createTimeMsg();
|
||||
break;
|
||||
case 3:
|
||||
this->createSaveConfig();
|
||||
break;
|
||||
case 4:
|
||||
this->createBootTitle();
|
||||
break;
|
||||
case 5:
|
||||
this->createPromptMessage();
|
||||
break;
|
||||
}
|
||||
} else if (this->page == 2) {
|
||||
switch(this->Selection) {
|
||||
case 0:
|
||||
this->createCopy();
|
||||
break;
|
||||
case 1:
|
||||
this->createMove();
|
||||
break;
|
||||
case 2:
|
||||
this->entryName = Input::setkbdString(50, "Enter the new entry.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (this->page == 0) {
|
||||
if (touching(touch, creatorButtons[0])) {
|
||||
this->createDownloadRelease();
|
||||
} else if (touching(touch, creatorButtons[1])) {
|
||||
this->createDownloadFile();
|
||||
} else if (touching(touch, creatorButtons[2])) {
|
||||
this->createDeleteFile();
|
||||
} else if (touching(touch, creatorButtons[3])) {
|
||||
this->createExtractFile();
|
||||
} else if (touching(touch, creatorButtons[4])) {
|
||||
this->createInstallCia();
|
||||
} else if (touching(touch, creatorButtons[5])) {
|
||||
this->createMkDir();
|
||||
}
|
||||
} else if (this->page == 1) {
|
||||
if (touching(touch, creatorButtons[0])) {
|
||||
this->createRmDir();
|
||||
} else if (touching(touch, creatorButtons[1])) {
|
||||
this->createMkFile();
|
||||
} else if (touching(touch, creatorButtons[2])) {
|
||||
this->createTimeMsg();
|
||||
} else if (touching(touch, creatorButtons[3])) {
|
||||
this->createSaveConfig();
|
||||
} else if (touching(touch, creatorButtons[4])) {
|
||||
this->createBootTitle();
|
||||
} else if (touching(touch, creatorButtons[5])) {
|
||||
this->createPromptMessage();
|
||||
}
|
||||
} else if (this->page == 2) {
|
||||
if (touching(touch, creatorButtons[0])) {
|
||||
this->createCopy();
|
||||
} else if (touching(touch, creatorButtons[1])) {
|
||||
this->createMove();
|
||||
} else if (touching(touch, creatorButtons[2])) {
|
||||
this->entryName = Input::setkbdString(50, "Enter the new entry.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_X) {
|
||||
this->setInfoStuff(); // Probably not needed at all.
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (this->mode == 0) {
|
||||
this->SubMenuLogic(hDown, hHeld, touch);
|
||||
} else if (this->mode == 1) {
|
||||
this->scriptLogic(hDown, hHeld, touch);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,668 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "keyboard.hpp"
|
||||
#include "overlay.hpp"
|
||||
#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; }
|
||||
|
||||
void Settings::Draw(void) const {
|
||||
if (mode == 0) {
|
||||
DrawSubMenu();
|
||||
} else if (mode == 1) {
|
||||
DrawLanguageSelection();
|
||||
} else if (mode == 2) {
|
||||
DrawColorChanging();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Settings::DrawSubMenu(void) const {
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 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);
|
||||
GFX::DrawArrow(318, 240, 180.0, 1);
|
||||
|
||||
if (this->settingPage == 0) {
|
||||
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, Lang::get("LANGUAGE"));
|
||||
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("COLORS"));
|
||||
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("CHANGE_BAR_STYLE"));
|
||||
} else if (this->settingPage == 1) {
|
||||
GFX::DrawButton(mainButtons2[0].x, mainButtons2[0].y, Lang::get("CHANGE_MUSICFILE"));
|
||||
GFX::DrawButton(mainButtons2[1].x, mainButtons2[1].y, Lang::get("CHANGE_KEY_DELAY"));
|
||||
GFX::DrawButton(mainButtons2[2].x, mainButtons2[2].y, Lang::get("TOGGLE_FADE"));
|
||||
GFX::DrawButton(mainButtons2[3].x, mainButtons2[3].y, Lang::get("TOGGLE_PROGRESSBAR"));
|
||||
} else if (this->settingPage == 2) {
|
||||
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, Lang::get("CHANGE_3DSX_PATH"));
|
||||
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("CHANGE_NDS_PATH"));
|
||||
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("CHANGE_ARCHIVE_PATH"));
|
||||
}
|
||||
|
||||
// Selector.
|
||||
if (this->settingPage == 0 || this->settingPage == 2) {
|
||||
Animation::Button(mainButtons[Selection].x, mainButtons[Selection].y, .060);
|
||||
} else {
|
||||
Animation::Button(mainButtons2[Selection].x, mainButtons2[Selection].y, .060);
|
||||
}
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
}
|
||||
|
||||
const std::vector<std::string> languages = {
|
||||
"Bruh",
|
||||
"Dansk",
|
||||
"Deutsch",
|
||||
"English",
|
||||
"Español",
|
||||
"Français",
|
||||
"Italiano",
|
||||
"Lietuvių",
|
||||
"Polski",
|
||||
"Português",
|
||||
"Русский",
|
||||
"日本語"
|
||||
};
|
||||
|
||||
void Settings::DrawLanguageSelection(void) const {
|
||||
std::string line1;
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 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());
|
||||
line1 = languages[screenPos + i];
|
||||
if (screenPos + i == selectedLang) {
|
||||
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
const std::vector<std::string> colorList = {
|
||||
"BAR_COLOR",
|
||||
"TOP_BG_COLOR",
|
||||
"BOTTOM_BG_COLOR",
|
||||
"TEXT_COLOR",
|
||||
"SELECTED_COLOR",
|
||||
"UNSELECTED_COLOR",
|
||||
"PROGRESSBAR_COLOR",
|
||||
"NOT_FOUND_COLOR",
|
||||
"OUTDATED_COLOR",
|
||||
"UPTODATE_COLOR",
|
||||
"FUTURE_COLOR",
|
||||
"BUTTON_COLOR"
|
||||
};
|
||||
|
||||
|
||||
void Settings::DrawColorChanging(void) const {
|
||||
std::string line1;
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 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->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->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->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());
|
||||
} else if (colorMode == 7) {
|
||||
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->outdatedColor());
|
||||
} else if (colorMode == 9) {
|
||||
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->futureColor());
|
||||
} else if (colorMode == 11) {
|
||||
GFX::DrawButton(100, 100, "");
|
||||
}
|
||||
|
||||
Gui::DrawStringCentered(0, 215, 0.7f, WHITE, Lang::get(colorList[colorMode]), 320);
|
||||
}
|
||||
|
||||
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
GFX::DrawBottom();
|
||||
if (!dropDownMenu) {
|
||||
GFX::DrawArrow(0, 218, 0, 1);
|
||||
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[5].x, arrowPos[5].y);
|
||||
}
|
||||
|
||||
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());
|
||||
line1 = Lang::get(colorList[screenPos + i]);
|
||||
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->textColor(), line1, 320);
|
||||
}
|
||||
} else {
|
||||
if (colorMode == 0) {
|
||||
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->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->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->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));
|
||||
} 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));
|
||||
} 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));
|
||||
} else if (colorMode == 7) {
|
||||
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->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->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->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->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
|
||||
}
|
||||
|
||||
|
||||
void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if ((hDown & KEY_B)) {
|
||||
Gui::screenBack(config->screenFade());
|
||||
return;
|
||||
}
|
||||
|
||||
if ((hDown & KEY_R) || (hDown & KEY_TOUCH && touching(touch, arrowPos[4]))) {
|
||||
if (this->settingPage < 2) {
|
||||
this->settingPage++;
|
||||
Selection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((hDown & KEY_L) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
if (this->settingPage > 0) {
|
||||
this->settingPage--;
|
||||
Selection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->settingPage == 0) {
|
||||
if (hDown & KEY_UP) {
|
||||
if (Selection > 0) Selection--;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (Selection < 2) Selection++;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
switch (Selection) {
|
||||
case 0:
|
||||
screenPos = 0;
|
||||
selectedLang = 0;
|
||||
mode = 1;
|
||||
break;
|
||||
case 1:
|
||||
screenPos = 0;
|
||||
mode = 2;
|
||||
break;
|
||||
case 2:
|
||||
if (config->useBars()) config->useBars(false);
|
||||
else config->useBars(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, mainButtons[0])) {
|
||||
screenPos = 0;
|
||||
selectedLang = 0;
|
||||
mode = 1;
|
||||
} else if (touching(touch, mainButtons[1])) {
|
||||
screenPos = 0;
|
||||
mode = 2;
|
||||
} else if (touching(touch, mainButtons[2])) {
|
||||
if (config->useBars()) config->useBars(false);
|
||||
else config->useBars(true);
|
||||
}
|
||||
}
|
||||
} else if (this->settingPage == 1) {
|
||||
if (hDown & KEY_A) {
|
||||
if (Selection == 0) {
|
||||
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2);
|
||||
if (tempMusic != "") {
|
||||
config->musicPath(tempMusic);
|
||||
}
|
||||
} else if (Selection == 1) {
|
||||
int temp = Input::setInt(255, Lang::get("ENTER_KEY_DELAY"));
|
||||
if (temp != -1) config->keyDelay(temp);
|
||||
} else if (Selection == 2) {
|
||||
if (config->screenFade()) {
|
||||
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) {
|
||||
config->screenFade(false);
|
||||
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
|
||||
}
|
||||
} else {
|
||||
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) {
|
||||
config->screenFade(true);
|
||||
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
|
||||
}
|
||||
}
|
||||
} else if (Selection == 3) {
|
||||
if (config->progressDisplay()) {
|
||||
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) {
|
||||
config->progressDisplay(false);
|
||||
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
|
||||
}
|
||||
} else {
|
||||
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) {
|
||||
config->progressDisplay(true);
|
||||
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, mainButtons2[0])) {
|
||||
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2);
|
||||
if (tempMusic != "") {
|
||||
config->musicPath(tempMusic);
|
||||
}
|
||||
} else if (touching(touch, mainButtons2[1])) {
|
||||
int temp = Input::setInt(255, Lang::get("ENTER_KEY_DELAY"));
|
||||
if (temp != -1) config->keyDelay(temp);
|
||||
} else if (touching(touch, mainButtons2[2])) {
|
||||
if (config->screenFade()) {
|
||||
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) {
|
||||
config->screenFade(false);
|
||||
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
|
||||
}
|
||||
} else {
|
||||
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) {
|
||||
config->screenFade(true);
|
||||
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
|
||||
}
|
||||
}
|
||||
} else if (touching(touch, mainButtons2[3])) {
|
||||
if (config->progressDisplay()) {
|
||||
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) {
|
||||
config->progressDisplay(false);
|
||||
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
|
||||
}
|
||||
} else {
|
||||
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) {
|
||||
config->progressDisplay(true);
|
||||
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Navigation.
|
||||
if (hDown & KEY_UP) {
|
||||
if (Selection > 1) Selection -= 2;
|
||||
} else if (hDown & KEY_DOWN) {
|
||||
if (Selection < 2) Selection += 2;
|
||||
} else if (hDown & KEY_LEFT) {
|
||||
if (Selection%2) Selection--;
|
||||
} else if (hDown & KEY_RIGHT) {
|
||||
if (!(Selection%2)) Selection++;
|
||||
}
|
||||
} else if (this->settingPage == 2) {
|
||||
if (hDown & KEY_UP) {
|
||||
if (Selection > 0) Selection--;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (Selection < 2) Selection++;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
std::string tempPath;
|
||||
switch (Selection) {
|
||||
case 0:
|
||||
tempPath = selectFilePath(Lang::get("SELECT_3DSX_PATH"), config->_3dsxpath(), {});
|
||||
if (tempPath != "") config->_3dsxpath(tempPath);
|
||||
break;
|
||||
case 1:
|
||||
tempPath = selectFilePath(Lang::get("SELECT_NDS_PATH"), config->ndspath(), {});
|
||||
if (tempPath != "") config->ndspath(tempPath);
|
||||
break;
|
||||
case 2:
|
||||
tempPath = selectFilePath(Lang::get("SELECT_ARCHIVE_PATH"), config->archivepath(), {});
|
||||
if (tempPath != "") config->archivepath(tempPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, mainButtons[0])) {
|
||||
std::string tempPath = selectFilePath(Lang::get("SELECT_3DSX_PATH"), config->_3dsxpath(), {});
|
||||
if (tempPath != "") config->_3dsxpath(tempPath);
|
||||
} else if (touching(touch, mainButtons[1])) {
|
||||
std::string tempPath = selectFilePath(Lang::get("SELECT_NDS_PATH"), config->ndspath(), {});
|
||||
if (tempPath != "") config->ndspath(tempPath);
|
||||
} else if (touching(touch, mainButtons[2])) {
|
||||
std::string tempPath = selectFilePath(Lang::get("SELECT_ARCHIVE_PATH"), config->archivepath(), {});
|
||||
if (tempPath != "") config->archivepath(tempPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string langsTemp[] = {"br", "da", "de", "en", "es", "fr", "it", "lt", "pl", "pt", "ru", "jp"};
|
||||
void Settings::LanguageSelection(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (keyRepeatDelay) keyRepeatDelay--;
|
||||
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
|
||||
if (selectedLang < (int)languages.size()-1) {
|
||||
selectedLang++;
|
||||
} else {
|
||||
selectedLang = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
|
||||
if (selectedLang > 0) {
|
||||
selectedLang--;
|
||||
} else {
|
||||
selectedLang = (int)languages.size()-1;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
config->language(langsTemp[selectedLang]);
|
||||
Lang::load(config->language());
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
if ((hDown & KEY_B)) {
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
if (selectedLang < screenPos) {
|
||||
screenPos = selectedLang;
|
||||
} else if (selectedLang > screenPos + ENTRIES_PER_SCREEN - 1) {
|
||||
screenPos = selectedLang - ENTRIES_PER_SCREEN + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (keyRepeatDelay) keyRepeatDelay--;
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
|
||||
if (dropDownMenu) {
|
||||
if (hDown & KEY_A) {
|
||||
colorMode = colorSelection;
|
||||
dropDownMenu = false;
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
|
||||
if (colorSelection < (int)colorList.size()-1) {
|
||||
colorSelection++;
|
||||
} else {
|
||||
colorSelection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
|
||||
if (colorSelection > 0) {
|
||||
colorSelection--;
|
||||
} else {
|
||||
colorSelection = (int)colorList.size()-1;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (hDown & KEY_A) {
|
||||
switch(this->colorMode) {
|
||||
case 0:
|
||||
config->barColor(Overlays::SelectRGB(config->barColor()));
|
||||
break;
|
||||
case 1:
|
||||
config->topBG(Overlays::SelectRGB(config->topBG()));
|
||||
break;
|
||||
case 2:
|
||||
config->bottomBG(Overlays::SelectRGB(config->bottomBG()));
|
||||
break;
|
||||
case 3:
|
||||
config->textColor(Overlays::SelectRGB(config->textColor()));
|
||||
break;
|
||||
case 4:
|
||||
config->selectedColor(Overlays::SelectRGB(config->selectedColor()));
|
||||
break;
|
||||
case 5:
|
||||
config->unselectedColor(Overlays::SelectRGB(config->unselectedColor()));
|
||||
break;
|
||||
case 6:
|
||||
config->progressbarColor(Overlays::SelectRGB(config->progressbarColor()));
|
||||
break;
|
||||
case 7:
|
||||
config->notfoundColor(Overlays::SelectRGB(config->notfoundColor()));
|
||||
break;
|
||||
case 8:
|
||||
config->outdatedColor(Overlays::SelectRGB(config->outdatedColor()));
|
||||
break;
|
||||
case 9:
|
||||
config->uptodateColor(Overlays::SelectRGB(config->uptodateColor()));
|
||||
break;
|
||||
case 10:
|
||||
config->futureColor(Overlays::SelectRGB(config->futureColor()));
|
||||
break;
|
||||
case 11:
|
||||
config->buttonColor(Overlays::SelectRGB(config->buttonColor()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||
colorSelection = colorMode;
|
||||
dropDownMenu = true;
|
||||
}
|
||||
|
||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
if ((hDown & KEY_L || hDown & KEY_LEFT)) {
|
||||
if (colorMode > 0) colorMode--;
|
||||
}
|
||||
|
||||
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
|
||||
if (colorMode < 11) colorMode++;
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, mainButtons[0])) {
|
||||
int temp = Input::setu8(Lang::get("ENTER_RED_RGB"));
|
||||
if (temp != -1) {
|
||||
red = temp;
|
||||
if (colorMode == 0) {
|
||||
config->barColor(RGBA8(red, ColorHelper::getColorValue(config->barColor(), 1), ColorHelper::getColorValue(config->barColor(), 0), 255));
|
||||
} else if (colorMode == 1) {
|
||||
config->topBG(RGBA8(red, ColorHelper::getColorValue(config->topBG(), 1), ColorHelper::getColorValue(config->topBG(), 0), 255));
|
||||
} else if (colorMode == 2) {
|
||||
config->bottomBG(RGBA8(red, ColorHelper::getColorValue(config->bottomBG(), 1), ColorHelper::getColorValue(config->bottomBG(), 0), 255));
|
||||
} else if (colorMode == 3) {
|
||||
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));
|
||||
} else if (colorMode == 5) {
|
||||
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));
|
||||
} else if (colorMode == 7) {
|
||||
config->notfoundColor(RGBA8(red, ColorHelper::getColorValue(config->notfoundColor(), 1), ColorHelper::getColorValue(config->notfoundColor(), 0), 255));
|
||||
} else if (colorMode == 8) {
|
||||
config->outdatedColor(RGBA8(red, ColorHelper::getColorValue(config->outdatedColor(), 1), ColorHelper::getColorValue(config->outdatedColor(), 0), 255));
|
||||
} else if (colorMode == 9) {
|
||||
config->uptodateColor(RGBA8(red, ColorHelper::getColorValue(config->uptodateColor(), 1), ColorHelper::getColorValue(config->uptodateColor(), 0), 255));
|
||||
} else if (colorMode == 10) {
|
||||
config->futureColor(RGBA8(red, ColorHelper::getColorValue(config->futureColor(), 1), ColorHelper::getColorValue(config->futureColor(), 0), 255));
|
||||
} else if (colorMode == 11) {
|
||||
config->buttonColor(RGBA8(red, ColorHelper::getColorValue(config->buttonColor(), 1), ColorHelper::getColorValue(config->buttonColor(), 0), 255));
|
||||
}
|
||||
}
|
||||
} else if (touching(touch, mainButtons[1])) {
|
||||
int temp = Input::setu8(Lang::get("ENTER_GREEN_RGB"));
|
||||
if (temp != -1) {
|
||||
green = temp;
|
||||
if (colorMode == 0) {
|
||||
config->barColor(RGBA8(ColorHelper::getColorValue(config->barColor(), 2), green, ColorHelper::getColorValue(config->barColor(), 0), 255));
|
||||
} else if (colorMode == 1) {
|
||||
config->topBG(RGBA8(ColorHelper::getColorValue(config->topBG(), 2), green, ColorHelper::getColorValue(config->topBG(), 0), 255));
|
||||
} else if (colorMode == 2) {
|
||||
config->bottomBG(RGBA8(ColorHelper::getColorValue(config->bottomBG(), 2), green, ColorHelper::getColorValue(config->bottomBG(), 0), 255));
|
||||
} else if (colorMode == 3) {
|
||||
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));
|
||||
} else if (colorMode == 5) {
|
||||
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));
|
||||
} else if (colorMode == 7) {
|
||||
config->notfoundColor(RGBA8(ColorHelper::getColorValue(config->notfoundColor(), 2), green, ColorHelper::getColorValue(config->notfoundColor(), 0), 255));
|
||||
} else if (colorMode == 8) {
|
||||
config->outdatedColor(RGBA8(ColorHelper::getColorValue(config->outdatedColor(), 2), green, ColorHelper::getColorValue(config->outdatedColor(), 0), 255));
|
||||
} else if (colorMode == 9) {
|
||||
config->uptodateColor(RGBA8(ColorHelper::getColorValue(config->uptodateColor(), 2), green, ColorHelper::getColorValue(config->uptodateColor(), 0), 255));
|
||||
} else if (colorMode == 10) {
|
||||
config->futureColor(RGBA8(ColorHelper::getColorValue(config->futureColor(), 2), green, ColorHelper::getColorValue(config->futureColor(), 0), 255));
|
||||
} else if (colorMode == 11) {
|
||||
config->buttonColor(RGBA8(ColorHelper::getColorValue(config->buttonColor(), 2), green, ColorHelper::getColorValue(config->buttonColor(), 0), 255));
|
||||
}
|
||||
}
|
||||
} else if (touching(touch, mainButtons[2])) {
|
||||
int temp = Input::setu8(Lang::get("ENTER_BLUE_RGB"));
|
||||
if (temp != -1) {
|
||||
blue = temp;
|
||||
if (colorMode == 0) {
|
||||
config->barColor(RGBA8(ColorHelper::getColorValue(config->barColor(), 2), ColorHelper::getColorValue(config->barColor(), 1), blue, 255));
|
||||
} else if (colorMode == 1) {
|
||||
config->topBG(RGBA8(ColorHelper::getColorValue(config->topBG(), 2), ColorHelper::getColorValue(config->topBG(), 1), blue, 255));
|
||||
} else if (colorMode == 2) {
|
||||
config->bottomBG(RGBA8(ColorHelper::getColorValue(config->bottomBG(), 2), ColorHelper::getColorValue(config->bottomBG(), 1), blue, 255));
|
||||
} else if (colorMode == 3) {
|
||||
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));
|
||||
} else if (colorMode == 5) {
|
||||
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));
|
||||
} else if (colorMode == 7) {
|
||||
config->notfoundColor(RGBA8(ColorHelper::getColorValue(config->notfoundColor(), 2), ColorHelper::getColorValue(config->notfoundColor(), 1), blue, 255));
|
||||
} else if (colorMode == 8) {
|
||||
config->outdatedColor(RGBA8(ColorHelper::getColorValue(config->outdatedColor(), 2), ColorHelper::getColorValue(config->outdatedColor(), 1), blue, 255));
|
||||
} else if (colorMode == 9) {
|
||||
config->uptodateColor(RGBA8(ColorHelper::getColorValue(config->uptodateColor(), 2), ColorHelper::getColorValue(config->uptodateColor(), 1), blue, 255));
|
||||
} else if (colorMode == 10) {
|
||||
config->futureColor(RGBA8(ColorHelper::getColorValue(config->futureColor(), 2), ColorHelper::getColorValue(config->futureColor(), 1), blue, 255));
|
||||
} else if (colorMode == 11) {
|
||||
config->buttonColor(RGBA8(ColorHelper::getColorValue(config->buttonColor(), 2), ColorHelper::getColorValue(config->buttonColor(), 1), blue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (colorSelection < screenPos) {
|
||||
screenPos = colorSelection;
|
||||
} else if (colorSelection > screenPos + ENTRIES_PER_SCREEN - 1) {
|
||||
screenPos = colorSelection - ENTRIES_PER_SCREEN + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (mode == 0) {
|
||||
SubMenuLogic(hDown, hHeld, touch);
|
||||
} else if (mode == 1) {
|
||||
LanguageSelection(hDown, hHeld, touch);
|
||||
} else if (mode == 2) {
|
||||
colorChanging(hDown, hHeld, touch);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "mainMenu.hpp"
|
||||
#include "scriptlist.hpp"
|
||||
#include "startup.hpp"
|
||||
#include "unistore.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||
extern int fadealpha;
|
||||
extern bool fadein;
|
||||
extern std::unique_ptr<Config> config;
|
||||
|
||||
Startup::Startup(int mode, std::string file) {
|
||||
this->mode = mode; this->file = file;
|
||||
}
|
||||
|
||||
void Startup::Draw(void) const {
|
||||
GFX::DrawTop();
|
||||
GFX::DrawSprite(sprites_dev_by_idx, 0, 25);
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
GFX::DrawBottom();
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
}
|
||||
|
||||
void Startup::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (this->delay > 0) {
|
||||
this->delay -= 2;
|
||||
if (this->delay <= 0) {
|
||||
if (this->mode == 0) {
|
||||
config->firstStartup(false);
|
||||
Gui::setScreen(std::make_unique<MainMenu>(), true, true);
|
||||
} else if (this->mode == 1) {
|
||||
config->firstStartup(false);
|
||||
if (access(this->file.c_str(), F_OK) == 0) {
|
||||
Gui::setScreen(std::make_unique<UniStore>(true, this->file), true, true);
|
||||
} else {
|
||||
Gui::setScreen(std::make_unique<MainMenu>(), true, true);
|
||||
}
|
||||
} else if (this->mode == 2) {
|
||||
config->firstStartup(false);
|
||||
if (access(this->file.c_str(), F_OK) == 0) {
|
||||
Gui::setScreen(std::make_unique<ScriptList>(), true, true);
|
||||
} else {
|
||||
Gui::setScreen(std::make_unique<MainMenu>(), true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,874 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "download.hpp"
|
||||
#include "fileBrowse.hpp"
|
||||
#include "formatting.hpp"
|
||||
#include "keyboard.hpp"
|
||||
#include "mainMenu.hpp"
|
||||
#include "unistore.hpp"
|
||||
#include "unistore_v1.hpp"
|
||||
#include "unistore_v2.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
extern void notImplemented(void);
|
||||
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;
|
||||
this->autobootFile = file;
|
||||
}
|
||||
|
||||
// Autoboot stuff.
|
||||
void UniStore::autobootLogic() {
|
||||
if (this->doAutoboot) {
|
||||
if (!didAutoboot) {
|
||||
specialHandling = true; // Special back handling.
|
||||
if (ScriptHelper::checkIfValid(this->autobootFile, 1) == true) {
|
||||
storeInfo.push_back(parseStoreInfo(this->autobootFile));
|
||||
|
||||
// Update if WiFi found and wanted.
|
||||
if (checkWifiStatus()) {
|
||||
if (Msg::promptMsg(Lang::get("WOULD_YOU_LIKE_UPDATE"))) {
|
||||
if (storeInfo[0].url != "" && storeInfo[0].url != "MISSING: storeInfo.url" &&
|
||||
storeInfo[0].file != "" && storeInfo[0].file != "MISSING: storeInfo.file") {
|
||||
ScriptHelper::downloadFile(storeInfo[0].url, storeInfo[0].file, Lang::get("UPDATING"));
|
||||
}
|
||||
|
||||
if (storeInfo[0].sheetURL != "" && storeInfo[0].sheetURL != "MISSING: storeInfo.sheetURL" &&
|
||||
storeInfo[0].storeSheet != "" && storeInfo[0].storeSheet != "MISSING: storeInfo.sheet") {
|
||||
ScriptHelper::downloadFile(storeInfo[0].sheetURL, storeInfo[0].storeSheet, Lang::get("UPDATING"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentStoreFile = this->autobootFile;
|
||||
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
|
||||
JSON = openStoreFile();
|
||||
displayInformations = handleIfDisplayText();
|
||||
const std::string sheetURL = storeInfo[0].storeSheet;
|
||||
if (storeInfo[0].version == 0 || storeInfo[0].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[0].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
|
||||
}
|
||||
} else {
|
||||
specialHandling = true; // Special back handling.
|
||||
// Display Warn or so?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse informations like URL, Title, Author, Description.
|
||||
StoreInfo UniStore::parseStoreInfo(std::string fileName) {
|
||||
FILE* file = fopen(fileName.c_str(), "rt");
|
||||
if (!file) {
|
||||
printf("File not found.\n");
|
||||
return {"", ""};
|
||||
}
|
||||
|
||||
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
|
||||
StoreInfo info;
|
||||
info.title = ScriptHelper::getString(json, "storeInfo", "title");
|
||||
info.author = ScriptHelper::getString(json, "storeInfo", "author");
|
||||
info.description = ScriptHelper::getString(json, "storeInfo", "description");
|
||||
info.url = ScriptHelper::getString(json, "storeInfo", "url");
|
||||
info.file = ScriptHelper::getString(json, "storeInfo", "file");
|
||||
info.storeSheet = ScriptHelper::getString(json, "storeInfo", "sheet");
|
||||
info.sheetURL = ScriptHelper::getString(json, "storeInfo", "sheetURL");
|
||||
info.version = ScriptHelper::getNum(json, "storeInfo", "version");
|
||||
return info;
|
||||
}
|
||||
|
||||
// Return a parsed UniStore file.
|
||||
nlohmann::json UniStore::openStoreFile() {
|
||||
FILE* file = fopen(currentStoreFile.c_str(), "rt");
|
||||
nlohmann::json jsonFile;
|
||||
if (file) jsonFile = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
return jsonFile;
|
||||
}
|
||||
|
||||
// Do the description, if found.
|
||||
void UniStore::descript() {
|
||||
if (storeInfo[Selection].description != "" || storeInfo[Selection].description != "MISSING: storeInfo.description") {
|
||||
storeDesc = storeInfo[Selection].description;
|
||||
} else storeDesc = "";
|
||||
}
|
||||
|
||||
// Load the store description.
|
||||
void UniStore::loadStoreDesc(void) {
|
||||
descLines.clear();
|
||||
while(storeDesc.find('\n') != storeDesc.npos) {
|
||||
descLines.push_back(storeDesc.substr(0, storeDesc.find('\n')));
|
||||
storeDesc = storeDesc.substr(storeDesc.find('\n')+1);
|
||||
}
|
||||
|
||||
descLines.push_back(storeDesc.substr(0, storeDesc.find('\n')));
|
||||
}
|
||||
|
||||
void UniStore::DrawSubMenu(void) const {
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("UNISTORE_SUBMENU"), 400);
|
||||
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
|
||||
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);
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
// First Screen -> Storelist.
|
||||
void UniStore::DrawStoreList(void) const {
|
||||
std::string line1;
|
||||
std::string line2;
|
||||
std::string storeAmount = std::to_string(Selection +1) + " | " + std::to_string(storeInfo.size());
|
||||
GFX::DrawTop();
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), storeInfo[Selection].title, 400);
|
||||
Gui::DrawString(5, config->useBars() ? 220 : 218, 0.6f, config->textColor(), Lang::get("UNISTORE_VERSION") + std::to_string(storeInfo[Selection].version), 400);
|
||||
Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), (config->useBars() ? 239 : 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->textColor(), descLines[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);
|
||||
GFX::DrawArrow(315, 240, 180.0);
|
||||
GFX::DrawArrow(0, 218, 0, 1);
|
||||
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
|
||||
|
||||
if (config->viewMode() == 0) {
|
||||
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)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::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());
|
||||
line1 = storeInfo[screenPosList + i].title;
|
||||
if (screenPosList + i == Selection) {
|
||||
if (!dropDownMenu) {
|
||||
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, config->selectedColor());
|
||||
}
|
||||
}
|
||||
|
||||
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->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());
|
||||
} else {
|
||||
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_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->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
|
||||
}
|
||||
|
||||
void UniStore::Draw(void) const {
|
||||
if (mode == 0) {
|
||||
DrawSubMenu();
|
||||
} else if (mode == 1) {
|
||||
DrawStoreList();
|
||||
} else if (mode == 2) {
|
||||
DrawSearch();
|
||||
} else if (mode == 3) {
|
||||
DrawFullURLScreen();
|
||||
} else if (mode == 4) {
|
||||
DrawGitHubScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void UniStore::updateStore(int selectedStore) {
|
||||
if (checkWifiStatus()) {
|
||||
if (Msg::promptMsg(Lang::get("WOULD_YOU_LIKE_UPDATE"))) {
|
||||
if (storeInfo[selectedStore].url != "" && storeInfo[selectedStore].url != "MISSING: storeInfo.url" &&
|
||||
storeInfo[selectedStore].file != "" && storeInfo[selectedStore].file != "MISSING: storeInfo.file") {
|
||||
ScriptHelper::downloadFile(storeInfo[selectedStore].url, storeInfo[selectedStore].file, Lang::get("UPDATING"));
|
||||
}
|
||||
|
||||
if (storeInfo[selectedStore].sheetURL != "" && storeInfo[selectedStore].sheetURL != "MISSING: storeInfo.sheetURL" &&
|
||||
storeInfo[selectedStore].storeSheet != "" && storeInfo[selectedStore].storeSheet != "MISSING: storeInfo.sheet") {
|
||||
ScriptHelper::downloadFile(storeInfo[selectedStore].sheetURL, storeInfo[selectedStore].storeSheet, Lang::get("UPDATING"));
|
||||
}
|
||||
|
||||
// Refresh the list.
|
||||
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
|
||||
dirContents.clear();
|
||||
storeInfo.clear();
|
||||
chdir(config->storePath().c_str());
|
||||
getDirectoryContents(dirContents, {"unistore"});
|
||||
for(uint i = 0; i < dirContents.size(); i++) {
|
||||
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UniStore::refreshList() {
|
||||
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
|
||||
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
|
||||
dirContents.clear();
|
||||
storeInfo.clear();
|
||||
chdir(config->storePath().c_str());
|
||||
getDirectoryContents(dirContents, {"unistore"});
|
||||
for(uint i = 0; i < dirContents.size(); i++) {
|
||||
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
Selection = 0;
|
||||
mode = 1;
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
|
||||
Selection = 0;
|
||||
mode = 0;
|
||||
}
|
||||
}
|
||||
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>(), config->screenFade(), true);
|
||||
} else {
|
||||
Gui::screenBack(config->screenFade());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_UP) {
|
||||
if(Selection > 0) Selection--;
|
||||
}
|
||||
if (hDown & KEY_DOWN) {
|
||||
if(Selection < 2) Selection++;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
switch(Selection) {
|
||||
case 0:
|
||||
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
|
||||
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
|
||||
dirContents.clear();
|
||||
storeInfo.clear();
|
||||
chdir(config->storePath().c_str());
|
||||
getDirectoryContents(dirContents, {"unistore"});
|
||||
for(uint i = 0; i < dirContents.size(); i++) {
|
||||
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
|
||||
Selection = 0;
|
||||
mode = 1;
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (checkWifiStatus()) {
|
||||
Selection = 0;
|
||||
mode = 2;
|
||||
} else {
|
||||
notConnectedMsg();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), config->storePath(), {});
|
||||
if (tempStore != "") {
|
||||
config->storePath(tempStore);
|
||||
changesMade = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, subPos[0])) {
|
||||
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
|
||||
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
|
||||
dirContents.clear();
|
||||
storeInfo.clear();
|
||||
chdir(config->storePath().c_str());
|
||||
getDirectoryContents(dirContents, {"unistore"});
|
||||
for(uint i = 0; i < dirContents.size(); i++) {
|
||||
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
|
||||
Selection = 0;
|
||||
mode = 1;
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
|
||||
}
|
||||
} else if (touching(touch, subPos[1])) {
|
||||
if (checkWifiStatus() == true) {
|
||||
Selection = 0;
|
||||
mode = 2;
|
||||
} else {
|
||||
notConnectedMsg();
|
||||
}
|
||||
} else if (touching(touch, subPos[2])) {
|
||||
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), config->storePath(), {});
|
||||
if (tempStore != "") {
|
||||
config->storePath(tempStore);
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UniStore::deleteStore(int selectedStore) {
|
||||
std::string path = config->storePath();
|
||||
path += dirContents[selectedStore].name;
|
||||
deleteFile(path.c_str());
|
||||
// Refresh the list.
|
||||
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
|
||||
Selection = 0;
|
||||
dirContents.clear();
|
||||
storeInfo.clear();
|
||||
chdir(config->storePath().c_str());
|
||||
getDirectoryContents(dirContents, {"unistore"});
|
||||
for(uint i = 0; i < dirContents.size(); i++) {
|
||||
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
|
||||
if (dirContents.size() == 0) {
|
||||
dirContents.clear();
|
||||
storeInfo.clear();
|
||||
Selection = 0;
|
||||
mode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool UniStore::handleIfDisplayText() {
|
||||
if (JSON.at("storeInfo").contains("displayInformation")) {
|
||||
if (JSON["storeInfo"]["displayInformation"] != true) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (keyRepeatDelay) keyRepeatDelay--;
|
||||
|
||||
if (dropDownMenu) {
|
||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||
dropDownMenu = false;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (dropSelection < 2) dropSelection++;
|
||||
}
|
||||
|
||||
if (hDown & KEY_UP) {
|
||||
if (dropSelection > 0) dropSelection--;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
switch(dropSelection) {
|
||||
case 0:
|
||||
if (Msg::promptMsg(Lang::get("DELETE_STORE"))) {
|
||||
deleteStore(Selection);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
updateStore(Selection);
|
||||
break;
|
||||
case 2:
|
||||
if (config->viewMode() == 0) {
|
||||
config->viewMode(1);
|
||||
} else {
|
||||
config->viewMode(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
dropDownMenu = false;
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, dropPos2[0])) {
|
||||
if (Msg::promptMsg(Lang::get("DELETE_STORE"))) {
|
||||
deleteStore(Selection);
|
||||
}
|
||||
dropDownMenu = false;
|
||||
} else if (touching(touch, dropPos2[1])) {
|
||||
updateStore(Selection);
|
||||
dropDownMenu = false;
|
||||
} else if (touching(touch, dropPos2[2])) {
|
||||
if (config->viewMode() == 0) {
|
||||
config->viewMode(1);
|
||||
} else {
|
||||
config->viewMode(0);
|
||||
}
|
||||
dropDownMenu = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||
dropSelection = 0;
|
||||
dropDownMenu = true;
|
||||
}
|
||||
|
||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
storeInfo.clear();
|
||||
Selection = 0;
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
|
||||
if (Selection < (int)storeInfo.size()-1) {
|
||||
Selection++;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
} else {
|
||||
Selection = 0;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
|
||||
if (Selection > 0) {
|
||||
Selection--;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
} else {
|
||||
Selection = (int)storeInfo.size()-1;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
|
||||
if (config->viewMode() == 0) {
|
||||
if (Selection < (int)storeInfo.size()-1-3) {
|
||||
Selection += 3;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
} else {
|
||||
Selection = (int)storeInfo.size()-1;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
} else {
|
||||
if (Selection < (int)storeInfo.size()-1-6) {
|
||||
Selection += 7;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
} else {
|
||||
Selection = (int)storeInfo.size()-1;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
|
||||
if (config->viewMode() == 0) {
|
||||
if (Selection > 2) {
|
||||
Selection -= 3;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
} else {
|
||||
Selection = 0;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
} else {
|
||||
if (Selection > 6) {
|
||||
Selection -= 7;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
} else {
|
||||
Selection = 0;
|
||||
descript();
|
||||
loadStoreDesc();
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
if (!dirContents[Selection].isDirectory && storeInfo.size() != 0) {
|
||||
if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) {
|
||||
updateStore(Selection);
|
||||
currentStoreFile = dirContents[Selection].name;
|
||||
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
|
||||
JSON = openStoreFile();
|
||||
displayInformations = handleIfDisplayText();
|
||||
const std::string sheetURL = storeInfo[Selection].storeSheet;
|
||||
|
||||
if (storeInfo[Selection].version == 0 || storeInfo[Selection].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[Selection].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config->viewMode() == 0) {
|
||||
if(Selection < screenPos) {
|
||||
screenPos = Selection;
|
||||
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
|
||||
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
|
||||
}
|
||||
} else if (config->viewMode() == 1) {
|
||||
if(Selection < screenPosList) {
|
||||
screenPosList = Selection;
|
||||
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
|
||||
screenPosList = Selection - ENTRIES_PER_LIST + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_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 (ScriptHelper::checkIfValid(dirContents[screenPos + i].name, 1) == true) {
|
||||
updateStore(screenPos + i);
|
||||
currentStoreFile = dirContents[screenPos + i].name;
|
||||
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
|
||||
JSON = openStoreFile();
|
||||
displayInformations = handleIfDisplayText();
|
||||
const std::string sheetURL = storeInfo[screenPos + i].storeSheet;
|
||||
if (storeInfo[screenPos + i].version == 0 || storeInfo[screenPos + i].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[screenPos + i].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), 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++) {
|
||||
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
|
||||
if (ScriptHelper::checkIfValid(dirContents[screenPosList + i].name, 1) == true) {
|
||||
updateStore(screenPosList + i);
|
||||
currentStoreFile = dirContents[screenPosList + i].name;
|
||||
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
|
||||
|
||||
JSON = openStoreFile();
|
||||
displayInformations = handleIfDisplayText();
|
||||
const std::string sheetURL = storeInfo[screenPosList + i].storeSheet;
|
||||
if (storeInfo[screenPosList + i].version == 0 || storeInfo[screenPosList + i].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[screenPosList + i].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_START) {
|
||||
if (config->autoboot() == 1) {
|
||||
if (Msg::promptMsg(Lang::get("DISABLE_AUTOBOOT"))) {
|
||||
config->autoboot(0);
|
||||
config->autobootFile("");
|
||||
changesMade = true;
|
||||
}
|
||||
} else {
|
||||
if (!dirContents[Selection].isDirectory && storeInfo.size() != 0) {
|
||||
if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) {
|
||||
if (Msg::promptMsg(Lang::get("AUTOBOOT_STORE"))) {
|
||||
config->autoboot(1);
|
||||
config->autobootFile(config->storePath() + dirContents[Selection].name);
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UniStore::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
this->autobootLogic();
|
||||
|
||||
if (mode == 0) {
|
||||
SubMenuLogic(hDown, hHeld, touch);
|
||||
} else if (mode == 1) {
|
||||
StoreSelectionLogic(hDown, hHeld, touch);
|
||||
} else if (mode == 2) {
|
||||
SearchLogic(hDown, hHeld, touch);
|
||||
} else if (mode == 3) {
|
||||
FullURLLogic(hDown, hHeld, touch);
|
||||
} else if (mode == 4) {
|
||||
GitHubLogic(hDown, hHeld, touch);
|
||||
}
|
||||
}
|
||||
|
||||
void UniStore::DrawSearch(void) const {
|
||||
GFX::DrawTop();
|
||||
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->textColor(), Lang::get("UNISTORE_SEARCH"), 400);
|
||||
}
|
||||
|
||||
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
|
||||
GFX::DrawBottom();
|
||||
GFX::DrawArrow(0, 218, 0, 1);
|
||||
|
||||
GFX::DrawButton(URLBtn[0].x, URLBtn[0].y,Lang::get("FULL_URL"));
|
||||
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);
|
||||
}
|
||||
|
||||
void UniStore::SearchLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
Selection = 0;
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
if (hDown & KEY_RIGHT || hDown & KEY_R) {
|
||||
if (Selection == 0) Selection = 1;
|
||||
else if (Selection == 2) Selection = 3;
|
||||
}
|
||||
if (hDown & KEY_LEFT || hDown & KEY_L) {
|
||||
if (Selection == 1) Selection = 0;
|
||||
else if (Selection == 3) Selection = 2;
|
||||
}
|
||||
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (Selection == 0) Selection = 2;
|
||||
else if (Selection == 1) Selection = 3;
|
||||
}
|
||||
|
||||
if (hDown & KEY_UP) {
|
||||
if (Selection == 2) Selection = 0;
|
||||
else if (Selection == 3) Selection = 1;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
if (Selection == 0) {
|
||||
Selection = 0;
|
||||
mode = 3;
|
||||
} else if (Selection == 1) {
|
||||
Selection = 0;
|
||||
mode = 4;
|
||||
} else if (Selection == 2) {
|
||||
if (Msg::promptMsg("TinyDB might be down. This would lead to Download Failed!\nDo you still like to continue?")) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH && touching(touch, URLBtn[0])) {
|
||||
Selection = 0;
|
||||
mode = 3;
|
||||
} else if (hDown & KEY_TOUCH && touching(touch, URLBtn[1])) {
|
||||
Selection = 0;
|
||||
mode = 4;
|
||||
} else if (hDown & KEY_TOUCH && touching(touch, URLBtn[2])) {
|
||||
if (Msg::promptMsg("TinyDB might be down. This would lead to Download Failed!\nDo you still like to continue?")) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void UniStore::DrawGitHubScreen(void) const {
|
||||
GFX::DrawTop();
|
||||
if (config->useBars() == true) {
|
||||
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("GITHUB"), 400);
|
||||
} else {
|
||||
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->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->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->textColor(), Lang::get("OK"), 40);
|
||||
|
||||
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) {
|
||||
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[0])) {
|
||||
OwnerAndRepo = Input::setkbdString(150, Lang::get("ENTER_OWNER_AND_REPO"));
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[1])) {
|
||||
fileName = Input::setkbdString(150, Lang::get("ENTER_FILENAME"));
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[2])) {
|
||||
if (checkWifiStatus() == true) {
|
||||
std::string URL = "https://github.com/";
|
||||
URL += OwnerAndRepo;
|
||||
URL += "/raw/master/unistore/";
|
||||
URL += fileName;
|
||||
ScriptHelper::downloadFile(URL, config->storePath() + fileName, Lang::get("DOWNLOADING") + fileName);
|
||||
} else {
|
||||
notConnectedMsg();
|
||||
}
|
||||
}
|
||||
|
||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
// Reset everything.
|
||||
OwnerAndRepo = "";
|
||||
fileName = "";
|
||||
Selection = 0;
|
||||
mode = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void UniStore::DrawFullURLScreen(void) const {
|
||||
GFX::DrawTop();
|
||||
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->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->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->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->textColor(), Lang::get("OK"), 40);
|
||||
|
||||
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) {
|
||||
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[0])) {
|
||||
FullURL = Input::setkbdString(150, Lang::get("ENTER_FULL_URL"));
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[1])) {
|
||||
fileName = Input::setkbdString(150, Lang::get("ENTER_FILENAME"));
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[2])) {
|
||||
if (checkWifiStatus() == true) {
|
||||
ScriptHelper::downloadFile(FullURL, config->storePath() + fileName, Lang::get("DOWNLOADING") + fileName);
|
||||
} else {
|
||||
notConnectedMsg();
|
||||
}
|
||||
}
|
||||
|
||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
// Reset everything.
|
||||
FullURL = "";
|
||||
fileName = "";
|
||||
Selection = 0;
|
||||
mode = 2;
|
||||
}
|
||||
}
|
||||
@@ -1,540 +0,0 @@
|
||||
/*
|
||||
* This file is part of Universal-Updater
|
||||
* Copyright (C) 2019-2020 Universal-Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "download.hpp"
|
||||
#include "formatting.hpp"
|
||||
#include "json.hpp"
|
||||
#include "scriptHelper.hpp"
|
||||
#include "unistore_v1.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
extern std::unique_ptr<Config> config;
|
||||
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||
extern u32 getColor(std::string colorString);
|
||||
|
||||
extern u32 barColor, bgTopColor, bgBottomColor, TextColor, progressBar, selected, unselected;
|
||||
extern bool didAutoboot, isScriptSelected;
|
||||
|
||||
UniStoreV1::UniStoreV1(nlohmann::json &JSON, const std::string sheetPath, bool displayInf) {
|
||||
this->storeJson = JSON;
|
||||
this->displayInformations = displayInf;
|
||||
|
||||
if (access(sheetPath.c_str(), F_OK) != 0) {
|
||||
this->sheetHasLoaded = false;
|
||||
} else {
|
||||
Gui::loadSheet(sheetPath.c_str(), this->sheet);
|
||||
this->sheetHasLoaded = true;
|
||||
}
|
||||
|
||||
u32 colorTemp;
|
||||
if (config->useScriptColor()) {
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
|
||||
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
|
||||
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
|
||||
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
|
||||
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
|
||||
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
|
||||
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
|
||||
|
||||
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
|
||||
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
|
||||
} else {
|
||||
barColor = config->barColor();
|
||||
bgTopColor = config->topBG();
|
||||
bgBottomColor = config->bottomBG();
|
||||
TextColor = config->textColor();
|
||||
selected = config->selectedColor();
|
||||
unselected = config->unselectedColor();
|
||||
progressBar = config->progressbarColor();
|
||||
}
|
||||
}
|
||||
|
||||
void UniStoreV1::drawBlend(int key, int x, int y) const {
|
||||
C2D_ImageTint tint;
|
||||
C2D_SetImageTint(&tint, C2D_TopLeft, C2D_Color32(0, 0, 0, 180), 0.5);
|
||||
C2D_SetImageTint(&tint, C2D_TopRight, C2D_Color32(0, 0, 0, 180), 0.5);
|
||||
C2D_SetImageTint(&tint, C2D_BotLeft, C2D_Color32(0, 0, 0, 180), 0.5);
|
||||
C2D_SetImageTint(&tint, C2D_BotRight, C2D_Color32(0, 0, 0, 180), 0.5);
|
||||
C2D_DrawImageAt(C2D_SpriteSheetGetImage(this->sheet, key), x, y, 0.5f, &tint);
|
||||
}
|
||||
|
||||
void UniStoreV1::parseObjects() {
|
||||
this->objects.clear();
|
||||
for(auto it = this->storeJson.begin();it != this->storeJson.end(); it++) {
|
||||
if (it.key() != "storeInfo") {
|
||||
this->objects.push_back(it.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UniStoreV1::~UniStoreV1() {
|
||||
// Only unload if sheet has loaded.
|
||||
if (this->sheetHasLoaded) {
|
||||
Gui::unloadSheet(this->sheet);
|
||||
}
|
||||
}
|
||||
|
||||
void UniStoreV1::Draw(void) const {
|
||||
std::string entryAmount = std::to_string(this->Selection+1) + " | " + std::to_string((int)this->storeJson.at("storeContent").size());
|
||||
std::string info;
|
||||
GFX::DrawTop();
|
||||
// Top Background.
|
||||
if (this->storeJson.at("storeInfo").contains("iconIndexTop") && sheetHasLoaded == true) {
|
||||
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["iconIndexTop"], 0, 0);
|
||||
}
|
||||
|
||||
// Icon.
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("info").contains("iconIndex") && sheetHasLoaded == true) {
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("info").contains("posX") && this->storeJson.at("storeContent").at(Selection).at("info").contains("posY")) {
|
||||
Gui::DrawSprite(this->sheet, this->storeJson["storeContent"][Selection]["info"]["iconIndex"], this->storeJson["storeContent"][Selection]["info"]["posX"], this->storeJson["storeContent"][Selection]["info"]["posY"]);
|
||||
} else {
|
||||
Gui::DrawSprite(this->sheet, this->storeJson["storeContent"][Selection]["info"]["iconIndex"], 175, 155);
|
||||
}
|
||||
}
|
||||
|
||||
if (displayInformations != false) {
|
||||
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, TextColor, std::string(this->storeJson["storeInfo"]["title"]), 400);
|
||||
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, TextColor, entryAmount);
|
||||
|
||||
Gui::DrawStringCentered(0, 32, 0.6f, TextColor, Lang::get("TITLE") + std::string(this->storeJson["storeContent"][Selection]["info"]["title"]), 400);
|
||||
Gui::DrawStringCentered(0, 57, 0.6f, TextColor, Lang::get("AUTHOR") + std::string(this->storeJson["storeContent"][Selection]["info"]["author"]), 400);
|
||||
Gui::DrawStringCentered(0, 82, 0.6f, TextColor, Lang::get("DESC") + std::string(this->storeJson["storeContent"][Selection]["info"]["description"]), 400);
|
||||
|
||||
if (this->storeJson["storeContent"][Selection]["info"]["version"] != "") {
|
||||
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + std::string(this->storeJson["storeContent"][Selection]["info"]["version"]), 400);
|
||||
} else {
|
||||
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + Lang::get("UNKNOWN"), 400);
|
||||
}
|
||||
|
||||
if (this->storeJson["storeContent"][Selection]["info"]["fileSize"] != 0) {
|
||||
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + formatBytes(int64_t(this->storeJson["storeContent"][Selection]["info"]["fileSize"])), 400);
|
||||
} else {
|
||||
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + Lang::get("UNKNOWN"), 400);
|
||||
}
|
||||
}
|
||||
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
|
||||
GFX::DrawBottom();
|
||||
|
||||
// Bottom Background.
|
||||
if (this->storeJson.at("storeInfo").contains("iconIndexBottom") && sheetHasLoaded == true) {
|
||||
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["iconIndexBottom"], 0, 0);
|
||||
}
|
||||
|
||||
GFX::DrawArrow(295, -1);
|
||||
GFX::DrawArrow(315, 240, 180.0);
|
||||
GFX::DrawArrow(0, 218, 0, 1);
|
||||
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
|
||||
|
||||
if (config->viewMode() == 0) {
|
||||
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)this->storeJson.at("storeContent").size(); i++) {
|
||||
info = this->storeJson["storeContent"][screenPos + i]["info"]["title"];
|
||||
if (screenPos + i == Selection) {
|
||||
if (this->storeJson.at("storeInfo").contains("buttonLarge") && sheetHasLoaded == true) {
|
||||
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["buttonLarge"], 0, 40+(i*57));
|
||||
} else {
|
||||
if (!dropDownMenu) {
|
||||
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, selected);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this->storeJson.at("storeInfo").contains("buttonLarge") && sheetHasLoaded == true) {
|
||||
this->drawBlend(this->storeJson["storeInfo"]["buttonLarge"], 0, 40+(i*57));
|
||||
} else {
|
||||
Gui::Draw_Rect(0, 40+(i*57), 320, 45, unselected);
|
||||
}
|
||||
}
|
||||
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, TextColor, info, 320);
|
||||
}
|
||||
} else if (config->viewMode() == 1) {
|
||||
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)this->storeJson.at("storeContent").size(); i++) {
|
||||
info = this->storeJson["storeContent"][screenPosList + i]["info"]["title"];
|
||||
if (screenPosList + i == Selection) {
|
||||
if (this->storeJson.at("storeInfo").contains("buttonSmall") && sheetHasLoaded == true) {
|
||||
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["buttonSmall"], 0, (i+1)*27);
|
||||
} else {
|
||||
if (!dropDownMenu) {
|
||||
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, selected);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this->storeJson.at("storeInfo").contains("buttonSmall") && sheetHasLoaded == true) {
|
||||
this->drawBlend(this->storeJson["storeInfo"]["buttonSmall"], 0, (i+1)*27);
|
||||
} else {
|
||||
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
|
||||
}
|
||||
}
|
||||
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, TextColor, info, 320);
|
||||
}
|
||||
}
|
||||
|
||||
// DropDown Menu.
|
||||
if (dropDownMenu) {
|
||||
// Draw Operation Box.
|
||||
Gui::Draw_Rect(0, 25, 140, 44, barColor);
|
||||
Gui::drawAnimatedSelector(dropPos[0].x, dropPos[0].y, dropPos[0].w, dropPos[0].h, .090, TRANSPARENT, 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, 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 UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (keyRepeatDelay) keyRepeatDelay--;
|
||||
|
||||
//DropDown Logic.
|
||||
if (dropDownMenu) {
|
||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||
dropDownMenu = false;
|
||||
}
|
||||
if (hDown & KEY_DOWN) {
|
||||
if (dropSelection < 1) dropSelection++;
|
||||
}
|
||||
if (hDown & KEY_UP) {
|
||||
if (dropSelection > 0) dropSelection--;
|
||||
}
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
if (config->viewMode() == 0) {
|
||||
config->viewMode(1);
|
||||
} else {
|
||||
config->viewMode(0);
|
||||
}
|
||||
dropDownMenu = false;
|
||||
}
|
||||
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (touching(touch, dropPos[0])) {
|
||||
if (config->viewMode() == 0) {
|
||||
config->viewMode(1);
|
||||
} else {
|
||||
config->viewMode(0);
|
||||
}
|
||||
dropDownMenu = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
|
||||
dropSelection = 0;
|
||||
dropDownMenu = true;
|
||||
}
|
||||
|
||||
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
|
||||
if (!didAutoboot) didAutoboot = true;
|
||||
Gui::screenBack(config->screenFade());
|
||||
return;
|
||||
}
|
||||
|
||||
// Go one entry up.
|
||||
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
|
||||
if (Selection > 0) {
|
||||
Selection--;
|
||||
} else {
|
||||
Selection = (int)this->storeJson.at("storeContent").size()-1;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
// Go one entry down.
|
||||
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
|
||||
if (Selection < (int)this->storeJson.at("storeContent").size()-1) {
|
||||
Selection++;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
|
||||
if (config->viewMode() == 0) {
|
||||
if (Selection < (int)this->storeJson.at("storeContent").size()-1-3) {
|
||||
Selection += 3;
|
||||
} else {
|
||||
Selection = (int)this->storeJson.at("storeContent").size()-1;
|
||||
}
|
||||
} else {
|
||||
if (Selection < (int)this->storeJson.at("storeContent").size()-1-6) {
|
||||
Selection += 7;
|
||||
} else {
|
||||
Selection = (int)this->storeJson.at("storeContent").size()-1;
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
|
||||
if (config->viewMode() == 0) {
|
||||
if (Selection > 2) {
|
||||
Selection -= 3;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
} else {
|
||||
if (Selection > 6) {
|
||||
Selection -= 7;
|
||||
} else {
|
||||
Selection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
keyRepeatDelay = config->keyDelay();
|
||||
}
|
||||
|
||||
// Execute touched Entry.
|
||||
if (hDown & KEY_TOUCH) {
|
||||
if (config->viewMode() == 0) {
|
||||
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)this->storeJson.at("storeContent").size(); i++) {
|
||||
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
|
||||
Selection = screenPos + i;
|
||||
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
|
||||
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
|
||||
execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (config->viewMode() == 1) {
|
||||
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)this->storeJson.at("storeContent").size(); i++) {
|
||||
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
|
||||
Selection = screenPosList + i;
|
||||
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
|
||||
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
|
||||
execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Execute that Entry.
|
||||
if (hDown & KEY_A) {
|
||||
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
|
||||
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
if (config->viewMode() == 0) {
|
||||
if (Selection < screenPos) {
|
||||
screenPos = Selection;
|
||||
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
|
||||
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
|
||||
}
|
||||
} else if (config->viewMode() == 1) {
|
||||
if (Selection < screenPosList) {
|
||||
screenPosList = Selection;
|
||||
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
|
||||
screenPosList = Selection - ENTRIES_PER_LIST + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Execute Entry.
|
||||
Result UniStoreV1::execute() {
|
||||
Result ret = NONE; // No Error has been occured now.
|
||||
for(int i = 0; i < (int)this->storeJson.at("storeContent").at(Selection).at("script").size(); i++) {
|
||||
if (ret == NONE) {
|
||||
std::string type = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("type");
|
||||
if (type == "deleteFile") {
|
||||
bool missing = false;
|
||||
std::string file, message;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
if (!missing) ret = ScriptHelper::removeFile(file, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "downloadFile") {
|
||||
bool missing = false;
|
||||
std::string file, output, message;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
if (!missing) ret = ScriptHelper::downloadFile(file, output, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "downloadRelease") {
|
||||
bool missing = false, includePrereleases = false, showVersions = false;
|
||||
std::string repo, file, output, message;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("repo")) repo = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("repo");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("includePrereleases") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("includePrereleases").is_boolean())
|
||||
includePrereleases = this->storeJson.at(Selection).at("script").at(i).at("includePrereleases");
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("showVersions") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("showVersions").is_boolean())
|
||||
showVersions = this->storeJson.at(Selection).at("script").at(i).at("showVersions");
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
if (!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "extractFile") {
|
||||
bool missing = false;
|
||||
std::string file, input, output, message;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("input")) input = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("input");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
if (!missing) ScriptHelper::extractFile(file, input, output, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "installCia") {
|
||||
bool missing = false, updateSelf = false;
|
||||
std::string file, message;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("updateSelf") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("updateSelf").is_boolean()) {
|
||||
updateSelf = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("updateSelf");
|
||||
}
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
if (!missing) ScriptHelper::installFile(file, updateSelf, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "mkdir") {
|
||||
bool missing = false;
|
||||
std::string directory, message;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
|
||||
else missing = true;
|
||||
if (!missing) makeDirs(directory.c_str());
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "rmdir") {
|
||||
bool missing = false;
|
||||
std::string directory, message, promptmsg;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
|
||||
else missing = true;
|
||||
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
|
||||
if (!missing) {
|
||||
if (access(directory.c_str(), F_OK) != 0 ) {
|
||||
ret = DELETE_ERROR;
|
||||
} else {
|
||||
if (Msg::promptMsg(promptmsg)) {
|
||||
removeDirRecursive(directory.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "mkfile") {
|
||||
bool missing = false;
|
||||
std::string file;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
|
||||
else missing = true;
|
||||
if (!missing) ScriptHelper::createFile(file.c_str());
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "timeMsg") {
|
||||
bool missing = false;
|
||||
std::string message;
|
||||
int seconds;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("seconds") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("seconds").is_number())
|
||||
seconds = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("seconds");
|
||||
else missing = true;
|
||||
if (!missing) ScriptHelper::displayTimeMsg(message, seconds);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "saveConfig") {
|
||||
config->save();
|
||||
|
||||
} else if (type == "notImplemented") {
|
||||
notImplemented();
|
||||
|
||||
} else if (type == "bootTitle") {
|
||||
std::string TitleID = "";
|
||||
std::string message = "";
|
||||
bool isNAND = false, missing = false;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("NAND");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
else missing = true;
|
||||
if (!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "promptMessage") {
|
||||
std::string Message = "";
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
ret = ScriptHelper::prompt(Message);
|
||||
|
||||
} else if (type == "copy") {
|
||||
std::string Message = "", source = "", destination = "";
|
||||
bool missing = false;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("source")) source = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("source");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("destination")) destination = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("destination");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
if (!missing) ret = ScriptHelper::copyFile(source, destination, Message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
|
||||
} else if (type == "move") {
|
||||
std::string Message = "", oldFile = "", newFile = "";
|
||||
bool missing = false;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("old")) oldFile = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("old");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("new")) newFile = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("new");
|
||||
else missing = true;
|
||||
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
|
||||
if (!missing) ret = ScriptHelper::renameFile(oldFile, newFile, Message);
|
||||
else ret = SYNTAX_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret == NONE) doneMsg();
|
||||
else if (ret == FAILED_DOWNLOAD) Msg::DisplayWarnMsg(Lang::get("DOWNLOAD_ERROR"));
|
||||
else if (ret == SCRIPT_CANCELED) Msg::DisplayWarnMsg(Lang::get("SCRIPT_CANCELED"));
|
||||
else if (ret == SYNTAX_ERROR) Msg::DisplayWarnMsg(Lang::get("SYNTAX_ERROR"));
|
||||
else if (ret == COPY_ERROR) Msg::DisplayWarnMsg(Lang::get("COPY_ERROR"));
|
||||
else if (ret == MOVE_ERROR) Msg::DisplayWarnMsg(Lang::get("MOVE_ERROR"));
|
||||
else if (ret == DELETE_ERROR) Msg::DisplayWarnMsg(Lang::get("DELETE_ERROR"));
|
||||
return ret;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user