From 3db55a410d58e5150969a4b99d9fee49c25ceabb Mon Sep 17 00:00:00 2001 From: flb Date: Fri, 26 Feb 2021 19:21:49 +0100 Subject: [PATCH] change way to fetch latest release tag --- Makefile | 2 +- include/constants.hpp | 2 +- include/download.hpp | 2 +- source/current_cfw.cpp | 8 ++++---- source/download.cpp | 6 +++--- source/utils.cpp | 12 ++++-------- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index daecf7c..1817d38 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ DATA := data INCLUDES := include lib/zipper/include APP_TITLE := All-in-One Switch Updater APP_AUTHOR := HamletDuFromage -APP_VERSION := 2.3.4 +APP_VERSION := 2.3.5 TARGET := $(notdir $(CURDIR)) ROMFS := resources diff --git a/include/constants.hpp b/include/constants.hpp index a50e66f..5e3ac88 100644 --- a/include/constants.hpp +++ b/include/constants.hpp @@ -10,7 +10,7 @@ #define RCM_PAYLOAD_PATH "romfs:/aio_rcm.bin" #define APP_URL "https://github.com/HamletDuFromage/aio-switch-updater/releases/latest/download/aio-switch-updater.zip" -#define TAGS_INFO "https://api.github.com/repos/HamletDuFromage/aio-switch-updater/tags" +#define TAGS_INFO "https://api.github.com/repos/HamletDuFromage/aio-switch-updater/releases/latest" #define APP_FILENAME "/config/aio-switch-updater/app.zip" #define SIGPATCHES_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/sigpatches.json" diff --git a/include/download.hpp b/include/download.hpp index 7f890b2..0540e71 100644 --- a/include/download.hpp +++ b/include/download.hpp @@ -9,4 +9,4 @@ void downloadFile(const char *url, const char *output, int api); std::vector> getLinks(const char *url); std::string fetchTitle(const char *url); std::string downloadPage(const char* url, std::vector headers = {}, std::string body = ""); -nlohmann::json getRequest(std::string url, std::vector headers = {}, std::string body = ""); \ No newline at end of file +nlohmann::ordered_json getRequest(std::string url, std::vector headers = {}, std::string body = ""); \ No newline at end of file diff --git a/source/current_cfw.cpp b/source/current_cfw.cpp index 2e77e78..a50469f 100644 --- a/source/current_cfw.cpp +++ b/source/current_cfw.cpp @@ -10,7 +10,7 @@ bool isServiceRunning(const char *serviceName) { smUnregisterService(service_name); return running; -}; +} Result smAtmosphereHasService(bool *out, SmServiceName name) { u8 tmp = 0; @@ -30,8 +30,8 @@ CFW getCFW(){ return sxos; } else { // use old method just in case - if(isServiceRunning("rnx")) return rnx; - else if(isServiceRunning("tx")) return sxos; + if(isServiceRunning("rnx")) return rnx; + if(isServiceRunning("tx")) return sxos; } return ams; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/source/download.cpp b/source/download.cpp index 80631ae..1207454 100644 --- a/source/download.cpp +++ b/source/download.cpp @@ -198,12 +198,12 @@ std::string downloadPage(const char* url, std::vector headers, std: return res; } -json getRequest(std::string url, std::vector headers, std::string body) { +nlohmann::ordered_json getRequest(std::string url, std::vector headers, std::string body) { std::string request; request = downloadPage(url.c_str(), headers, body); - if(json::accept(request)) return json::parse(request); - else return json::object(); + if(json::accept(request)) return nlohmann::ordered_json::parse(request); + else return nlohmann::ordered_json::object(); } std::vector> getLinks(const char *url) { diff --git a/source/utils.cpp b/source/utils.cpp index 45db11c..034232b 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -263,15 +263,11 @@ void shut_down(bool reboot){ } std::string getLatestTag(const char *url){ - std::string page = downloadPage(url); - try{ - nlohmann::json tags = nlohmann::json::parse(page); - nlohmann::json:: iterator latest = tags.begin(); - return latest.value()["name"]; - } - catch (...){ + nlohmann::json tag = getRequest(url, {"accept: application/vnd.github.v3+json"}); + if(tag.find("tag_name") != tag.end()) + return tag["tag_name"]; + else return ""; - } } void cp(const char *from, const char *to){