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:
StackZ
2020-10-30 03:31:20 +01:00
committed by GitHub
parent 5d38c98698
commit 913475eabf
142 changed files with 13937 additions and 14588 deletions
-179
View File
@@ -1,179 +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 "colorHelper.hpp"
#include "config.hpp"
#include "gui.hpp"
#include "keyboard.hpp"
#include "overlay.hpp"
#include "structs.hpp"
extern std::unique_ptr<Config> config;
extern touchPosition touch;
extern bool touching(Structs::ButtonPos button);
// Draw RGB Colors.
static void DrawRGBColor(u8 r, u8 g, u8 b) {
// Display RGB line.
for (int i = 0; i < 256; i++) {
Gui::Draw_Rect((10 + i), 30, 1, 20, C2D_Color32(i, 0, 0, 255));
Gui::Draw_Rect((10 + i), 80, 1, 20, C2D_Color32(0, i, 0, 255));
Gui::Draw_Rect((10 + i), 130, 1, 20, C2D_Color32(0, 0, i, 255));
}
Gui::Draw_Rect((10 + r), 30, 1, 20, C2D_Color32(255, 255, 255, 255));
Gui::Draw_Rect((10 + g), 80, 1, 20, C2D_Color32(255, 255, 255, 255));
Gui::Draw_Rect((10 + b), 130, 1, 20, C2D_Color32(255, 255, 255, 255));
// Display RGB Boxes.
Gui::Draw_Rect(270, 30, 40, 20, C2D_Color32(200, 200, 200, 255));
Gui::Draw_Rect(270, 80, 40, 20, C2D_Color32(200, 200, 200, 255));
Gui::Draw_Rect(270, 130, 40, 20, C2D_Color32(200, 200, 200, 255));
// Display Values.
Gui::DrawStringCentered(-(40 / 2) + 150, 30 + (20/2) - (Gui::GetStringHeight(0.6f, std::to_string(r)) / 2), 0.6f, C2D_Color32(0, 0, 0, 255), std::to_string(r), 40, 20);
Gui::DrawStringCentered(-(40 / 2) + 150, 80 + (20/2) - (Gui::GetStringHeight(0.6f, std::to_string(g)) / 2), 0.6f, C2D_Color32(0, 0, 0, 255), std::to_string(g), 40, 20);
Gui::DrawStringCentered(-(40 / 2) + 150, 130 + (20/2) - (Gui::GetStringHeight(0.6f, std::to_string(b)) / 2), 0.6f, C2D_Color32(0, 0, 0, 255), std::to_string(b), 40, 20);
// Display as formated string.
char hexValues[16];
snprintf(hexValues, sizeof hexValues, "#%02x%02x%02x", r, g, b);
Gui::DrawStringCentered(0, 158, 0.7f, config->textColor(), "RGB: " + std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b) + " - Hex: " + hexValues, 310);
Gui::Draw_Rect(110, 180, 100, 30, C2D_Color32(r, g, b, 255));
}
// Draw.
static void Draw(u8 r, u8 g, u8 b) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, C2D_Color32(0, 0, 0, 0));
C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0));
GFX::DrawTop();
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 190));
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("SELECT_RGB_COLOR"), 400);
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.7f, Lang::get("UI_COLOR_BEHAVIOUR")))/2, 0.7f, config->textColor(), Lang::get("UI_COLOR_BEHAVIOUR"), 390, 70);
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 240, config->bottomBG() + C2D_Color32(0, 0, 0, 190));
DrawRGBColor(r, g, b);
C3D_FrameEnd(0);
}
u32 Overlays::SelectRGB(u32 oldColor) {
u8 r = ColorHelper::getColorValue(oldColor, 2);
u8 g = ColorHelper::getColorValue(oldColor, 1);
u8 b = ColorHelper::getColorValue(oldColor, 0);
int selection = 0;
while(1) {
Draw(r, g, b);
hidScanInput();
hidTouchRead(&touch);
if (hidKeysDown() & KEY_UP) {
if (selection > 0) selection--;
}
if (hidKeysDown() & KEY_DOWN) {
if (selection < 2) selection++;
}
if (hidKeysHeld() & KEY_RIGHT) {
switch(selection) {
case 0: // Red.
if (r < 255) r++;
break;
case 1: // Green.
if (g < 255) g++;
break;
case 2:
if (b < 255) b++;
break;
}
}
if (hidKeysHeld() & KEY_LEFT) {
switch(selection) {
case 0: // Red.
if (r > 0) r--;
break;
case 1: // Green.
if (g > 0) g--;
break;
case 2:
if (b > 0) b--;
break;
}
}
if (hidKeysDown() & KEY_START) {
return RGBA8(r, g, b, 255);
}
if (hidKeysDown() & KEY_B) {
return oldColor;
}
if (hidKeysHeld() & KEY_TOUCH) {
for (int i = 0; i < 256; i++) {
if (touch.px >= (10 + i) && touch.px <= (10 + i) + 1 && touch.py >= 30 && touch.py <= 30 + 20) {
r = i;
}
if (touch.px >= (10 + i) && touch.px <= (10 + i) + 1 && touch.py >= 80 && touch.py <= 80 + 20) {
g = i;
}
if (touch.px >= (10 + i) && touch.px <= (10 + i) + 1 && touch.py >= 130 && touch.py <= 130 + 20) {
b = i;
}
}
}
// Change RGB Value on the next button!
if (hidKeysDown() & KEY_TOUCH) {
if (touch.px >= 270 && touch.px <= 270 + 40 && touch.py >= 30 && touch.py <= 30 + 20) {
int temp = Input::setu8(Lang::get("ENTER_RED_RGB"));
if (temp != -1) {
r = temp;
}
} else if (touch.px >= 270 && touch.px <= 270 + 40 && touch.py >= 80 && touch.py <= 80 + 20) {
int temp = Input::setu8(Lang::get("ENTER_GREEN_RGB"));
if (temp != -1) {
g = temp;
}
} else if (touch.px >= 270 && touch.px <= 270 + 40 && touch.py >= 130 && touch.py <= 130 + 20) {
int temp = Input::setu8(Lang::get("ENTER_BLUE_RGB"));
if (temp != -1) {
b = temp;
}
}
}
}
}
+65
View File
@@ -0,0 +1,65 @@
/*
* 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 "overlay.hpp"
/*
Show the Credits.
*/
void Overlays::ShowCredits() {
bool doOut = false;
while(!doOut) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
GFX::DrawSprite(sprites_universal_updater_idx, 220, 30);
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, "Universal-Updater - " + Lang::get("CREDITS"));
Gui::DrawString(10, 30, 0.5f, TEXT_COLOR, "- Universal-Team");
Gui::DrawString(10, 50, 0.5f, TEXT_COLOR, "- devkitPro");
Gui::DrawString(10, 70, 0.5f, TEXT_COLOR, "- dlbeer");
Gui::DrawString(10, 90, 0.5f, TEXT_COLOR, "- FlagBrew");
Gui::DrawString(10, 110, 0.5f, TEXT_COLOR, "- https://icons8.com/");
Gui::DrawString(10, 130, 0.5f, TEXT_COLOR, "- PabloMK7");
Gui::DrawString(10, 150, 0.5f, TEXT_COLOR, Lang::get("CONTRIBUTOR_TRANSLATORS"));
Gui::DrawString(10, 195, 0.5f, TEXT_COLOR, Lang::get("GITHUB"));
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, Lang::get("CURRENT_VERSION") + std::string(V_STRING), 390);
GFX::DrawBottom();
GFX::DrawSprite(sprites_universal_core_idx, 0, 26);
C3D_FrameEnd(0);
hidScanInput();
if ((hidKeysDown() & KEY_START) || (hidKeysDown() & KEY_B) || (hidKeysDown() & KEY_A)) doOut = true;
}
}
+187
View File
@@ -0,0 +1,187 @@
/*
* 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 "overlay.hpp"
#include <unistd.h>
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 10, 6, 300, 22 },
{ 10, 36, 300, 22 },
{ 10, 66, 300, 22 },
{ 10, 96, 300, 22 },
{ 10, 126, 300, 22 },
{ 10, 156, 300, 22 },
{ 10, 186, 300, 22 }
};
/*
Select a Directory.
*/
std::string Overlays::SelectDir(const std::string &oldDir, const std::string &msg) {
std::string currentPath = oldDir;
bool dirChanged = true;
int selection = 0, sPos = 0;
std::vector<DirEntry> dirContents;
if (dirChanged) {
dirChanged = false;
dirContents.clear();
chdir(oldDir.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, {"/"});
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
}
while(1) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, msg, 380);
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, currentPath, 390);
GFX::DrawBottom();
Gui::Draw_Rect(0, 215, 320, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 320, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 220, 0.5f, TEXT_COLOR, Lang::get("START_SELECT"), 390);
if (dirContents.size() > 0) {
for(int i = 0; i < 7 && i < (int)dirContents.size(); i++) {
GFX::drawBox(10, mainButtons[i].y, 300, 22, sPos + i == selection);
Gui::DrawStringCentered(10 - 160 + (300 / 2), mainButtons[i].y + 4, 0.45f, TEXT_COLOR, dirContents[sPos + i].name, 295);
}
}
C3D_FrameEnd(0);
if (dirChanged) {
dirChanged = false;
selection = 0;
sPos = 0;
dirContents.clear();
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, {"/"});
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
}
hidScanInput();
touchPosition touch;
hidTouchRead(&touch);
u32 hRepeat = hidKeysDownRepeat();
if (dirContents.size() > 0) {
if (hRepeat & KEY_DOWN) {
if (selection < (int)dirContents.size() - 1) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = dirContents.size() - 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 7 < (int)dirContents.size()-1) selection += 7;
else selection = dirContents.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 7 > 0) selection -= 7;
else selection = 0;
}
if (hidKeysDown() & KEY_A) {
if (dirContents[selection].isDirectory) {
chdir(dirContents[selection].name.c_str());
char path[PATH_MAX];
getcwd(path, PATH_MAX);
currentPath = path;
dirChanged = true;
}
}
if (hidKeysDown() & KEY_TOUCH) {
for (int i = 0; i < 6; i++) {
if (touching(touch, mainButtons[i])) {
if (i + sPos < (int)dirContents.size()) {
if (dirContents[i + sPos].isDirectory) {
chdir(dirContents[i + sPos].name.c_str());
char path[PATH_MAX];
getcwd(path, PATH_MAX);
currentPath = path;
dirChanged = true;
break;
}
}
}
}
}
if (selection < sPos) sPos = selection;
else if (selection > sPos + 7 - 1) sPos = selection - 7 + 1;
}
if ((hidKeysDown() & KEY_X) || (hidKeysDown() & KEY_START)) {
if (currentPath.size() > 0 && currentPath.back() == '/') currentPath.pop_back(); // Pop back the "/".
return currentPath;
}
if (hidKeysDown() & KEY_B) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
if (strcmp(path, "sdmc:/") == 0 || strcmp(path, "/") == 0) {
return "";
} else {
chdir("..");
getcwd(path, PATH_MAX);
currentPath = path;
dirChanged = true;
}
}
}
}
+124
View File
@@ -0,0 +1,124 @@
/*
* 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 "overlay.hpp"
#include "scriptUtils.hpp"
#include "storeUtils.hpp"
extern bool checkWifiStatus();
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<std::string> languages = { "Bruh", "Dansk", "Deutsch", "English", "Español", "Français", "Italiano", "Lietuvių", "Polski", "Português", "Русский", "日本語" };
static const std::string langsTemp[] = { "br", "da", "de", "en", "es", "fr", "it", "lt", "pl", "pt", "ru", "jp "};
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 85, 4, 150, 22 },
{ 85, 34, 150, 22 },
{ 85, 64, 150, 22 },
{ 85, 94, 150, 22 },
{ 85, 124, 150, 22 },
{ 85, 154, 150, 22 },
{ 85, 184, 150, 22 },
{ 85, 214, 150, 22 }
};
/*
Select a Language.
Can be skipped with `B`.
*/
void Overlays::SelectLanguage() {
bool doOut = false;
int selection = 0, sPos = 0;
while(!doOut) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, Lang::get("SELECT_LANG"));
GFX::DrawBottom();
for(int i = 0; i < 8 && i < (int)languages.size(); i++) {
GFX::drawBox(85, mainButtons[i].y, 150, 22, sPos + i == selection);
Gui::DrawStringCentered(0, mainButtons[i].y + 4, 0.45f, TEXT_COLOR, languages[sPos + i], 280);
}
C3D_FrameEnd(0);
hidScanInput();
touchPosition touch;
hidTouchRead(&touch);
u32 hRepeat = hidKeysDownRepeat();
if (hRepeat & KEY_DOWN) {
if (selection < (int)languages.size() - 1) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = languages.size() - 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 8 < (int)languages.size()-1) selection += 8;
else selection = languages.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 8 > 0) selection -= 8;
else selection = 0;
}
if (hidKeysDown() & KEY_A) {
const std::string l = langsTemp[selection];
config->language(l);
Lang::load(config->language());
doOut = true;
}
if (hidKeysDown() & KEY_TOUCH) {
for (int i = 0; i < 8; i++) {
if (touching(touch, mainButtons[i])) {
if (i + sPos < (int)languages.size()) {
const std::string l = langsTemp[i + sPos];
config->language(l);
Lang::load(config->language());
doOut = true;
}
}
}
}
if (selection < sPos) sPos = selection;
else if (selection > sPos + 8 - 1) sPos = selection - 8 + 1;
if (hidKeysDown() & KEY_B) doOut = true;
}
}
+322
View File
@@ -0,0 +1,322 @@
/*
* 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 "files.hpp"
#include "keyboard.hpp"
#include "overlay.hpp"
#include "qrcode.hpp"
#include "scriptUtils.hpp"
#include "storeUtils.hpp"
#include <unistd.h>
extern bool checkWifiStatus();
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 10, 4, 300, 22 },
{ 10, 34, 300, 22 },
{ 10, 64, 300, 22 },
{ 10, 94, 300, 22 },
{ 10, 124, 300, 22 },
{ 10, 154, 300, 22 },
{ 10, 184, 300, 22 },
/* Add, Delete, Info.. */
{ 92, 215, 16, 16 },
{ 136, 215, 16, 16 },
{ 180, 215, 16, 16 },
{ 224, 215, 16, 16 }
};
/*
Delete a Store.. including the Spritesheets, if found.
const std::string &file: The file of the UniStore.
*/
static void DeleteStore(const std::string &file) {
FILE *temp = fopen((std::string(_STORE_PATH) + file).c_str(), "rt");
nlohmann::json storeJson = nlohmann::json::parse(temp, nullptr, false);
fclose(temp);
/* Check, if Spritesheet exist on UniStore. */
if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) {
const std::vector<std::string> sht = storeJson["storeInfo"]["sheet"].get<std::vector<std::string>>();
/* Cause it's an array, delete all Spritesheets which exist. */
for (int i = 0; i < (int)sht.size(); i++) {
if ((std::string(_STORE_PATH) + sht[i]) != "") {
if (!(StringUtils::lower_case(sht[i]).find(StringUtils::lower_case("/")) != std::string::npos)) {
if (access((std::string(_STORE_PATH) + sht[i]).c_str(), F_OK) == 0) {
deleteFile((std::string(_STORE_PATH) + sht[i]).c_str());
}
}
}
}
/* Else, if it's just a string.. check and delete single Spritesheet. */
} else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) {
const std::string fl = storeJson["storeInfo"]["sheet"];
if ((std::string(_STORE_PATH) + fl) != "") {
if (!(StringUtils::lower_case(fl).find(StringUtils::lower_case("/")) != std::string::npos)) {
if (access((std::string(_STORE_PATH) + fl).c_str(), F_OK) == 0) {
deleteFile((std::string(_STORE_PATH) + fl).c_str());
}
}
}
}
deleteFile((std::string(_STORE_PATH) + file).c_str()); // Now delete UniStore.
}
/*
Download a Store.. including the SpriteSheets, if found.
bool Cam: if cam should be used.
*/
static bool DownloadStore(bool Cam = true) {
bool doSheet = false;
std::string file = "";
const std::string URL = Cam ? QR_Scanner::GetQRURL() : Input::setkbdString(150, Lang::get("ENTER_URL"));
if (URL != "") doSheet = DownloadUniStore(URL, -1, file, true);
if (doSheet) {
FILE *temp = fopen(file.c_str(), "rt");
nlohmann::json storeJson = nlohmann::json::parse(temp, nullptr, false);
fclose(temp);
if (doSheet) {
if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_array()) {
if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) {
const std::vector<std::string> locs = storeJson["storeInfo"]["sheetURL"].get<std::vector<std::string>>();
const std::vector<std::string> sht = storeJson["storeInfo"]["sheet"].get<std::vector<std::string>>();
if (locs.size() == sht.size()) {
for (int i = 0; i < (int)sht.size(); i++) {
if (!(sht[i].find("/") != std::string::npos)) {
char msg[150];
snprintf(msg, sizeof(msg), Lang::get("DOWNLOADING_SPRITE_SHEET2").c_str(), i + 1, sht.size());
Msg::DisplayMsg(msg);
DownloadSpriteSheet(locs[i], sht[i]);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
}
}
}
}
} else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) {
if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_string()) {
const std::string fl = storeJson["storeInfo"]["sheetURL"];
const std::string fl2 = storeJson["storeInfo"]["sheet"];
if (!(fl2.find("/") != std::string::npos)) {
Msg::DisplayMsg(Lang::get("DOWNLOADING_SPRITE_SHEET"));
DownloadSpriteSheet(fl, fl2);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
}
}
}
}
}
return doSheet;
}
/*
This is the UniStore Manage Handle.
Here you can..
- Delete a UniStore.
- Download / Add a UniStore.
- Check for Updates for a UniStore.
- Switch the UniStore.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the Store Entries.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
void Overlays::SelectStore(std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::unique_ptr<Meta> &meta) {
bool doOut = false;
int selection = 0, sPos = 0;
std::vector<UniStoreInfo> info = GetUniStoreInfo(_STORE_PATH);
while(!doOut) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, Lang::get("SELECT_UNISTORE_2"));
if (info.size() > 0) {
if (info[selection].StoreSize != -1) {
Gui::DrawStringCentered(0, 30, 0.6f, TEXT_COLOR, info[selection].Title, 370);
Gui::DrawStringCentered(0, 60, 0.5f, TEXT_COLOR, info[selection].Author, 370);
if (info[selection].Description != "") {
/* "\n\n" breaks C2D_WordWrap, so check here. */
if (!(info[selection].Description.find("\n\n") != std::string::npos)) {
Gui::DrawStringCentered(0, 100, 0.5f, TEXT_COLOR, info[selection].Description, 390, 95, nullptr, C2D_WordWrap);
} else {
Gui::DrawStringCentered(0, 100, 0.5f, TEXT_COLOR, info[selection].Description, 390, 95);
}
}
} else {
Gui::DrawStringCentered(0, 30, 0.6f, TEXT_COLOR, Lang::get("INVALID_UNISTORE"), 370);
}
Gui::DrawString(10, 200, 0.4, TEXT_COLOR, "- " + Lang::get("ENTRIES") + ": " + std::to_string(info[selection].StoreSize));
Gui::DrawString(10, 210, 0.4, TEXT_COLOR, "- " + Lang::get("VERSION") + ": " + std::to_string(info[selection].Version));
Gui::DrawString(10, 220, 0.4, TEXT_COLOR, "- " + Lang::get("REVISION") + ": " + std::to_string(info[selection].Revision));
GFX::DrawBottom();
for(int i = 0; i < 7 && i < (int)info.size(); i++) {
GFX::drawBox(10, mainButtons[i].y, 300, 22, sPos + i == selection);
Gui::DrawStringCentered(10 - 160 + (300 / 2), mainButtons[i].y + 4, 0.45f, TEXT_COLOR, info[sPos + i].FileName, 295);
}
}
if (info.size() <= 0) GFX::DrawBottom(); // Otherwise we'd draw on top.
GFX::DrawSprite(sprites_delete_idx, mainButtons[7].x, mainButtons[7].y);
GFX::DrawSprite(sprites_update_idx, mainButtons[8].x, mainButtons[8].y);
GFX::DrawSprite(sprites_add_idx, mainButtons[9].x, mainButtons[9].y);
GFX::DrawSprite(sprites_qr_code_idx, mainButtons[10].x, mainButtons[10].y);
C3D_FrameEnd(0);
hidScanInput();
touchPosition touch;
hidTouchRead(&touch);
u32 hRepeat = hidKeysDownRepeat();
if (info.size() > 0) {
if (hRepeat & KEY_DOWN) {
if (selection < (int)info.size() - 1) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = info.size() - 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 7 < (int)info.size()-1) selection += 7;
else selection = info.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 7 > 0) selection -= 8;
else selection = 0;
}
if (hidKeysDown() & KEY_A) {
/* Load selected one. */
if (info[selection].Version == -1) Msg::waitMsg(Lang::get("UNISTORE_INVALID_ERROR"));
else if (info[selection].Version < 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_OLD"));
else if (info[selection].Version > 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_NEW"));
else {
store = std::make_unique<Store>(_STORE_PATH + info[selection].FileName);
StoreUtils::ResetAll(store, meta, entries);
config->lastStore(info[selection].FileName);
StoreUtils::SortEntries(false, SortType::LAST_UPDATED, entries);
doOut = true;
}
}
if (hidKeysDown() & KEY_TOUCH) {
for (int i = 0; i < 7; i++) {
if (touching(touch, mainButtons[i])) {
if (i + sPos < (int)info.size()) {
if (info[i + sPos].Version == -1) Msg::waitMsg(Lang::get("UNISTORE_INVALID_ERROR"));
else if (info[i + sPos].Version < 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_OLD"));
else if (info[i + sPos].Version > 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_NEW"));
else {
store = std::make_unique<Store>(_STORE_PATH + info[i + sPos].FileName);
StoreUtils::ResetAll(store, meta, entries);
config->lastStore(info[i + sPos].FileName);
doOut = true;
}
}
}
}
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[8])) {
if (checkWifiStatus()) {
if (info[selection].Revision > 0) {
const bool result = IsUpdateAvailable(info[selection].URL, info[selection].Revision);
Msg::waitMsg((result ? Lang::get("UPDATE_AVAILABLE") : Lang::get("UPDATE_NOT_AVAILABLE")));
}
}
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[7])) {
if (info[selection].FileName != "") {
DeleteStore(info[selection].FileName);
selection = 0;
info = GetUniStoreInfo(_STORE_PATH);
}
}
if (selection < sPos) sPos = selection;
else if (selection > sPos + 7 - 1) sPos = selection - 7 + 1;
}
if ((hidKeysDown() & KEY_Y) || (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[9]))) {
if (checkWifiStatus()) {
if (DownloadStore(false)) {
selection = 0;
info = GetUniStoreInfo(_STORE_PATH);
}
}
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[10])) {
if (checkWifiStatus()) {
if (DownloadStore()) {
selection = 0;
info = GetUniStoreInfo(_STORE_PATH);
}
}
}
if (hidKeysDown() & KEY_B) doOut = true;
}
}