mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
WIP: Display if update is available on UniStore v2!
Use `updates.json` for it in `sd:/3ds/Universal-Updater/`.
This commit is contained in:
@@ -78,7 +78,7 @@ void UniStore::autobootLogic() {
|
||||
if (storeInfo[0].version == 0 || storeInfo[0].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[0].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
|
||||
}
|
||||
@@ -596,7 +596,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (storeInfo[Selection].version == 0 || storeInfo[Selection].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[Selection].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
|
||||
}
|
||||
@@ -632,7 +632,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (storeInfo[screenPos + i].version == 0 || storeInfo[screenPos + i].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[screenPos + i].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
|
||||
}
|
||||
@@ -653,7 +653,7 @@ void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (storeInfo[screenPosList + i].version == 0 || storeInfo[screenPosList + i].version == 1) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
|
||||
} else if (storeInfo[screenPosList + i].version == 2) {
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL), config->screenFade(), true);
|
||||
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
|
||||
} else {
|
||||
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||
#define DOWNLOAD_ENTRIES 5
|
||||
extern bool didAutoboot;
|
||||
|
||||
UniStoreV2::UniStoreV2(nlohmann::json &JSON, const std::string sheetPath) {
|
||||
UniStoreV2::UniStoreV2(nlohmann::json &JSON, const std::string sheetPath, const std::string fileName) {
|
||||
this->storeJson = JSON;
|
||||
this->sortedStore = std::make_unique<Store>(this->storeJson);
|
||||
this->sortedStore = std::make_unique<Store>(this->storeJson, fileName);
|
||||
|
||||
if (access(sheetPath.c_str(), F_OK) != 0) {
|
||||
this->iconAmount = 0;
|
||||
@@ -141,7 +141,7 @@ void UniStoreV2::DrawGrid(void) const {
|
||||
int offset2 = (48 - temp.subtex->height) / 2;
|
||||
Gui::DrawSprite(this->sheet, this->sortedStore->returnIconIndex(i + (this->storePage * STORE_ENTRIES)), this->StoreBoxesGrid[i].x+1 + offset, this->StoreBoxesGrid[i].y+1 + offset2);
|
||||
} else {
|
||||
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1);
|
||||
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesGrid[i].x+1, this->StoreBoxesGrid[i].y+1);
|
||||
}
|
||||
temp = {nullptr, nullptr};
|
||||
} else {
|
||||
@@ -153,6 +153,10 @@ void UniStoreV2::DrawGrid(void) const {
|
||||
} else {
|
||||
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesGrid[i].x+1, this->StoreBoxesGrid[i].y+1);
|
||||
}
|
||||
|
||||
if (this->sortedStore->isUpdateAvailable(i + (this->storePage * STORE_ENTRIES))) {
|
||||
GFX::DrawSprite(sprites_updateStore_idx, this->StoreBoxesGrid[i].x+35, this->StoreBoxesGrid[i].y+35);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +190,11 @@ void UniStoreV2::DrawList(void) const {
|
||||
GFX::DrawSprite(sprites_noIcon_idx, this->StoreBoxesList[i].x+1, this->StoreBoxesList[i].y+1);
|
||||
}
|
||||
|
||||
if (this->sortedStore->isUpdateAvailable(i + (this->storePageList * STORE_ENTRIES_LIST))) {
|
||||
GFX::DrawSprite(sprites_updateStore_idx, this->StoreBoxesList[i].x+340, this->StoreBoxesList[i].y+30);
|
||||
}
|
||||
|
||||
// Display Author & App name.
|
||||
|
||||
Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+12, 0.45f, this->returnTextColor(), this->sortedStore->returnTitle(i + (this->storePageList * STORE_ENTRIES_LIST)), 300);
|
||||
Gui::DrawString(this->StoreBoxesList[i].x+55, this->StoreBoxesList[i].y+28, 0.45f, this->returnTextColor(), this->sortedStore->returnAuthor(i + (this->storePageList * STORE_ENTRIES_LIST)), 300);
|
||||
}
|
||||
@@ -274,7 +281,7 @@ void UniStoreV2::DropDownMenu(void) const {
|
||||
}
|
||||
}
|
||||
|
||||
void UniStoreV2::displaySelectedEntry(int selection) const {
|
||||
void UniStoreV2::displaySelectedEntry(int selection, int storeIndex) const {
|
||||
this->DrawBaseTop();
|
||||
|
||||
Gui::DrawStringCentered(0, 218, 0.7f, this->returnTextColor(), std::to_string(this->downloadPage + 1) + " | " + std::to_string(1 + (this->objects.size() / DOWNLOAD_ENTRIES)));
|
||||
@@ -329,6 +336,8 @@ void UniStoreV2::displaySelectedEntry(int selection) const {
|
||||
Gui::DrawStringCentered(0, 140, 0.5f, this->returnTextColor(), Lang::get("DESC") + "?", 400);
|
||||
}
|
||||
|
||||
Gui::DrawStringCentered(0, 170, 0.5f, this->returnTextColor(), this->sortedStore->isUpdateAvailable(storeIndex) ? Lang::get("UPDATE_AVAILABLE") : Lang::get("UPDATE_NOT_AVAILABLE"), 400);
|
||||
|
||||
this->DrawBaseBottom();
|
||||
|
||||
if (this->objects.size() > 0) {
|
||||
@@ -363,6 +372,9 @@ void UniStoreV2::Draw(void) const {
|
||||
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
|
||||
this->DrawBaseBottom();
|
||||
char entryAmount [150];
|
||||
snprintf(entryAmount, sizeof(entryAmount), Lang::get("ENTRY_AMOUNT").c_str(), this->sortedStore->getSize());
|
||||
Gui::DrawStringCentered(0, 0, 0.6f, this->returnTextColor(), entryAmount, 300);
|
||||
this->DrawSortingMenu();
|
||||
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
|
||||
@@ -381,9 +393,12 @@ void UniStoreV2::Draw(void) const {
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
|
||||
this->DrawBaseBottom();
|
||||
this->DrawSortingMenu();
|
||||
char entryAmount [150];
|
||||
snprintf(entryAmount, sizeof(entryAmount), Lang::get("ENTRY_AMOUNT").c_str(), this->sortedStore->getSize());
|
||||
Gui::DrawStringCentered(0, 0, 0.6f, this->returnTextColor(), entryAmount, 300);
|
||||
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
|
||||
} else if (this->mode == 2) {
|
||||
this->displaySelectedEntry(this->selection);
|
||||
this->displaySelectedEntry(this->selection, this->selectedObject);
|
||||
} else if (this->mode == 3) {
|
||||
this->DrawSearchMenu();
|
||||
} else if (this->mode == 4) {
|
||||
@@ -561,6 +576,7 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
if (this->sortedStore->returnJSONIndex(this->selectedBox + (this->storePage * STORE_ENTRIES)) < (int)this->storeJson.at("storeContent").size()) {
|
||||
this->selectedObject = this->selectedBox + (this->storePage * STORE_ENTRIES);
|
||||
this->selection = this->sortedStore->returnJSONIndex(this->selectedBox + (this->storePage * STORE_ENTRIES));
|
||||
this->parseObjects(this->selection);
|
||||
this->canDisplay = true;
|
||||
@@ -619,6 +635,7 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
|
||||
if (hDown & KEY_A) {
|
||||
if (this->sortedStore->returnJSONIndex(this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST)) < (int)this->storeJson.at("storeContent").size()) {
|
||||
this->selectedObject = this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST);
|
||||
this->selection = this->sortedStore->returnJSONIndex(this->selectedBoxList + (this->storePageList * STORE_ENTRIES_LIST));
|
||||
this->parseObjects(this->selection);
|
||||
this->canDisplay = true;
|
||||
@@ -646,7 +663,10 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (this->objects.size() > 0) {
|
||||
for (int i = 0, i2 = 0 + (this->downloadPage * DOWNLOAD_ENTRIES); i2 < DOWNLOAD_ENTRIES + (this->downloadPage * DOWNLOAD_ENTRIES) && i2 < (int)this->objects.size(); i2++, i++) {
|
||||
if (touching(touch, downloadBoxes[i])) {
|
||||
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n" + this->objects[i + (this->downloadPage * DOWNLOAD_ENTRIES)])) runFunctions(this->objects[i + (this->downloadPage * DOWNLOAD_ENTRIES)]);
|
||||
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n" + this->objects[i + (this->downloadPage * DOWNLOAD_ENTRIES)])) {
|
||||
runFunctions(this->objects[i + (this->downloadPage * DOWNLOAD_ENTRIES)]);
|
||||
this->sortedStore->writeToFile(this->selectedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -655,7 +675,10 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||
if (hDown & KEY_A) {
|
||||
if (this->objects.size() > 0) {
|
||||
if ((int)this->objects.size() >= this->subSelection) {
|
||||
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n" + this->objects[this->subSelection])) runFunctions(this->objects[this->subSelection]);
|
||||
if (Msg::promptMsg(Lang::get("EXECUTE_SCRIPT") + "\n" + this->objects[this->subSelection])) {
|
||||
runFunctions(this->objects[this->subSelection]);
|
||||
this->sortedStore->writeToFile(this->selectedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+71
-2
@@ -25,22 +25,88 @@
|
||||
*/
|
||||
|
||||
#include "store.hpp"
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
Store::Store(nlohmann::json &JS) {
|
||||
Store::Store(nlohmann::json &JS, std::string JSONName) {
|
||||
this->storeJson = JS;
|
||||
this->updateFile = JSONName;
|
||||
|
||||
if (access("sdmc:/3ds/Universal-Updater/updates.json", F_OK) != 0) {
|
||||
// We'd create the file here.
|
||||
FILE *file = fopen("sdmc:/3ds/Universal-Updater/updates.json", "w");
|
||||
this->updateJSON = nlohmann::json::parse("{}"); // So we have a valid JSON at the end.
|
||||
fwrite(this->updateJSON.dump(1, '\t').c_str(), 1, this->updateJSON.dump(1, '\t').size(), file);
|
||||
fclose(file);
|
||||
|
||||
FILE *file2 = fopen("sdmc:/3ds/Universal-Updater/updates.json", "r");
|
||||
this->updateJSON = nlohmann::json::parse(file2, nullptr, false);
|
||||
fclose(file2);
|
||||
} else {
|
||||
FILE *file = fopen("sdmc:/3ds/Universal-Updater/updates.json", "r");
|
||||
this->updateJSON = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < (int)this->storeJson.at("storeContent").size(); i++) {
|
||||
this->unsortedStore.push_back(this->getData(i));
|
||||
}
|
||||
|
||||
this->sortedStore = this->unsortedStore; // Put that to sorted store as well.
|
||||
|
||||
// If Categories available, push them to our vector.
|
||||
if (this->storeJson.at("storeInfo").contains("categories")) {
|
||||
this->availableCategories = this->storeJson["storeInfo"]["categories"].get<std::vector<std::string>>();
|
||||
}
|
||||
}
|
||||
|
||||
bool Store::updateAvailable(int index) {
|
||||
if (index > (int)this->storeJson.at("storeContent").size()) return false; // out of scope.
|
||||
if (this->storeJson.at("storeContent").at(index).at("info").contains("last_updated")) {
|
||||
const std::string updateEntry = this->storeJson.at("storeContent").at(index).at("info").at("last_updated");
|
||||
const std::string entry = this->storeJson.at("storeContent").at(index).at("info").at("title");
|
||||
|
||||
if (this->updateJSON.contains(this->updateFile)) {
|
||||
if (this->updateJSON.at(this->updateFile).contains(entry)) {
|
||||
const std::string updateEntry2 = (std::string)this->updateJSON.at(this->updateFile).at(entry);
|
||||
return strcasecmp(updateEntry.c_str(), updateEntry2.c_str()) > 0;
|
||||
} else {
|
||||
return true; // Since we do not have this entry there yet.
|
||||
}
|
||||
} else { // Our update json don't have that yet.. so display available.
|
||||
return true;
|
||||
}
|
||||
} else { // Since the Store doesn't have that feature.
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Here we write that to our file.
|
||||
void Store::writeToFile(int index) {
|
||||
std::string timeString;
|
||||
|
||||
time_t rawtime;
|
||||
struct tm * ptm;
|
||||
time (&rawtime);
|
||||
ptm = gmtime (&rawtime);
|
||||
|
||||
timeString = std::to_string(ptm->tm_year + 1900) + "-" + std::to_string(ptm->tm_mon + 1) + "-" + std::to_string(ptm->tm_mday) + " at " + std::to_string(ptm->tm_hour) + ":"
|
||||
+ std::to_string(ptm->tm_min) + " (UTC)";
|
||||
|
||||
FILE *file = fopen("sdmc:/3ds/Universal-Updater/updates.json", "w");
|
||||
this->updateJSON[this->updateFile][this->sortedStore[index].title] = timeString;
|
||||
fwrite(this->updateJSON.dump(1, '\t').c_str(), 1, this->updateJSON.dump(1, '\t').size(), file);
|
||||
fclose(file);
|
||||
|
||||
this->sortedStore[index].updateAvailable = false;
|
||||
}
|
||||
|
||||
// Here we get the data of the UniStore!
|
||||
UniStoreV2Struct Store::getData(const int index) {
|
||||
UniStoreV2Struct temp = {"", "", "", "", "" ,"", -1, 0};
|
||||
UniStoreV2Struct temp = {"", "", "", "", "" ,"", -1, 0, false};
|
||||
|
||||
if (index > (int)this->storeJson.at("storeContent").size()) return temp; // Empty.
|
||||
|
||||
@@ -79,6 +145,9 @@ UniStoreV2Struct Store::getData(const int index) {
|
||||
temp.icon_index = this->storeJson.at("storeContent").at(index).at("info").at("icon_index");
|
||||
}
|
||||
|
||||
// Update available(?).
|
||||
temp.updateAvailable = this->updateAvailable(index);
|
||||
|
||||
// JSON index.
|
||||
temp.JSONIndex = index;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user