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")); } }