1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-12-29 10:56:01 +00:00

changed links fetching method

This commit is contained in:
flb 2021-02-08 21:30:58 +01:00
parent 2a7a182b55
commit 682e023d68
11 changed files with 10704 additions and 5682 deletions

View file

@ -22,7 +22,7 @@ DATA := data
INCLUDES := include lib/zipper/include INCLUDES := include lib/zipper/include
APP_TITLE := All-in-One Switch Updater APP_TITLE := All-in-One Switch Updater
APP_AUTHOR := HamletDuFromage APP_AUTHOR := HamletDuFromage
APP_VERSION := 2.0.1 APP_VERSION := 2.1.0
TARGET := $(notdir $(CURDIR)) TARGET := $(notdir $(CURDIR))
ROMFS := resources ROMFS := resources

View file

@ -13,23 +13,24 @@
#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/tags"
#define APP_FILENAME "/config/aio-switch-updater/app.zip" #define APP_FILENAME "/config/aio-switch-updater/app.zip"
#define SIGPATCHES_URL "https://hamletdufromage.github.io/sigpatches-updater/sigpatches.html" #define SIGPATCHES_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/sigpatches.json"
#define SIGPATCHES_FILENAME "/config/aio-switch-updater/sigpatches.zip" #define SIGPATCHES_FILENAME "/config/aio-switch-updater/sigpatches.zip"
#define HEKATE_IPL_PATH "/bootloader/hekate_ipl.ini" #define HEKATE_IPL_PATH "/bootloader/hekate_ipl.ini"
#define FIRMWARE_URL "https://hamletdufromage.github.io/switch-fw/firmwares.html" #define FIRMWARE_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/firmwares.json"
#define FIRMWARE_FILENAME "/config/aio-switch-updater/firmware.zip" #define FIRMWARE_FILENAME "/config/aio-switch-updater/firmware.zip"
#define FIRMWARE_PATH "/firmware/" #define FIRMWARE_PATH "/firmware/"
#define CFW_URL "https://hamletdufromage.github.io/switch-cfw/cfw.html" #define CFW_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/cfw.json"
#define CFW_FILENAME "/config/aio-switch-updater/cfw.zip" #define CFW_FILENAME "/config/aio-switch-updater/cfw.zip"
#define AMS_URL "https://hamletdufromage.github.io/switch-cfw/ams.html" #define AMS_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/ams.json"
#define SXOS_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/sxos.json"
#define AMS_FILENAME "/config/aio-switch-updater/ams.zip" #define AMS_FILENAME "/config/aio-switch-updater/ams.zip"
#define HEKATE_URL "https://hamletdufromage.github.io/switch-cfw/hekate.html" #define HEKATE_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/hekate.json"
#define PAYLOAD_URL "https://hamletdufromage.github.io/switch-payloads/payloads.html" #define PAYLOAD_URL "https://raw.githubusercontent.com/HamletDuFromage/nx-links/master/payloads.json"
#define CHEATS_RELEASE_URL "https://github.com/HamletDuFromage/switch-cheats-db/releases/tag/v1.0" #define CHEATS_RELEASE_URL "https://github.com/HamletDuFromage/switch-cheats-db/releases/tag/v1.0"
#define CHEATS_URL_TITLES "https://github.com/HamletDuFromage/switch-cheats-db/releases/download/v1.0/titles.zip" #define CHEATS_URL_TITLES "https://github.com/HamletDuFromage/switch-cheats-db/releases/download/v1.0/titles.zip"

View file

@ -15,7 +15,7 @@
#include "json.hpp" #include "json.hpp"
void downloadFile(const char *url, const char *output, int api); void downloadFile(const char *url, const char *output, int api);
std::tuple<std::vector<std::string>, std::vector<std::string>> fetchLinks(const char *url); std::vector<std::pair<std::string, std::string>> getLinks(const char *url);
std::string fetchTitle(const char *url); std::string fetchTitle(const char *url);
std::string downloadPage(const char* url, std::vector<std::string> headers = {}, std::string body = ""); std::string downloadPage(const char* url, std::vector<std::string> headers = {}, std::string body = "");
nlohmann::json getRequest(std::string url, std::vector<std::string> headers = {}, std::string body = ""); nlohmann::json getRequest(std::string url, std::vector<std::string> headers = {}, std::string body = "");

View file

@ -10,7 +10,7 @@ class DownloadPayloadPage : public brls::AppletFrame
brls::Label* label; brls::Label* label;
brls::Label* notFound; brls::Label* notFound;
brls::List* list; brls::List* list;
std::vector<brls::ListItem*> items; brls::ListItem* listItem;
public: public:
DownloadPayloadPage(); DownloadPayloadPage();

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
"about_tab.cpp":"", "about_tab.cpp":"",
"About_Title": "All-in-One Nintendo Switch Updater", "About_Title": "All-in-One Nintendo Switch Updater",
"copyright": "AIO-switch-updater is licensed under GPL-3.0\n\u00A9 2020 HamletDuFromage", "copyright": "AIO-switch-updater is licensed under GPL-3.0\n\u00A9 2020 HamletDuFromage",
"Disclaimers": "\uE016 Aside from cheat codes that are mirrored from the main Gbatemp thread, HamletDuFromage isn't hosting anything. All credits go to respective owners.\n\uE016 Links are refreshed every three hours. If a link remains broken after 3 hours have passed, please open a Github issue.\n", "Disclaimers": "\uE016 Aside from cheat codes that are mirrored from the main Gbatemp thread, HamletDuFromage isn't hosting anything. All credits go to respective owners.\n\uE016 Links are refreshed every 30 minutes. If a link remains broken after 30 minutes have passed, please open a Github issue.\n",
"donate": "\uE016 Like the app? Consider donating to support my efforts: 'https://git.io/donate_homlet'", "donate": "\uE016 Like the app? Consider donating to support my efforts: 'https://git.io/donate_homlet'",
"app_page.cpp":"", "app_page.cpp":"",
@ -67,6 +67,8 @@
"v2_0_0_text": "\uE016 Added ability to download cheatslips cheats.\n\uE016 Added way to toggle out tabs.\n\uE016 Various code improvements.", "v2_0_0_text": "\uE016 Added ability to download cheatslips cheats.\n\uE016 Added way to toggle out tabs.\n\uE016 Various code improvements.",
"v2_0_1": "v2.0.1", "v2_0_1": "v2.0.1",
"v2_0_1_text": "\uE016 Fixed a bug not letting the user click no when asked if they want to install hekate.n\uE016 Correct a bunch of typos.", "v2_0_1_text": "\uE016 Fixed a bug not letting the user click no when asked if they want to install hekate.n\uE016 Correct a bunch of typos.",
"v2_1_0": "v2.1.0",
"v2_1_0_text": "\uE016 Switched to a better way to get links.",
"Ok_button": "Ok", "Ok_button": "Ok",
"cheats_page.cpp":"", "cheats_page.cpp":"",
@ -208,10 +210,10 @@
"utils_do": " Do you want to overwrite existing ", "utils_do": " Do you want to overwrite existing ",
"utils_no": "No", "utils_no": "No",
"utils_yes": "Yes", "utils_yes": "Yes",
"utils_the": "The downloaded file is not a sigpatches archive. This is most likely due to a broken link. If the problem persists after more than 3 hours, please open an issue on Github.", "utils_the": "The downloaded file is not a sigpatches archive. This is most likely due to a broken link. If the problem persists after more than 30 minutes, please open an issue on Github.",
"utils_the_downloaded": "The downloaded file is not a firmware archive. This is most likely due to a broken link. If the problem persists after more than 3 hours, please open an issue on Github.", "utils_the_downloaded": "The downloaded file is not a firmware archive. This is most likely due to a broken link. If the problem persists after more than 30 minutes, please open an issue on Github.",
"ultils_overwrite": "Do you want to overwrite existing .ini config files?", "ultils_overwrite": "Do you want to overwrite existing .ini config files?",
"ultis_file": "The downloaded file is not a CFW archive. This is most likely due to a broken link. If the problem persists after more than 3 hours, please open an issue on Github.", "ultis_file": "The downloaded file is not a CFW archive. This is most likely due to a broken link. If the problem persists after more than 30 minutes, please open an issue on Github.",
"reboot_rcm" : "The Switch will now reboot to a special payload in order to finalise the install.", "reboot_rcm" : "The Switch will now reboot to a special payload in order to finalise the install.",
"hekate_dialogue" : "Do you want to also download Hekate?\nIf not, the Switch will now launch reboot to a special payload in order to finalise the install.", "hekate_dialogue" : "Do you want to also download Hekate?\nIf not, the Switch will now launch reboot to a special payload in order to finalise the install.",

View file

@ -6,10 +6,10 @@ using namespace i18n::literals;
AmsTab::AmsTab() : AmsTab::AmsTab() :
brls::List() brls::List()
{ {
std::tuple<std::vector<std::string>, std::vector<std::string>> links; std::vector<std::pair<std::string, std::string>> links;
std::string operation = "menus/Getting"_i18n ; std::string operation = "menus/Getting"_i18n ;
this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true); this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true);
links = fetchLinks(AMS_URL); links = getLinks(AMS_URL);
operation += "menus/list_cfw"_i18n ; operation += "menus/list_cfw"_i18n ;
this->description->setText( this->description->setText(
"menus/list_ams"_i18n "menus/list_ams"_i18n
@ -19,16 +19,16 @@ AmsTab::AmsTab() :
int nbLinks = std::get<0>(links).size(); int nbLinks = links.size();
if(nbLinks){ if(nbLinks){
auto hekate_link = fetchLinks(HEKATE_URL); auto hekate_link = getLinks(HEKATE_URL);
std::string hekate_url = std::get<1>(hekate_link)[0]; std::string hekate_url = links[0].second;
std::string text_hekate = "menus/list_down"_i18n + std::get<0>(hekate_link)[0]; std::string text_hekate = "menus/list_down"_i18n + links[0].first;
for (int i = 0; i<nbLinks; i++){ for (int i = 0; i < nbLinks; i++){
std::string url = std::get<1>(links)[i]; std::string url = links[i].second;
std::string text("menus/list_down"_i18n + std::get<0>(links)[i] + "menus/list_from"_i18n + url); std::string text("menus/list_down"_i18n + links[i].first + "menus/list_from"_i18n + url);
listItem = new brls::ListItem(std::get<0>(links)[i]); listItem = new brls::ListItem(links[i].first);
listItem->setHeight(LISTITEM_HEIGHT); listItem->setHeight(LISTITEM_HEIGHT);
listItem->getClickEvent()->subscribe([&, text, text_hekate, url, hekate_url, operation](brls::View* view) { listItem->getClickEvent()->subscribe([&, text, text_hekate, url, hekate_url, operation](brls::View* view) {
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();

View file

@ -85,6 +85,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true)
verTitles.push_back("menus/v2_0_1"_i18n ); verTitles.push_back("menus/v2_0_1"_i18n );
changes.push_back("menus/v2_0_1_text"_i18n ); changes.push_back("menus/v2_0_1_text"_i18n );
verTitles.push_back("2.1.0");
changes.push_back("menus/v2_1_0_text"_i18n );
int nbVersions = verTitles.size(); int nbVersions = verTitles.size();
items.reserve(nbVersions); items.reserve(nbVersions);
for(int i = nbVersions -1 ; i >= 0; i--){ for(int i = nbVersions -1 ; i >= 0; i--){

View file

@ -1,9 +1,7 @@
#include "download.hpp" #include "download.hpp"
#include "utils.hpp" #include "utils.hpp"
#include <algorithm> #include <algorithm>
#define API_AGENT "HamletDuFromage" #define API_AGENT "HamletDuFromage"
#define _1MiB 0x100000 #define _1MiB 0x100000
@ -120,42 +118,6 @@ static size_t WriteMemoryCallback2(void *contents, size_t size, size_t nmemb, vo
return realsize; return realsize;
} }
std::tuple<std::vector<std::string>, std::vector<std::string>> fetchLinks(const char *url){
CURL *curl_handle;
struct MemoryStruct chunk;
chunk.memory = static_cast<char *>(malloc(1)); /* will be grown as needed by the realloc above */
chunk.size = 0; /* no data at this point */
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback2);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, API_AGENT);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_perform(curl_handle);
std::tuple <std::vector<std::string>, std::vector<std::string>> links;
std::string s = std::string(chunk.memory);
//<a href=.*?> links
//>(?:(?!>).)*?</a> titles
auto titles = htmlProcess(s, std::regex(">(?:(?!>).)*?</a>"));
std::transform(titles.begin(), titles.end(), titles.begin(),
[](std::string s) -> std::string {return s.substr(1, s.size() - 1 - 4);});
auto targets = htmlProcess(s, std::regex("<a href=.*?>"));
std::transform(targets.begin(), targets.end(), targets.begin(),
[](std::string s) -> std::string {return s.substr(8, s.size() - 8 - 1);});
links = std::make_tuple(titles, targets);
curl_easy_cleanup(curl_handle);
free(chunk.memory);
curl_global_cleanup();
return links;
}
std::string fetchTitle(const char *url){ std::string fetchTitle(const char *url){
CURL *curl_handle; CURL *curl_handle;
struct MemoryStruct chunk; struct MemoryStruct chunk;
@ -231,8 +193,20 @@ json getRequest(std::string url, std::vector<std::string> headers, std::string b
std::string request; std::string request;
request = downloadPage(url.c_str(), headers, body); request = downloadPage(url.c_str(), headers, body);
json res = {}; if(json::accept(request)) return json::parse(request);
bool valid = json::accept(request); else return json::object();
if(valid) return json::parse(request); }
else return json::object();
std::vector<std::pair<std::string, std::string>> getLinks(const char *url) {
std::string request;
request = downloadPage(url);
nlohmann::ordered_json jason = json::accept(request) ? nlohmann::ordered_json::parse(request) : nlohmann::ordered_json::object();
std::vector<std::pair<std::string, std::string>> res;
for (auto it = jason.begin(); it != jason.end(); ++it) {
res.push_back(std::make_pair(it.key(), it.value()));
}
return res;
} }

View file

@ -12,16 +12,16 @@ DownloadPayloadPage::DownloadPayloadPage() : AppletFrame(true, true)
true true
); );
list->addView(label); list->addView(label);
std::tuple<std::vector<std::string>, std::vector<std::string>> links = fetchLinks(PAYLOAD_URL);
int nbLinks = std::get<0>(links).size(); auto links = getLinks(PAYLOAD_URL);
int nbLinks = links.size();
if(nbLinks){ if(nbLinks){
items.reserve(nbLinks);
for (int i = 0; i<nbLinks; i++){ for (int i = 0; i<nbLinks; i++){
std::string url = std::get<1>(links)[i]; std::string url = links[i].second;
std::string path = std::string(BOOTLOADER_PL_PATH) + std::get<0>(links)[i]; std::string path = std::string(BOOTLOADER_PL_PATH) + links[i].first;
std::string text("menus/Download"_i18n + std::get<0>(links)[i] + "menus/from"_i18n + url); std::string text("menus/Download"_i18n + links[i].first + "menus/from"_i18n + url);
items[i] = new brls::ListItem(std::get<0>(links)[i]); listItem = new brls::ListItem(links[i].first);
items[i]->getClickEvent()->subscribe([&, text, url, path](brls::View* view) { listItem->getClickEvent()->subscribe([&, text, url, path](brls::View* view) {
createTree(BOOTLOADER_PL_PATH); createTree(BOOTLOADER_PL_PATH);
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle("menus/getting_paylaod"_i18n ); stagedFrame->setTitle("menus/getting_paylaod"_i18n );
@ -36,7 +36,7 @@ DownloadPayloadPage::DownloadPayloadPage() : AppletFrame(true, true)
); );
brls::Application::pushView(stagedFrame); brls::Application::pushView(stagedFrame);
}); });
list->addView(items[i]); list->addView(listItem);
} }
} }
else{ else{

View file

@ -6,7 +6,8 @@ using namespace i18n::literals;
ListDownloadTab::ListDownloadTab(archiveType type) : ListDownloadTab::ListDownloadTab(archiveType type) :
brls::List() brls::List()
{ {
std::tuple<std::vector<std::string>, std::vector<std::string>> links; std::vector<std::pair<std::string, std::string>> links;
std::vector<std::pair<std::string, std::string>> sxoslinks;
std::string operation = "menus/Getting"_i18n ; std::string operation = "menus/Getting"_i18n ;
std::string firmwareText("menus/firmware_text"_i18n); std::string firmwareText("menus/firmware_text"_i18n);
@ -16,14 +17,14 @@ ListDownloadTab::ListDownloadTab(archiveType type) :
this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true); this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true);
switch(type){ switch(type){
case sigpatches: case sigpatches:
links = fetchLinks(SIGPATCHES_URL); links = getLinks(SIGPATCHES_URL);
operation += "menus/operation_1"_i18n ; operation += "menus/operation_1"_i18n ;
this->description->setText( this->description->setText(
"menus/list_sigpatches"_i18n "menus/list_sigpatches"_i18n
); );
break; break;
case fw: case fw:
links = fetchLinks(FIRMWARE_URL); links = getLinks(FIRMWARE_URL);
operation += "menus/operation_2"_i18n ; operation += "menus/operation_2"_i18n ;
SetSysFirmwareVersion ver; SetSysFirmwareVersion ver;
if (R_SUCCEEDED(setsysGetFirmwareVersion(&ver))) firmwareText += ver.display_version; if (R_SUCCEEDED(setsysGetFirmwareVersion(&ver))) firmwareText += ver.display_version;
@ -31,12 +32,13 @@ ListDownloadTab::ListDownloadTab(archiveType type) :
this->description->setText(firmwareText); this->description->setText(firmwareText);
break; break;
case app: case app:
std::get<0>(links).push_back("menus/list_latest"_i18n ); links.push_back(std::make_pair("menus/list_latest"_i18n, APP_URL));
std::get<1>(links).push_back(APP_URL);
operation += "menus/list_app"_i18n ; operation += "menus/list_app"_i18n ;
break; break;
case cfw: case cfw:
links = fetchLinks(CFW_URL); links = getLinks(CFW_URL);
sxoslinks = getLinks(SXOS_URL);
links.insert(links.end(), sxoslinks.begin(), sxoslinks.end());
operation += "menus/list_cfw"_i18n ; operation += "menus/list_cfw"_i18n ;
this->description->setText( this->description->setText(
"menus/list_main"_i18n "menus/list_main"_i18n
@ -45,16 +47,15 @@ ListDownloadTab::ListDownloadTab(archiveType type) :
case cheats: case cheats:
std::string cheatsVer = fetchTitle(CHEATS_RELEASE_URL); std::string cheatsVer = fetchTitle(CHEATS_RELEASE_URL);
if(cheatsVer != "-1"){ if(cheatsVer != "-1"){
std::get<0>(links).push_back("menus/list_latest_ver"_i18n + cheatsVer + ")");
switch(getCFW()){ switch(getCFW()){
case sxos: case sxos:
std::get<1>(links).push_back(CHEATS_URL_TITLES); links.push_back(std::make_pair("menus/list_latest_ver"_i18n + cheatsVer + ")", CHEATS_URL_TITLES));
break; break;
case ams: case ams:
std::get<1>(links).push_back(CHEATS_URL_CONTENTS); links.push_back(std::make_pair("menus/list_latest_ver"_i18n + cheatsVer + ")", CHEATS_URL_CONTENTS));
break; break;
case rnx: case rnx:
std::get<1>(links).push_back(CHEATS_URL_CONTENTS); links.push_back(std::make_pair("menus/list_latest_ver"_i18n + cheatsVer + ")", CHEATS_URL_CONTENTS));
break; break;
} }
} }
@ -66,12 +67,12 @@ ListDownloadTab::ListDownloadTab(archiveType type) :
this->addView(description); this->addView(description);
int nbLinks = std::get<0>(links).size(); int nbLinks = links.size();
if(nbLinks){ if(nbLinks){
for (int i = 0; i<nbLinks; i++){ for (int i = 0; i<nbLinks; i++){
std::string url = std::get<1>(links)[i]; std::string url = links[i].second;
std::string text("menus/list_down"_i18n + std::get<0>(links)[i] + "menus/list_from"_i18n + url); std::string text("menus/list_down"_i18n + links[i].first + "menus/list_from"_i18n + url);
listItem = new brls::ListItem(std::get<0>(links)[i]); listItem = new brls::ListItem(links[i].first);
listItem->setHeight(LISTITEM_HEIGHT); listItem->setHeight(LISTITEM_HEIGHT);
listItem->getClickEvent()->subscribe([&, text, url, type, operation](brls::View* view) { listItem->getClickEvent()->subscribe([&, text, url, type, operation](brls::View* view) {
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();