From d8531aa1fd0a8b8a6291bc56e55401805ed025d3 Mon Sep 17 00:00:00 2001 From: VoltZ <47382115+SuperSaiyajinVoltZ@users.noreply.github.com> Date: Wed, 6 Nov 2019 15:14:11 +0100 Subject: [PATCH] Check for an Int for real on the Script version. --- include/utils/common.hpp | 3 ++- source/screens/scriptlist.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/utils/common.hpp b/include/utils/common.hpp index b582b0c..200490b 100644 --- a/include/utils/common.hpp +++ b/include/utils/common.hpp @@ -59,4 +59,5 @@ using json = nlohmann::json; extern char * arg0; #define WORKING_DIR "/" -#define SCRIPTS_PATH "sdmc:/3ds/Universal-Updater/scripts/" // The Scripts will be here. \ No newline at end of file +#define SCRIPTS_PATH "sdmc:/3ds/Universal-Updater/scripts/" // The Scripts will be here. +#define SCRIPT_VERSION 2 \ No newline at end of file diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index a5c1293..497cffe 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -62,6 +62,15 @@ std::string get(nlohmann::json json, const std::string &key, const std::string & return json.at(key).at(key2).get_ref(); } +int getNum(nlohmann::json json, const std::string &key, const std::string &key2) { + if(!json.contains(key)) return 0; + if(!json.at(key).is_object()) return 0; + + if(!json.at(key).contains(key2)) return 0; + if(!json.at(key).at(key2).is_number()) return 0; + return json.at(key).at(key2).get_ref(); +} + Info parseInfo(std::string fileName) { FILE* file = fopen(fileName.c_str(), "rt"); if(!file) { @@ -85,7 +94,8 @@ void checkForValidate(void) { std::string version; version = get(json, "info", "version"); - if (version != "1") { + int ver = getNum(json, "info", "version"); + if (ver < SCRIPT_VERSION || ver > SCRIPT_VERSION) { Gui::DisplayWarnMsg(Lang::get("INCOMPATIBLE_SCRIPT")); } }