From e97d4a73b3535fdfd5e0cad0afcf9958471ea142 Mon Sep 17 00:00:00 2001 From: Epicpkmn11 Date: Wed, 6 Nov 2019 14:14:20 -0600 Subject: [PATCH] Get current file revisions --- source/screens/scriptBrowse.cpp | 108 +++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 37 deletions(-) diff --git a/source/screens/scriptBrowse.cpp b/source/screens/scriptBrowse.cpp index 2a50476..ae97446 100644 --- a/source/screens/scriptBrowse.cpp +++ b/source/screens/scriptBrowse.cpp @@ -32,65 +32,99 @@ #include "utils/fileBrowse.h" #include "utils/json.hpp" +#include + #define ENTRIES_PER_SCREEN 3 -nlohmann::json jsonFileBrowse; +nlohmann::json infoJson; -std::string metaFile = "sdmc:/3ds/Universal-Updater/ScriptInfo.json"; +#define metaFile "sdmc:/3ds/Universal-Updater/ScriptInfo.json" extern std::string get(nlohmann::json json, const std::string &key, const std::string &key2); -nlohmann::json openMetaFile() { - FILE* file = fopen(metaFile.c_str(), "rt"); - nlohmann::json jsonFile; - if(file) jsonFile = nlohmann::json::parse(file, nullptr, false); - fclose(file); - return jsonFile; -} - -nlohmann::json parseInfo() { - FILE* file = fopen(metaFile.c_str(), "rt"); - if(!file) { - printf("File not found\n"); - fclose(file); - return {"", ""}; - } - nlohmann::json json = nlohmann::json::parse(file, nullptr, false); - fclose(file); - +void fixInfo(nlohmann::json &json) { for(uint i=0;i dirContents; + getDirectoryContents(dirContents); + for(uint i=0;i()), 400); + Gui::DrawStringCentered(0, 80, 0.7f, Config::TxtColor, Lang::get("TITLE") + std::string(infoJson[screenPos+selection]["title"]), 400); + Gui::DrawStringCentered(0, 100, 0.7f, Config::TxtColor, Lang::get("AUTHOR") + std::string(infoJson[screenPos+selection]["author"]), 400); + Gui::DrawStringCentered(0, 120, 0.7f, Config::TxtColor, Lang::get("INSTALLED_REV") + std::to_string(int64_t(infoJson[screenPos+selection]["curRevision"])), 400); + Gui::DrawStringCentered(0, 140, 0.7f, Config::TxtColor, Lang::get("CURRENT_REV")+ std::to_string(int64_t(infoJson[screenPos+selection]["revision"])), 400); Gui::DrawBottom(); - for(int i=0;i 0) { selection--; } else { - selection = (int)jsonFileBrowse.size()-1; + selection = (int)infoJson.size()-1; } if (fastMode == true) { keyRepeatDelay = 3; @@ -130,10 +164,10 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_A) { - if (jsonFileBrowse.size() != 0) { - std::string fileName = Lang::get("DOWNLOADING") + std::string(jsonFileBrowse[selection]["title"]); + if (infoJson.size() != 0) { + std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[selection]["title"]); - std::string titleFix = jsonFileBrowse[selection]["title"]; + std::string titleFix = infoJson[selection]["title"]; for (int i = 0; i < (int)titleFix.size(); i++) { if (titleFix[i] == '/') { titleFix[i] = '-'; @@ -141,7 +175,7 @@ void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } DisplayMsg(fileName); - downloadToFile(jsonFileBrowse[selection]["url"], Config::ScriptPath + titleFix + ".json"); + downloadToFile(infoJson[selection]["url"], Config::ScriptPath + titleFix + ".json"); } }