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
+154
View File
@@ -0,0 +1,154 @@
/*
* 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 "scriptUtils.hpp"
#include "storeUtils.hpp"
#include "structs.hpp"
#define DOWNLOAD_ENTRIES 8
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> downloadBoxes = {
{ 54, 4, 262, 22 },
{ 54, 34, 262, 22 },
{ 54, 64, 262, 22 },
{ 54, 94, 262, 22 },
{ 54, 124, 262, 22 },
{ 54, 154, 262, 22 },
{ 54, 184, 262, 22 },
{ 54, 214, 262, 22 }
};
/*
Draw the Download Entries part.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::vector<std::string> &entries: Const Reference to the download list as a vector of strings.
const bool &fetch: Const Reference to Fetch.
*/
void StoreUtils::DrawDownList(const std::unique_ptr<Store> &store, const std::vector<std::string> &entries, const bool &fetch) {
if (store && !fetch) {
if (entries.size() > 0) {
for (int i = 0; i < DOWNLOAD_ENTRIES && i < (int)entries.size(); i++) {
GFX::drawBox(downloadBoxes[i].x, downloadBoxes[i].y, downloadBoxes[i].w, downloadBoxes[i].h, store->GetDownloadIndex() == i + store->GetDownloadSIndex());
Gui::DrawStringCentered(54 - 160 + (262 / 2), downloadBoxes[i].y + 4, 0.45f, TEXT_COLOR, entries[(i + store->GetDownloadSIndex())], 260);
}
} else { // If no downloads available..
Gui::DrawStringCentered(25, downloadBoxes[0].y + 4, 0.5f, TEXT_COLOR, Lang::get("NO_DOWNLOADS_AVAILABLE"), 260);
}
}
}
/*
This is the Download List handle.
Here you can..
- Scroll through the download list, if any available.
- Execute an Entry of the download list.
- Return back to EntryInfo through `B`.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
const std::unique_ptr<Store> &store: Const Reference to the Store class, since we do not modify anything in it.
const std::unique_ptr<StoreEntry> &entry: Const Reference to the current StoreEntry, since we do not modify anything in it.
const std::vector<std::string> &entries: Const Reference to the download list, since we do not modify anything in it.
int &currentMenu: Reference to the StoreMode / Menu, so we can switch back to EntryInfo with `B`.
std::unique_ptr<Meta> &meta: Reference to the Meta, to apply the updates stuff.
const int &lastMode: Const Reference to the last mode.
int &smallDelay: Reference to the small delay. This helps to not directly press A.
*/
void StoreUtils::DownloadHandle(u32 hDown, u32 hHeld, touchPosition touch, const std::unique_ptr<Store> &store, const std::unique_ptr<StoreEntry> &entry, const std::vector<std::string> &entries, int &currentMenu, std::unique_ptr<Meta> &meta, const int &lastMode, int &smallDelay) {
if (store && entry) { // Ensure, store & entry is not a nullptr.
if (smallDelay > 0) {
smallDelay--;
}
if (hRepeat & KEY_DOWN) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() < (int)entries.size() - 1) store->SetDownloadIndex(store->GetDownloadIndex() + 1);
else store->SetDownloadIndex(0);
}
if (hRepeat & KEY_UP) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() > 0) store->SetDownloadIndex(store->GetDownloadIndex() - 1);
else store->SetDownloadIndex(entries.size() - 1);
}
if (hRepeat & KEY_RIGHT) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() + DOWNLOAD_ENTRIES < (int)entries.size()-1) store->SetDownloadIndex(store->GetDownloadIndex() + DOWNLOAD_ENTRIES);
else store->SetDownloadIndex(entries.size()-1);
}
if (hRepeat & KEY_LEFT) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() - DOWNLOAD_ENTRIES > 0) store->SetDownloadIndex(store->GetDownloadIndex() - DOWNLOAD_ENTRIES);
else store->SetDownloadIndex(0);
}
if (smallDelay == 0 && hDown & KEY_TOUCH) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
for (int i = 0; i < DOWNLOAD_ENTRIES; i++) {
if (touching(touch, downloadBoxes[i])) {
if (i + store->GetDownloadSIndex() < (int)entries.size()) {
const std::string tmp = Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[i + store->GetDownloadSIndex()];
if (Msg::promptMsg(tmp)) {
ScriptUtils::runFunctions(store->GetJson(), entry->GetEntryIndex(), entries[i + store->GetDownloadSIndex()]);
if (meta) meta->SetUpdated(store->GetUniStoreTitle(), entry->GetTitle(), entry->GetLastUpdated());
entry->SetUpdateAvl(false);
}
}
}
}
}
if (smallDelay == 0 && hDown & KEY_A) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
const std::string tmp = Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[store->GetDownloadIndex()];
if (Msg::promptMsg(tmp)) {
ScriptUtils::runFunctions(store->GetJson(), entry->GetEntryIndex(), entries[store->GetDownloadIndex()]);
if (meta) meta->SetUpdated(store->GetUniStoreTitle(), entry->GetTitle(), entry->GetLastUpdated());
entry->SetUpdateAvl(false);
}
}
if (hDown & KEY_B) currentMenu = lastMode; // Go back to EntryInfo.
/* Scroll Handle. */
if (store->GetDownloadIndex() < store->GetDownloadSIndex()) store->SetDownloadSIndex(store->GetDownloadIndex());
else if (store->GetDownloadIndex() > store->GetDownloadSIndex() + DOWNLOAD_ENTRIES - 1) store->SetDownloadSIndex(store->GetDownloadIndex() - DOWNLOAD_ENTRIES + 1);
}
}
+83
View File
@@ -0,0 +1,83 @@
/*
* 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 "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const Structs::ButtonPos btn = { 53, 215, 20, 20 };
/*
Draw the Entry Info part.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::unique_ptr<StoreEntry> &entry: Const Reference to the current StoreEntry.
*/
void StoreUtils::DrawEntryInfo(const std::unique_ptr<Store> &store, const std::unique_ptr<StoreEntry> &entry) {
if (store && entry) { // Ensure, store & entry is not a nullptr.
Gui::Draw_Rect(48, 0, 272, 36, ENTRY_BAR_COLOR);
Gui::Draw_Rect(48, 36, 272, 1, ENTRY_BAR_OUTL_COLOR);
Gui::DrawStringCentered(25, 0, 0.6, TEXT_COLOR, entry->GetTitle(), 265);
Gui::DrawStringCentered(25, 20, 0.4, TEXT_COLOR, entry->GetAuthor(), 265);
if (entry->GetDescription() != "") {
/* "\n\n" breaks C2D_WordWrap, so check here. */
if (!(entry->GetDescription().find("\n\n") != std::string::npos)) {
Gui::DrawStringCentered(25, 50, 0.4, TEXT_COLOR, entry->GetDescription(), 220, 0, nullptr, C2D_WordWrap);
} else {
Gui::DrawStringCentered(25, 50, 0.4, TEXT_COLOR, entry->GetDescription(), 220, 0);
}
}
Gui::DrawString(61, 130, 0.45, TEXT_COLOR, Lang::get("VERSION") + ": " + entry->GetVersion(), 240);
Gui::DrawString(61, 145, 0.45, TEXT_COLOR, Lang::get("CATEGORY") + ": " + entry->GetCategory(), 240);
Gui::DrawString(61, 160, 0.45, TEXT_COLOR, Lang::get("CONSOLE") + ": " + entry->GetConsole(), 240);
Gui::DrawString(61, 175, 0.45, TEXT_COLOR, Lang::get("LAST_UPDATED") + ": " + entry->GetLastUpdated(), 240);
Gui::DrawString(61, 190, 0.45, TEXT_COLOR, Lang::get("LICENSE") + ": " + entry->GetLicense(), 240);
GFX::drawBox(btn.x, btn.y, btn.w, btn.h, false);
Gui::DrawString(btn.x + 3, btn.y, 0.6f, TEXT_COLOR, "");
}
}
/*
The EntryInfo handle.
Here you can..
- Go to the download list, by pressing `A`.
- Show the MarkMenu with START.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
bool &showMark: Reference to showMark.. to show the mark menu.
bool &fetch: Reference to fetch, so we know, if we need to fetch, when accessing download list.
*/
void StoreUtils::EntryHandle(u32 hDown, u32 hHeld, touchPosition touch, bool &showMark, bool &fetch) {
if ((hDown & KEY_START) || (hDown & KEY_TOUCH && touching(touch, btn))) showMark = true;
}
+175
View File
@@ -0,0 +1,175 @@
/*
* 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 "storeUtils.hpp"
#include "structs.hpp"
static const std::vector<Structs::ButtonPos> GridBoxes = {
{25, 45, 50, 50},
{100, 45, 50, 50},
{175, 45, 50, 50},
{250, 45, 50, 50},
{325, 45, 50, 50},
{25, 105, 50, 50},
{100, 105, 50, 50},
{175, 105, 50, 50},
{250, 105, 50, 50},
{325, 105, 50, 50},
{25, 165, 50, 50},
{100, 165, 50, 50},
{175, 165, 50, 50},
{250, 165, 50, 50},
{325, 165, 50, 50}
};
/*
Draw the Top Grid.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::vector<std::unique_ptr<StoreEntry>> &entries: Const Reference to the StoreEntries.
*/
void StoreUtils::DrawGrid(const std::unique_ptr<Store> &store, const std::vector<std::unique_ptr<StoreEntry>> &entries) {
if (store) { // Ensure, store is not a nullptr.
for (int i = 0, i2 = 0 + (store->GetScreenIndx() * 5); i2 < 15 + (store->GetScreenIndx() * 5) && i2 < (int)entries.size(); i2++, i++) {
/* Boxes. */
if (i == store->GetBox()) {
GFX::drawBox(GridBoxes[i].x, GridBoxes[i].y, 50, 50, true);
} else {
GFX::drawBox(GridBoxes[i].x, GridBoxes[i].y, 50, 50, false);
}
/* Ensure, entries is larger than the index. */
if ((int)entries.size() > i2) {
if (entries[i2]) { // Ensure, the Entry is not nullptr.
const C2D_Image tempImg = entries[i2]->GetIcon();
const uint8_t offsetW = (48 - tempImg.subtex->width) / 2; // Center W.
const uint8_t offsetH = (48 - tempImg.subtex->height) / 2; // Center H.
C2D_DrawImageAt(tempImg, GridBoxes[i].x + 1 + offsetW, GridBoxes[i].y + 1 + offsetH, 0.5);
/* Update Available mark. */
if (entries[i2]->GetUpdateAvl()) GFX::DrawSprite(sprites_update_app_idx, GridBoxes[i].x + 32, GridBoxes[i].y + 32);
}
}
}
}
}
/*
Top Grid Logic Handle.
Here you can..
- Scroll through the Grid with the D-Pad.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
const int &currentMode: Reference to the current Mode.
int &lastMode: Reference to the last mode.
bool &fetch: Reference to fetch.
int &smallDelay: Reference to the small delay.
*/
void StoreUtils::GridLogic(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, int &currentMode, int &lastMode, bool &fetch, int &smallDelay) {
if (store) { // Ensure, store is not a nullptr.
bool needUpdate = false;
if (hRepeat & KEY_DOWN) {
if (store->GetBox() > 9) {
if (store->GetEntry() + 5 < (int)entries.size()) {
store->SetEntry(store->GetEntry() + 5);
needUpdate = true;
}
} else {
if (store->GetEntry() + 5 < (int)entries.size()) {
store->SetBox(store->GetBox() + 5);
store->SetEntry(store->GetEntry() + 5);
}
}
}
if (hRepeat & KEY_RIGHT) {
if (store->GetEntry() < (int)entries.size() - 1) {
if (store->GetBox() < 14) {
store->SetBox(store->GetBox() + 1);
store->SetEntry(store->GetEntry() + 1);
}
}
}
if (hRepeat & KEY_LEFT) {
if (store->GetEntry() > 0) {
if (store->GetBox() > 0) {
store->SetBox(store->GetBox() - 1);
store->SetEntry(store->GetEntry() - 1);
}
}
}
if (hRepeat & KEY_UP) {
if (store->GetBox() < 5) {
if (store->GetEntry() > 4) {
store->SetEntry(store->GetEntry() - 5);
needUpdate = true;
}
} else {
store->SetBox(store->GetBox() - 5);
store->SetEntry(store->GetEntry() - 5);
}
}
if (hDown & KEY_A) {
fetch = true;
smallDelay = 5;
lastMode = currentMode;
currentMode = 1;
}
if (needUpdate) {
needUpdate = false;
/* Scroll Logic. */
if (store->GetBox() > 9) {
if (store->GetEntry() < (int)entries.size()) {
store->SetScreenIndx(store->GetScreenIndx() + 1);
}
} else if (store->GetBox() < 5) {
if (store->GetScreenIndx() > 0) {
store->SetScreenIndx(store->GetScreenIndx() - 1);
}
}
}
}
}
+118
View File
@@ -0,0 +1,118 @@
/*
* 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 "storeUtils.hpp"
#include "structs.hpp"
static const std::vector<Structs::ButtonPos> StoreBoxesList = {
{ 20, 45, 360, 50 },
{ 20, 105, 360, 50 },
{ 20, 165, 360, 50 }
};
/*
Draw the top List.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::vector<std::unique_ptr<StoreEntry>> &entries: Const Reference to the StoreEntries.
*/
void StoreUtils::DrawList(const std::unique_ptr<Store> &store, const std::vector<std::unique_ptr<StoreEntry>> &entries) {
if (store) { // Ensure, store is not a nullptr.
if (entries.size() > 0) {
for (int i = 0; i < 3 && i < (int)entries.size(); i++) {
/* Boxes. */
GFX::drawBox(StoreBoxesList[i].x, StoreBoxesList[i].y, StoreBoxesList[i].w, StoreBoxesList[i].h, i + store->GetScreenIndx() == store->GetEntry());
/* Ensure, entries is larger than the index. */
if ((int)entries.size() > i + store->GetScreenIndx()) {
if (entries[i + store->GetScreenIndx()]) { // Ensure, the Entry is not nullptr.
const C2D_Image tempImg = entries[i + store->GetScreenIndx()]->GetIcon();
const uint8_t offsetW = (48 - tempImg.subtex->width) / 2; // Center W.
const uint8_t offsetH = (48 - tempImg.subtex->height) / 2; // Center H.
C2D_DrawImageAt(tempImg, StoreBoxesList[i].x + 1 + offsetW, StoreBoxesList[i].y + 1 + offsetH, 0.5);
}
if (entries[i + store->GetScreenIndx()]->GetUpdateAvl()) GFX::DrawSprite(sprites_update_app_idx, StoreBoxesList[i].x + 32, StoreBoxesList[i].y + 32);
Gui::DrawStringCentered(29, StoreBoxesList[i].y + 5, 0.6f, TEXT_COLOR, entries[i + store->GetScreenIndx()]->GetTitle(), 300);
Gui::DrawStringCentered(29, StoreBoxesList[i].y + 24, 0.6f, TEXT_COLOR, entries[i + store->GetScreenIndx()]->GetAuthor(), 300);
}
}
}
}
}
/*
Top List Logic Handle.
Here you can..
- Scroll through the Grid with the D-Pad Up / Down and skip 3 Entries with Left / Right.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
int &currentMode: Const Reference to the current Mode.
int &lastMode: Reference to the last mode.
bool &fetch: Reference to fetch.
int &smallDelay: Reference to the small delay.
*/
void StoreUtils::ListLogic(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, int &currentMode, int &lastMode, bool &fetch, int &smallDelay) {
if (store) { // Ensure, store is not a nullptr.
if (hRepeat & KEY_DOWN) {
if (store->GetEntry() < (int)entries.size() - 1) store->SetEntry(store->GetEntry() + 1);
else store->SetEntry(0);
}
if (hRepeat & KEY_RIGHT) {
if (store->GetEntry() < (int)entries.size() - 3) store->SetEntry(store->GetEntry() + 3);
else store->SetEntry(entries.size() - 1);
}
if (hRepeat & KEY_LEFT) {
if (store->GetEntry() - 2 > 0) store->SetEntry(store->GetEntry() - 3);
}
if (hRepeat & KEY_UP) {
if (store->GetEntry() > 0) store->SetEntry(store->GetEntry() - 1);
else store->SetEntry(entries.size() - 1);
}
if (hDown & KEY_A) {
fetch = true;
smallDelay = 5;
lastMode = currentMode;
currentMode = 1;
}
/* Scroll Logic. */
if (store->GetEntry() < store->GetScreenIndx()) store->SetScreenIndx(store->GetEntry());
else if (store->GetEntry() > store->GetScreenIndx() + 3 - 1) store->SetScreenIndx(store->GetEntry() - 3 + 1);
}
}
+123
View File
@@ -0,0 +1,123 @@
/*
* 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 "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> markBox = {
{10, 94, 52, 52},
{72, 94, 52, 52},
{134, 94, 52, 52},
{196, 94, 52, 52},
{258, 94, 52, 52},
{ 53, 215, 20, 20 }
};
/*
Draw the Marking part.
const int &marks: A Reference to the active mark flags.
*/
void StoreUtils::DisplayMarkBox(const int &marks) {
Gui::Draw_Rect(0, 0, 320, 240, DIM_COLOR); // Darken.
GFX::drawBox(markBox[0].x, markBox[0].y, markBox[0].w, markBox[0].h, marks & favoriteMarks::STAR);
GFX::drawBox(markBox[1].x, markBox[1].y, markBox[1].w, markBox[1].h, marks & favoriteMarks::HEART);
GFX::drawBox(markBox[2].x, markBox[2].y, markBox[2].w, markBox[2].h, marks & favoriteMarks::DIAMOND);
GFX::drawBox(markBox[3].x, markBox[3].y, markBox[3].w, markBox[3].h, marks & favoriteMarks::CLUBS);
GFX::drawBox(markBox[4].x, markBox[4].y, markBox[4].w, markBox[4].h, marks & favoriteMarks::SPADE);
Gui::DrawString(markBox[0].x + 15, markBox[0].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[1].x + 15, markBox[1].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[2].x + 15, markBox[2].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[3].x + 15, markBox[3].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[4].x + 15, markBox[4].y + 12, 0.9, TEXT_COLOR, "");
GFX::drawBox(markBox[5].x, markBox[5].y, markBox[5].w, markBox[5].h, false);
Gui::DrawString(markBox[5].x + 3, markBox[5].y, 0.6f, TEXT_COLOR, "");
}
/*
Mark Menu handle.
Here you can..
- Mark the selected app.
- Return to EntryInfo with `B`.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<StoreEntry> &entry: Reference to the current StoreEntry.
const std::unique_ptr<Store> &store: Const Reference to the Store, since we do not modify anything there.
bool &showMark: Reference to showMark, so we know, if we should stay here or not.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
void StoreUtils::MarkHandle(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<StoreEntry> &entry, const std::unique_ptr<Store> &store, bool &showMark, std::unique_ptr<Meta> &meta) {
hidScanInput();
touchPosition t;
hidTouchRead(&t);
if (meta && entry) {
if (hidKeysDown() & KEY_TOUCH) {
/* Star. */
if (touching(t, markBox[0])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::STAR);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Heart. */
} else if (touching(t, markBox[1])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::HEART);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Diamond. */
} else if (touching(t, markBox[2])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::DIAMOND);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Clubs. */
} else if (touching(t, markBox[3])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::CLUBS);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Spade. */
} else if (touching(t, markBox[4])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::SPADE);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
}
}
}
if ((hidKeysDown() & KEY_B || hidKeysDown() & KEY_START) || (hidKeysDown() & KEY_TOUCH && touching(t, markBox[5]))) showMark = false; // Return back to screen.
}
+140
View File
@@ -0,0 +1,140 @@
/*
* 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 "common.hpp"
#include "fileBrowse.hpp"
#include "meta.hpp"
#include <unistd.h>
/*
The Constructor of the Meta.
Includes MetaData file creation, if non existent.
*/
Meta::Meta() {
if (access(_META_PATH, F_OK) != 0) {
FILE *temp = fopen(_META_PATH, "w");
char tmp[2] = { '{', '}' };
fwrite(tmp, sizeof(tmp), 1, temp);
fclose(temp);
}
FILE *temp = fopen(_META_PATH, "rt");
this->metadataJson = nlohmann::json::parse(temp, nullptr, false);
fclose(temp);
if (config->metadata()) this->ImportMetadata();
}
/*
Import the old Metadata of the 'updates.json' file.
*/
void Meta::ImportMetadata() {
if (access("sdmc:/3ds/Universal-Updater/updates.json", F_OK) != 0) {
config->metadata(false);
return; // Not found.
}
Msg::DisplayMsg(Lang::get("FETCHING_METADATA"));
FILE *old = fopen("sdmc:/3ds/Universal-Updater/updates.json", "r");
nlohmann::json oldJson = nlohmann::json::parse(old, nullptr, false);
fclose(old);
std::vector<UniStoreInfo> info = GetUniStoreInfo(_STORE_PATH); // Fetch UniStores.
for (int i = 0; i < (int)info.size(); i++) {
if (info[i].Title != "" && oldJson.contains(info[i].FileName)) {
for(auto it = oldJson[info[i].FileName].begin(); it != oldJson[info[i].FileName].end(); ++it) {
this->SetUpdated(info[i].Title, it.key().c_str(), it.value().get<std::string>());
}
}
}
config->metadata(false);
}
/*
Get Last Updated.
std::string unistoreName: The UniStore name.
std::string entry: The Entry name.
*/
std::string Meta::GetUpdated(std::string unistoreName, std::string entry) const {
if (!this->metadataJson.contains(unistoreName)) return ""; // UniStore Name does not exist.
if (!this->metadataJson[unistoreName].contains(entry)) return ""; // Entry does not exist.
if (!this->metadataJson[unistoreName][entry].contains("updated")) return ""; // updated does not exist.
if (this->metadataJson[unistoreName][entry]["updated"].is_string()) return this->metadataJson[unistoreName][entry]["updated"];
return "";
}
/*
Get the marks.
std::string unistoreName: The UniStore name.
std::string entry: The Entry name.
*/
int Meta::GetMarks(std::string unistoreName, std::string entry) const {
int temp = 0;
if (!this->metadataJson.contains(unistoreName)) return temp; // UniStore Name does not exist.
if (!this->metadataJson[unistoreName].contains(entry)) return temp; // Entry does not exist.
if (!this->metadataJson[unistoreName][entry].contains("marks")) return temp; // marks does not exist.
if (this->metadataJson[unistoreName][entry]["marks"].is_number()) return this->metadataJson[unistoreName][entry]["marks"];
return temp;
}
/*
Return, if update available.
std::string unistoreName: The UniStore name.
std::string entry: The Entry name.
std::string updated: Compare for the update.
*/
bool Meta::UpdateAvailable(std::string unistoreName, std::string entry, std::string updated) const {
if (this->GetUpdated(unistoreName, entry) != "" && updated != "") {
return strcasecmp(updated.c_str(), this->GetUpdated(unistoreName, entry).c_str()) > 0;
}
return false;
}
/*
The save call.
Write to file.. called on destructor.
*/
void Meta::SaveCall() {
FILE *file = fopen(_META_PATH, "wb");
const std::string dump = this->metadataJson.dump(1, '\t');
fwrite(dump.c_str(), 1, dump.size(), file);
fclose(file);
}
+185
View File
@@ -0,0 +1,185 @@
/*
* 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 "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> SearchMenu = {
{ 55, 5, 258, 30 }, // Search bar.
/* Includes. */
{ 85, 84, 10, 10 },
{ 85, 100, 10, 10 },
{ 167, 84, 10, 10 },
{ 167, 100, 10, 10 },
/* Filters. */
{ 82, 170, 30, 30 },
{ 117, 170, 30, 30 },
{ 152, 170, 30, 30 },
{ 187, 170, 30, 30 },
{ 222, 170, 30, 30 },
{ 257, 170, 30, 30 }
};
/*
Draw the Search + Filter Menu.
const std::vector<bool> &searchIncludes: Const Reference to the searchIncludes.
const std::string &searchResult: Const Reference to the searchResult.
const int &marks: Const Reference to the filter mark flags.
const bool &updateFilter: Const Reference to the update filter.
*/
void StoreUtils::DrawSearchMenu(const std::vector<bool> &searchIncludes, const std::string &searchResult, const int &marks, const bool &updateFilter) {
Gui::Draw_Rect(54, 4, 260, SearchMenu[0].h + 2, SEARCH_BAR_OUTL_COLOR);
Gui::Draw_Rect(SearchMenu[0].x, SearchMenu[0].y, SearchMenu[0].w, SearchMenu[0].h, SEARCH_BAR_COLOR);
Gui::DrawStringCentered(28, 10, 0.6, TEXT_COLOR, searchResult, 265);
/* Checkboxes. */
for (int i = 0; i < 4; i++) {
GFX::DrawCheckbox(SearchMenu[i + 1].x, SearchMenu[i + 1].y, searchIncludes[i]);
}
Gui::DrawString(84, 60, 0.5, TEXT_COLOR, Lang::get("INCLUDE_IN_RESULTS"));
Gui::DrawString(SearchMenu[1].x + 18, SearchMenu[1].y + 1, 0.4, TEXT_COLOR, Lang::get("TITLE"));
Gui::DrawString(SearchMenu[2].x + 18, SearchMenu[2].y + 1, 0.4, TEXT_COLOR, Lang::get("AUTHOR"));
Gui::DrawString(SearchMenu[3].x + 18, SearchMenu[3].y + 1, 0.4, TEXT_COLOR, Lang::get("CATEGORY"));
Gui::DrawString(SearchMenu[4].x + 18, SearchMenu[4].y + 1, 0.4, TEXT_COLOR, Lang::get("CONSOLE"));
/* Filters. */
Gui::DrawString(84, 150, 0.5, TEXT_COLOR, Lang::get("FILTER_TO"));
GFX::drawBox(SearchMenu[5].x, SearchMenu[5].y, SearchMenu[5].w, SearchMenu[5].h, marks & favoriteMarks::STAR);
GFX::drawBox(SearchMenu[6].x, SearchMenu[6].y, SearchMenu[6].w, SearchMenu[6].h, marks & favoriteMarks::HEART);
GFX::drawBox(SearchMenu[7].x, SearchMenu[7].y, SearchMenu[7].w, SearchMenu[7].h, marks & favoriteMarks::DIAMOND);
GFX::drawBox(SearchMenu[8].x, SearchMenu[8].y, SearchMenu[8].w, SearchMenu[8].h, marks & favoriteMarks::CLUBS);
GFX::drawBox(SearchMenu[9].x, SearchMenu[9].y, SearchMenu[9].w, SearchMenu[9].h, marks & favoriteMarks::SPADE);
GFX::drawBox(SearchMenu[10].x, SearchMenu[10].y, SearchMenu[10].w, SearchMenu[10].h, updateFilter);
GFX::DrawSprite(sprites_update_filter_idx, SearchMenu[10].x + 8, SearchMenu[10].y + 8);
Gui::DrawString(SearchMenu[5].x + 8, SearchMenu[5].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[6].x + 8, SearchMenu[6].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[7].x + 8, SearchMenu[7].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[8].x + 8, SearchMenu[8].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[9].x + 8, SearchMenu[9].y + 8, 0.5, TEXT_COLOR, "");
}
/*
Search + Filter Handle.
Here you can..
- Filter your apps for the marks.
- Search the UniStore.
- Include stuff into the search.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the Store Entries.
std::vector<bool> &searchIncludes: Reference to the searchIncludes.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
std::string &searchResult: Reference to the searchResult.
int &marks: Reference to the mark flags.
bool &updateFilter: Reference to the update filter.
*/
void StoreUtils::SearchHandle(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::vector<bool> &searchIncludes, std::unique_ptr<Meta> &meta, std::string &searchResult, int &marks, bool &updateFilter, bool ascending, SortType sorttype) {
/* Checkboxes. */
if (hDown & KEY_TOUCH) {
bool didTouch = false;
/* Includes. */
for (int i = 0; i < 4; i++) {
if (touching(touch, SearchMenu[i + 1])) {
searchIncludes[i] = !searchIncludes[i];
didTouch = true;
break;
}
}
/* Search bar. */
if (!didTouch) {
if (touching(touch, SearchMenu[0])) {
searchResult = Input::setkbdString(20, Lang::get("ENTER_SEARCH"));
didTouch = true;
}
}
/* Filters. */
if (!didTouch) {
if (touching(touch, SearchMenu[5])) {
marks = marks ^ favoriteMarks::STAR;
didTouch = true;
} else if (touching(touch, SearchMenu[6])) {
marks = marks ^ favoriteMarks::HEART;
didTouch = true;
} else if (touching(touch, SearchMenu[7])) {
marks = marks ^ favoriteMarks::DIAMOND;
didTouch = true;
} else if (touching(touch, SearchMenu[8])) {
marks = marks ^ favoriteMarks::CLUBS;
didTouch = true;
} else if (touching(touch, SearchMenu[9])) {
marks = marks ^ favoriteMarks::SPADE;
didTouch = true;
} else if (touching(touch, SearchMenu[10])) {
updateFilter = !updateFilter;
didTouch = true;
}
}
if (didTouch) {
if (store && store->GetValid()) { // Only search, when valid.
StoreUtils::ResetAll(store, meta, entries);
StoreUtils::search(entries, searchResult, searchIncludes[0], searchIncludes[1], searchIncludes[2], searchIncludes[3], marks, updateFilter);
store->SetScreenIndx(0);
store->SetEntry(0);
store->SetBox(0);
StoreUtils::SortEntries(ascending, sorttype, entries);
}
}
}
/* Reset all. */
if (hDown & KEY_X) {
marks = 0;
updateFilter = false;
for(uint i = 0; i < searchIncludes.size(); i++)
searchIncludes[i] = false;
searchResult = "";
if (store && store->GetValid()) {
StoreUtils::ResetAll(store, meta, entries);
StoreUtils::SortEntries(ascending, sorttype, entries);
}
}
}
+303
View File
@@ -0,0 +1,303 @@
/*
* 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"
#include "storeUtils.hpp"
extern bool exiting;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 54, 4, 262, 22 },
{ 54, 34, 262, 22 },
{ 54, 64, 262, 22 },
{ 54, 94, 262, 22 },
{ 54, 124, 262, 22 },
{ 54, 154, 262, 22 },
{ 54, 184, 262, 22 }
};
static const std::string autoupdate() { return (config->autoupdate() ? "DISABLE_AUTOUPDATE_UNISTORE" : "ENABLE_AUTOUPDATE_UNISTORE"); };
static const std::string updateCheck() { return (config->updatecheck() ? "DISABLE_UPDATE_CHECK" : "ENABLE_UPDATE_CHECK"); };
static const std::vector<std::string> mainStrings = { "LANGUAGE", "SELECT_UNISTORE", "CHANGE_DIRECTORIES", "CREDITS", "EXIT_APP" };
static const std::vector<std::string> dirStrings = { "CHANGE_3DSX_PATH", "CHANGE_NDS_PATH", "CHANGE_ARCHIVE_PATH" };
/*
Main Settings.
const int &selection: Const Reference to the Settings Selection.
*/
static void DrawSettingsMain(const int &selection) {
for (int i = 0; i < 7; i++) {
GFX::drawBox(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, i == selection);
}
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[0].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[0]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[1].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[1]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[2].y + 4, 0.45f, TEXT_COLOR, Lang::get(autoupdate()), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[3].y + 4, 0.45f, TEXT_COLOR, Lang::get(updateCheck()), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[4].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[2]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[5].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[3]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[6].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[4]), 260);
}
/*
Directory Change Draw.
const int &selection: Const Reference to the Settings Selection.
*/
static void DrawSettingsDir(const int &selection) {
for (int i = 0; i < 3; i++) {
GFX::DrawButton(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, i == selection, Lang::get(dirStrings[i]));
}
}
/*
Settings Main Handle.
Here you can..
- Change the Language.
- Access the UniStore Manage Handle.
- Enable UniStore auto update on boot.
- Show the Credits.
- Exit Universal-Updater.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
int &page: Reference to the page.
bool &dspSettings: Reference to the display Settings.
int &storeMode: Reference to the Store Mode.
int &selection: Reference to the Selection.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
static void SettingsHandleMain(u32 hDown, u32 hHeld, touchPosition touch, int &page, bool &dspSettings, int &storeMode, int &selection, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::unique_ptr<Meta> &meta) {
if (hDown & KEY_B) {
selection = 0;
storeMode = 0;
}
if (hRepeat & KEY_DOWN) {
if (selection < 6) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = mainStrings.size() + 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 8 < (int)mainStrings.size() + 1) selection += 8;
else selection = mainStrings.size() + 1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 8 > 0) selection -= 8;
else selection = 0;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
Overlays::SelectLanguage();
} else if (touching(touch, mainButtons[1])) {
Overlays::SelectStore(store, entries, meta);
} else if (touching(touch, mainButtons[2])) {
config->autoupdate(!config->autoupdate());
} else if (touching(touch, mainButtons[3])) {
config->updatecheck(!config->updatecheck());
} else if (touching(touch, mainButtons[4])) {
selection = 0;
page = 1;
} else if (touching(touch, mainButtons[5])) {
Overlays::ShowCredits();
} else if (touching(touch, mainButtons[6])) {
exiting = true;
}
}
if (hDown & KEY_A) {
switch(selection) {
case 0:
Overlays::SelectLanguage();
break;
case 1:
Overlays::SelectStore(store, entries, meta);
break;
case 2:
config->autoupdate(!config->autoupdate());
break;
case 3:
config->updatecheck(!config->updatecheck());
break;
case 4:
selection = 0;
page = 1;
break;
case 5:
Overlays::ShowCredits();
break;
case 6:
exiting = true;
break;
}
}
}
/*
Directory Handle.
Here you can..
- Change the Directory of...
- 3DSX, NDS & Archives.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
int &page: Reference to the page.
int &selection: Reference to the Selection.
*/
static void SettingsHandleDir(u32 hDown, u32 hHeld, touchPosition touch, int &page, int &selection) {
if (hDown & KEY_B) {
page = 0;
selection = 4;
}
if (hRepeat & KEY_DOWN) {
if (selection < 2) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = dirStrings.size()-1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 8 < (int)dirStrings.size()-1) selection += 8;
else selection = dirStrings.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 8 > 0) selection -= 8;
else selection = 0;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
const std::string path = Overlays::SelectDir(config->_3dsxPath(), Lang::get("SELECT_DIR"));
if (path != "") config->_3dsxPath(path);
} else if (touching(touch, mainButtons[1])) {
const std::string path = Overlays::SelectDir(config->ndsPath(), Lang::get("SELECT_DIR"));
if (path != "") config->ndsPath(path);
} else if (touching(touch, mainButtons[2])) {
const std::string path = Overlays::SelectDir(config->archPath(), Lang::get("SELECT_DIR"));
if (path != "") config->archPath(path);
}
}
if (hDown & KEY_A) {
std::string path = "";
switch(selection) {
case 0:
path = Overlays::SelectDir(config->_3dsxPath(), Lang::get("SELECT_DIR"));
if (path != "") config->_3dsxPath(path);
break;
case 1:
path = Overlays::SelectDir(config->ndsPath(), Lang::get("SELECT_DIR"));
if (path != "") config->ndsPath(path);
break;
case 2:
path = Overlays::SelectDir(config->archPath(), Lang::get("SELECT_DIR"));
if (path != "") config->archPath(path);
break;
}
}
}
/*
Draw the Settings.
const int &page: Const Reference to the page.
const int &selection: Const Reference to the selection.
*/
void StoreUtils::DrawSettings(const int &page, const int &selection) {
switch(page) {
case 0:
DrawSettingsMain(selection);
break;
case 1:
DrawSettingsDir(selection);
break;
}
}
/*
Settings Handle.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
int &page: Reference to the page.
bool &dspSettings: Reference to the display Settings.
int &storeMode: Reference to the Store Mode.
int &selection: Reference to the Selection.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
void StoreUtils::SettingsHandle(u32 hDown, u32 hHeld, touchPosition touch, int &page, bool &dspSettings, int &storeMode, int &selection, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::unique_ptr<Meta> &meta) {
switch(page) {
case 0:
SettingsHandleMain(hDown, hHeld, touch, page, dspSettings, storeMode, selection, store, entries, meta);
break;
case 1:
SettingsHandleDir(hDown, hHeld, touch, page, selection);
break;
}
}
+98
View File
@@ -0,0 +1,98 @@
/*
* 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 "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> sidePos = {
{ 0, 0, 48, 48 },
{ 0, 48, 48, 48 },
{ 0, 96, 48, 48 },
{ 0, 144, 48, 48 },
{ 0, 192, 48, 48 }
};
/*
Draw the Side Menu part.
const int &currentMenu: Const Reference to the current Store Mode / Menu.
*/
void StoreUtils::DrawSideMenu(const int &currentMenu) {
for (int i = 0; i < 5; i++) {
if (i == currentMenu) {
Gui::Draw_Rect(sidePos[i].x, sidePos[i].y, sidePos[i].w, sidePos[i].h, SIDEBAR_SELECTED_COLOR);
} else {
Gui::Draw_Rect(sidePos[i].x, sidePos[i].y, sidePos[i].w, sidePos[i].h, SIDEBAR_UNSELECTED_COLOR);
}
}
GFX::DrawSprite(sprites_info_idx, sidePos[0].x + 4, sidePos[0].y + 4);
GFX::DrawSprite(sprites_download_idx, sidePos[1].x + 4, sidePos[1].y + 4);
GFX::DrawSprite(sprites_search_idx, sidePos[2].x + 4, sidePos[2].y + 4);
GFX::DrawSprite(sprites_sort_idx, sidePos[3].x + 4, sidePos[3].y + 4);
GFX::DrawSprite(sprites_settings_idx, sidePos[4].x + 4, sidePos[4].y + 4);
Gui::Draw_Rect(48, 0, 1, 240, BAR_OUTL_COLOR);
}
/*
Side Menu Handle.
Here you can..
- Switch between the Menus through the sidebar.
u32 hDown: The hidKeysDown() variable.
touchPosition touch: The TouchPosition variable.
int &currentMenu: Reference to the Store Mode / Menu.
bool &fetch: Reference of the download fetch variable.. so we know, if we need to fetch the download entries.
*/
void StoreUtils::SideMenuHandle(u32 hDown, touchPosition touch, int &currentMenu, bool &fetch) {
if (hDown & KEY_TOUCH) {
for (int i = 0; i < 5; i++) {
if (touching(touch, sidePos[i])) {
if (i == 1) fetch = true; // Fetch download list, if 1.
currentMenu = i;
break;
}
}
}
if (hRepeat & KEY_R) {
if (currentMenu < 4) {
if (currentMenu + 1 == 1) fetch = true; // Fetch download list, if 1.
currentMenu++;
}
}
if (hRepeat & KEY_L) {
if (currentMenu > 0) {
if (currentMenu - 1 == 1) fetch = true; // Fetch download list, if 1.
currentMenu--;
}
}
}
+161
View File
@@ -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 "keyboard.hpp"
#include "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> buttons = {
{ 75, 50, 100, 16 },
{ 75, 70, 100, 16 },
{ 75, 90, 100, 16 },
{ 205, 50, 100, 16 },
{ 205, 70, 100, 16 },
{ 75, 160, 100, 16 },
{ 75, 180, 100, 16 }
};
static void DrawCheck(int pos, bool v) {
GFX::DrawSprite((v ? sprites_sort_checked_idx : sprites_sort_unchecked_idx), buttons[pos].x + 5, buttons[pos].y);
}
/*
Return SortType as an uint8_t.
const SortType &st: Const Reference to the SortType variable.
*/
static const uint8_t GetType(const SortType &st) {
switch(st) {
case SortType::TITLE:
return 0;
case SortType::AUTHOR:
return 1;
case SortType::LAST_UPDATED:
return 2;
}
return 1;
}
/*
Draw the Sort Menu.
const bool &asc: Const Reference to the Ascending variable.
const SortType &st: Const Reference to the SortType variable.
*/
void StoreUtils::DrawSorting(const bool &asc, const SortType &st) {
/* Sort By. */
Gui::DrawString(buttons[0].x + 5, buttons[0].y - 20, 0.6f, TEXT_COLOR, Lang::get("SORT_BY"));
for (int i = 0; i < 3; i++) {
DrawCheck(i, i == GetType(st));
}
Gui::DrawString(buttons[0].x + 25, buttons[0].y + 2, 0.4f, TEXT_COLOR, Lang::get("TITLE"));
Gui::DrawString(buttons[1].x + 25, buttons[1].y + 2, 0.4f, TEXT_COLOR, Lang::get("AUTHOR"));
Gui::DrawString(buttons[2].x + 25, buttons[2].y + 2, 0.4f, TEXT_COLOR, Lang::get("LAST_UPDATED"));
/* Direction. */
Gui::DrawString(buttons[3].x + 5, buttons[3].y - 20, 0.6f, TEXT_COLOR, Lang::get("DIRECTION"));
DrawCheck(3, asc);
DrawCheck(4, !asc);
Gui::DrawString(buttons[3].x + 25, buttons[3].y + 2, 0.4f, TEXT_COLOR, Lang::get("ASCENDING"));
Gui::DrawString(buttons[4].x + 25, buttons[4].y + 2, 0.4f, TEXT_COLOR, Lang::get("DESCENDING"));
/* Top Style. */
Gui::DrawString(buttons[5].x + 5, buttons[5].y - 20, 0.6f, TEXT_COLOR, Lang::get("TOP_STYLE"));
DrawCheck(5, config->list());
DrawCheck(6, !config->list());
Gui::DrawString(buttons[5].x + 25, buttons[5].y + 2, 0.4f, TEXT_COLOR, Lang::get("LIST"));
Gui::DrawString(buttons[6].x + 25, buttons[6].y + 2, 0.4f, TEXT_COLOR, Lang::get("GRID"));
}
/*
Sort Handle.
Here you can..
- Sort your Entries to..
- Title (Ascending / Descending).
- Author (Ascending / Descending).
- Last Updated Date (Ascending / Descending).
- Change the Top Style.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
bool &asc: Reference to the Ascending variable.
SortType &st: Reference to the SortType.
*/
void StoreUtils::SortHandle(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, bool &asc, SortType &st) {
if (store && store->GetValid() && entries.size() > 0) { // Ensure, this is valid and more than 0 entries exist.
if (hDown & KEY_TOUCH) {
/* SortType Part. */
if (touching(touch, buttons[0])) {
st = SortType::TITLE;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[1])) {
st = SortType::AUTHOR;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[2])) {
st = SortType::LAST_UPDATED;
StoreUtils::SortEntries(asc, st, entries);
/* Ascending | Descending Part. */
} else if (touching(touch, buttons[3])) {
asc = true;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[4])) {
asc = false;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[5])) {
if (config->list()) return;
config->list(true);
store->SetEntry(0);
store->SetScreenIndx(0);
store->SetBox(0);
} else if (touching(touch, buttons[6])) {
if (!config->list()) return;
config->list(false);
store->SetEntry(0);
store->SetScreenIndx(0);
store->SetBox(0);
}
}
}
}
+427
View File
@@ -0,0 +1,427 @@
/*
* 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 "common.hpp"
#include "download.hpp"
#include "gui.hpp"
#include "scriptUtils.hpp"
#include "store.hpp"
#include <unistd.h>
extern C2D_SpriteSheet sprites;
extern bool checkWifiStatus();
static bool firstStart = true;
/*
Initialize a store.
const std::string &file: The UniStore file.
*/
Store::Store(const std::string &file) { this->update(file); };
/*
Update an UniStore,, including SpriteSheet, if revision increased.
const std::string &file: Const Reference to the fileName.
*/
void Store::update(const std::string &file) {
bool doSheet = false;
this->LoadFromFile(file);
int rev = -1;
/* Only do this, if valid. */
if (this->valid) {
if (this->storeJson["storeInfo"].contains("revision") && this->storeJson["storeInfo"]["revision"].is_number()) {
rev = this->storeJson["storeInfo"]["revision"];
}
/* First start exceptions. */
if (firstStart) {
firstStart = false;
if (!config->autoupdate()) {
this->loadSheets();
return;
}
}
if (this->storeJson.contains("storeInfo")) {
/* Checking... */
if (checkWifiStatus()) { // Only do, if WiFi available.
if (this->storeJson["storeInfo"].contains("url") && this->storeJson["storeInfo"]["url"].is_string()) {
if (this->storeJson["storeInfo"].contains("file") && this->storeJson["storeInfo"]["file"].is_string()) {
const std::string fl = this->storeJson["storeInfo"]["file"];
if (!(fl.find("/") != std::string::npos)) {
const std::string URL = this->storeJson["storeInfo"]["url"];
if (URL != "") {
std::string tmp = "";
doSheet = DownloadUniStore(URL, rev, tmp);
}
} else {
Msg::waitMsg(Lang::get("FILE_SLASH"));
}
}
}
if (doSheet) {
/* SpriteSheet Array. */
if (this->storeJson["storeInfo"].contains("sheetURL") && this->storeJson["storeInfo"]["sheetURL"].is_array()) {
if (this->storeJson["storeInfo"].contains("sheet") && this->storeJson["storeInfo"]["sheet"].is_array()) {
const std::vector<std::string> locs = this->storeJson["storeInfo"]["sheetURL"].get<std::vector<std::string>>();
const std::vector<std::string> sht = this->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("UPDATING_SPRITE_SHEET2").c_str(), i + 1, sht.size());
Msg::DisplayMsg(msg);
DownloadSpriteSheet(locs[i], sht[i]);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
i++;
}
}
}
}
/* Single SpriteSheet (No array). */
} else if (this->storeJson["storeInfo"].contains("sheetURL") && this->storeJson["storeInfo"]["sheetURL"].is_string()) {
if (this->storeJson["storeInfo"].contains("sheet") && this->storeJson["storeInfo"]["sheet"].is_string()) {
const std::string fl = this->storeJson["storeInfo"]["sheetURL"];
const std::string fl2 = this->storeJson["storeInfo"]["sheet"];
if (!(fl2.find("/") != std::string::npos)) {
Msg::DisplayMsg(Lang::get("UPDATING_SPRITE_SHEET"));
DownloadSpriteSheet(fl, fl2);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
}
}
}
}
}
this->LoadFromFile(file);
this->loadSheets();
}
}
}
/*
Unload all SpriteSheets on Destructor.
*/
Store::~Store() { this->unloadSheets(); };
/*
Unload all SpriteSheets.
*/
void Store::unloadSheets() {
if (this->valid) {
if (this->sheets.size() > 0) {
for (int i = 0; i < (int)this->sheets.size(); i++) {
if (this->sheets[i]) C2D_SpriteSheetFree(this->sheets[i]);
}
}
this->sheets.clear();
}
}
/*
Load all SpriteSheets.
*/
void Store::loadSheets() {
if (this->valid) {
if (this->storeJson["storeInfo"].contains("sheet")) {
this->unloadSheets();
std::vector<std::string> sheetLocs = { "" };
if (this->storeJson["storeInfo"]["sheet"].is_array()) {
sheetLocs = this->storeJson["storeInfo"]["sheet"].get<std::vector<std::string>>();
} else if (this->storeJson["storeInfo"]["sheet"].is_string()) {
sheetLocs[0] = this->storeJson["storeInfo"]["sheet"];
} else {
return;
}
for (int i = 0; i < (int)sheetLocs.size(); i++) {
this->sheets.push_back({ });
if (sheetLocs[i] != "") {
if (!(sheetLocs[i].find("/") != std::string::npos)) {
if (access((std::string(_STORE_PATH) + sheetLocs[i]).c_str(), F_OK) == 0) {
char msg[150];
snprintf(msg, sizeof(msg), Lang::get("LOADING_SPRITESHEET").c_str(), i + 1, sheetLocs.size());
Msg::DisplayMsg(msg);
this->sheets[i] = C2D_SpriteSheetLoad((std::string(_STORE_PATH) + sheetLocs[i]).c_str());
}
}
}
}
}
}
}
/*
Load a UniStore from a file.
const std::string &file: The file of the UniStore.
*/
void Store::LoadFromFile(const std::string &file) {
FILE *in = fopen(file.c_str(), "rt");
this->storeJson = nlohmann::json::parse(in, nullptr, false);
fclose(in);
/* Check, if valid. */
if (this->storeJson.contains("storeInfo") && this->storeJson.contains("storeContent")) {
if (this->storeJson["storeInfo"].contains("version") && this->storeJson["storeInfo"]["version"].is_number()) {
if (this->storeJson["storeInfo"]["version"] < 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_OLD"));
else if (this->storeJson["storeInfo"]["version"] > 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_NEW"));
this->valid = this->storeJson["storeInfo"]["version"] == 3;
}
} else {
Msg::waitMsg(Lang::get("UNISTORE_INVALID_ERROR"));
}
}
/*
Return the Title of the UniStore.
*/
std::string Store::GetUniStoreTitle() const {
if (this->valid) {
if (this->storeJson["storeInfo"].contains("title")) return this->storeJson["storeInfo"]["title"];
}
return "";
}
/*
Return the Title of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetTitleEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("title") && this->storeJson["storeContent"][index]["info"]["title"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["title"];
}
return "";
}
/*
Return the Author name of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetAuthorEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("author") && this->storeJson["storeContent"][index]["info"]["author"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["author"];
}
return "";
}
/*
Return the Description of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetDescriptionEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("description") && this->storeJson["storeContent"][index]["info"]["description"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["description"];
}
return "";
}
/*
Return the Category of an index.
const int &index: Const Reference to the index.
*/
std::vector<std::string> Store::GetCategoryIndex(const int &index) const {
if (!this->valid) return { "" };
if (index > (int)this->storeJson["storeContent"].size() - 1) return { "" }; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("category")) {
if (this->storeJson["storeContent"][index]["info"]["category"].is_array()) {
return this->storeJson["storeContent"][index]["info"]["category"].get<std::vector<std::string>>();
} else if (this->storeJson["storeContent"][index]["info"]["category"].is_string()) {
std::vector<std::string> temp;
temp.push_back( this->storeJson["storeContent"][index]["info"]["category"] );
return temp;
}
}
return { "" };
}
/*
Return the Version of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetVersionEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("version") && this->storeJson["storeContent"][index]["info"]["version"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["version"];
}
return "";
}
/*
Return the Console of an index.
const int &index: Const Reference to the index.
*/
std::vector<std::string> Store::GetConsoleEntry(const int &index) const {
if (!this->valid) return { "" };
if (index > (int)this->storeJson["storeContent"].size() - 1) return { "" }; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("console")) {
if (this->storeJson["storeContent"][index]["info"]["console"].is_array()) {
return this->storeJson["storeContent"][index]["info"]["console"].get<std::vector<std::string>>();
} else if (this->storeJson["storeContent"][index]["info"]["console"].is_string()) {
std::vector<std::string> temp;
temp.push_back( this->storeJson["storeContent"][index]["info"]["console"] );
return temp;
}
}
return { "" };
}
/*
Return the Last updated date of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetLastUpdatedEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("last_updated") && this->storeJson["storeContent"][index]["info"]["last_updated"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["last_updated"];
}
return "";
}
/*
Return the License of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetLicenseEntry(const int &index) const {
if (!this->valid) return Lang::get("NO_LICENSE");
if (index > (int)this->storeJson["storeContent"].size() - 1) return Lang::get("NO_LICENSE"); // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("license") && this->storeJson["storeContent"][index]["info"]["license"].is_string()) {
if (this->storeJson["storeContent"][index]["info"]["license"] == "") return Lang::get("NO_LICENSE");
return this->storeJson["storeContent"][index]["info"]["license"];
}
return Lang::get("NO_LICENSE");
}
/*
Return a C2D_Image of an index.
const int &index: Const Reference to the index.
*/
C2D_Image Store::GetIconEntry(const int &index) const {
if (!this->valid) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
int iconIndex = -1, sheetIndex = 0;
if (index > (int)this->storeJson["storeContent"].size() - 1) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (this->storeJson["storeContent"][index]["info"].contains("icon_index") && this->storeJson["storeContent"][index]["info"]["icon_index"].is_number()) {
iconIndex = this->storeJson["storeContent"][index]["info"]["icon_index"];
}
if (this->storeJson["storeContent"][index]["info"].contains("sheet_index") && this->storeJson["storeContent"][index]["info"]["sheet_index"].is_number()) {
sheetIndex = this->storeJson["storeContent"][index]["info"]["sheet_index"];
}
if (iconIndex == -1) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (sheetIndex > (int)this->sheets.size()) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (!this->sheets[sheetIndex]) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (iconIndex > (int)C2D_SpriteSheetCount(this->sheets[sheetIndex])-1) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
C2D_Image temp = C2D_SpriteSheetGetImage(this->sheets[sheetIndex], iconIndex);
if (temp.subtex->width < 49 && temp.subtex->height < 49) return temp; // up to 48x48 is valid.
return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
}
/*
Return the download list of an entry.
const int &index: Const Reference to the index.
*/
std::vector<std::string> Store::GetDownloadList(const int &index) const {
if (!this->valid) return { "" };
std::vector<std::string> temp;
if (index > (int)this->storeJson["storeContent"].size() - 1) return temp;
for(auto it = this->storeJson.at("storeContent").at(index).begin(); it != this->storeJson.at("storeContent").at(index).end(); it++) {
if (it.key() != "info") temp.push_back(it.key());
}
return temp;
}
+58
View File
@@ -0,0 +1,58 @@
/*
* 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 "storeEntry.hpp"
/*
Fetch informations on constructor.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::unique_ptr<Meta> &meta: Const Reference to the Meta class.
const int &index: Const Reference Index of the entry.
*/
StoreEntry::StoreEntry(const std::unique_ptr<Store> &store, const std::unique_ptr<Meta> &meta, const int &index) {
this->Title = store->GetTitleEntry(index);
this->Author = store->GetAuthorEntry(index);
this->Description = store->GetDescriptionEntry(index);
this->Category = StringUtils::FetchStringsFromVector(store->GetCategoryIndex(index));
this->Version = store->GetVersionEntry(index);
this->Console = StringUtils::FetchStringsFromVector(store->GetConsoleEntry(index));
this->LastUpdated = store->GetLastUpdatedEntry(index);
this->License = store->GetLicenseEntry(index);
this->MarkString = StringUtils::GetMarkString(meta->GetMarks(store->GetUniStoreTitle(), this->Title));
this->Icon = store->GetIconEntry(index);
this->SheetIndex = 0;
this->EntryIndex = index;
this->FullCategory = store->GetCategoryIndex(index);
this->FullConsole = store->GetConsoleEntry(index);
this->UpdateAvailable = meta->UpdateAvailable(store->GetUniStoreTitle(), this->Title, store->GetLastUpdatedEntry(index));
this->Marks = meta->GetMarks(store->GetUniStoreTitle(), this->Title);
}
+178
View File
@@ -0,0 +1,178 @@
/*
* 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 "storeUtils.hpp"
/*
Compare Title.
const std::unique_ptr<StoreEntry> &a: Const Reference to Entry A.
const std::unique_ptr<StoreEntry> &b: Const Reference to Entry B.
*/
bool StoreUtils::compareTitleDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(a->GetTitle()).c_str(), StringUtils::lower_case(b->GetTitle()).c_str()) > 0;
return true;
}
bool StoreUtils::compareTitleAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(b->GetTitle()).c_str(), StringUtils::lower_case(a->GetTitle()).c_str()) > 0;
return true;
}
/*
Compare Author.
const std::unique_ptr<StoreEntry> &a: Const Reference to Entry A.
const std::unique_ptr<StoreEntry> &b: Const Reference to Entry B.
*/
bool StoreUtils::compareAuthorDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(a->GetAuthor()).c_str(), StringUtils::lower_case(b->GetAuthor()).c_str()) > 0;
return true;
}
bool StoreUtils::compareAuthorAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(b->GetAuthor()).c_str(), StringUtils::lower_case(a->GetAuthor()).c_str()) > 0;
return true;
}
/*
Compare Last Updated.
const std::unique_ptr<StoreEntry> &a: Const Reference to Entry A.
const std::unique_ptr<StoreEntry> &b: Const Reference to Entry B.
*/
bool StoreUtils::compareUpdateDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(a->GetLastUpdated()).c_str(), StringUtils::lower_case(b->GetLastUpdated()).c_str()) > 0;
return true;
}
bool StoreUtils::compareUpdateAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(b->GetLastUpdated()).c_str(), StringUtils::lower_case(a->GetLastUpdated()).c_str()) > 0;
return true;
}
/*
Sort the entries.
const bool &Ascending: Const Reference to Ascending.
const SortType &sorttype: Const Reference to the sort type.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the Entries, which should be sorted.
*/
void StoreUtils::SortEntries(const bool &Ascending, const SortType &sorttype, std::vector<std::unique_ptr<StoreEntry>> &entries) {
switch(sorttype) {
case SortType::TITLE:
Ascending ? std::sort(entries.begin(), entries.end(), StoreUtils::compareTitleAscending) : std::sort(entries.begin(), entries.end(), StoreUtils::compareTitleDescending);
break;
case SortType::AUTHOR:
Ascending ? std::sort(entries.begin(), entries.end(), StoreUtils::compareAuthorAscending) : std::sort(entries.begin(), entries.end(), StoreUtils::compareAuthorDescending);
break;
case SortType::LAST_UPDATED:
Ascending ? std::sort(entries.begin(), entries.end(), StoreUtils::compareUpdateAscending) : std::sort(entries.begin(), entries.end(), StoreUtils::compareUpdateDescending);
break;
}
}
/*
Find a query from a vector.
const std::vector<std::string> &items: Const Reference to the vector strings / items.
const std::string &query: Const Reference to the query.
*/
static bool findInVector(const std::vector<std::string> &items, const std::string &query) {
for(const std::string &item : items) {
if (StringUtils::lower_case(item).find(query) != std::string::npos) return true;
}
return false;
}
/*
Search for stuff of the store.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the entries.
const std::string &query: Const Reference to the query.
bool title: if titles should be included.
bool author: if authors should be included.
bool category: if categories should be included.
bool console: if consoles should be included.
int selectedMarks: The selected mark flags.
bool updateAvl: if available updates should be an included flag
*/
void StoreUtils::search(std::vector<std::unique_ptr<StoreEntry>> &entries, const std::string &query, bool title, bool author, bool category, bool console, int selectedMarks, bool updateAvl) {
for (auto it = entries.begin(); it != entries.end(); ++it) {
if (!(((title && StringUtils::lower_case((*it)->GetTitle()).find(StringUtils::lower_case(query)) != std::string::npos)
|| (author && StringUtils::lower_case((*it)->GetAuthor()).find(StringUtils::lower_case(query)) != std::string::npos)
|| (category && findInVector((*it)->GetCategoryFull(), StringUtils::lower_case(query)))
|| (console && findInVector((*it)->GetConsoleFull(), StringUtils::lower_case(query)))
|| (!title && !author && !category && !console))
&& ((selectedMarks == 0 && !updateAvl) || (*it)->GetMarks() & selectedMarks || (updateAvl && (*it)->GetUpdateAvl())))) {
entries.erase(it);
--it;
}
}
}
/*
Filter for available updates.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the entries.
*/
void StoreUtils::FilterUpdateAvailable(std::vector<std::unique_ptr<StoreEntry>> &entries) {
for (auto it = entries.begin(); it != entries.end(); ++it) {
if (!((*it)->GetUpdateAvl())) {
entries.erase(it);
--it;
}
}
}
/*
Reset everything of the store and clear + fetch the Entries again.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::unique_ptr<Meta> &meta: Const Reference to the Meta class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the entries.
*/
void StoreUtils::ResetAll(const std::unique_ptr<Store> &store, const std::unique_ptr<Meta> &meta, std::vector<std::unique_ptr<StoreEntry>> &entries) {
if (store) {
entries.clear();
if (store->GetValid()) {
for (int i = 0; i < store->GetStoreSize(); i++) {
entries.push_back( std::make_unique<StoreEntry>(store, meta, i) );
}
store->SetBox(0);
store->SetEntry(0);
store->SetScreenIndx(0);
}
}
}