1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-25 02:52:05 +00:00
AIO-switch-updater/source/list_download_tab.cpp

190 lines
7.5 KiB
C++
Raw Normal View History

2020-09-20 01:21:28 +01:00
#include "list_download_tab.hpp"
2021-02-10 16:28:47 +00:00
#include <string>
#include "download.hpp"
#include "extract.hpp"
#include "confirm_page.hpp"
#include "worker_page.hpp"
#include "current_cfw.hpp"
#include "utils.hpp"
#include "app_page.hpp"
#include <filesystem>
#include <fstream>
namespace i18n = brls::i18n;
using namespace i18n::literals;
2021-02-12 22:20:16 +00:00
ListDownloadTab::ListDownloadTab(const archiveType type) :
2020-09-20 01:21:28 +01:00
brls::List()
{
2021-02-08 20:30:58 +00:00
std::vector<std::pair<std::string, std::string>> links;
std::vector<std::pair<std::string, std::string>> sxoslinks;
2021-03-01 18:19:17 +00:00
std::string operation = "menus/main/getting"_i18n ;
std::string firmwareText("menus/main/firmware_text"_i18n);
std::string currentCheatsVer =
2021-03-01 18:19:17 +00:00
"menus/main/cheats_text"_i18n ;
2020-09-20 01:21:28 +01:00
this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true);
switch(type){
case sigpatches:
2021-02-08 20:30:58 +00:00
links = getLinks(SIGPATCHES_URL);
2021-03-01 18:19:17 +00:00
operation += "menus/main/sigpatches"_i18n ;
2020-09-20 01:21:28 +01:00
this->description->setText(
2021-03-01 18:19:17 +00:00
"menus/main/sigpatches_text"_i18n
2020-09-20 01:21:28 +01:00
);
break;
case fw:
2021-02-08 20:30:58 +00:00
links = getLinks(FIRMWARE_URL);
2021-03-01 18:19:17 +00:00
operation += "menus/main/firmware"_i18n ;
SetSysFirmwareVersion ver;
if (R_SUCCEEDED(setsysGetFirmwareVersion(&ver))) firmwareText += ver.display_version;
2021-03-01 18:19:17 +00:00
else firmwareText += "menus/main/not_found"_i18n ;
this->description->setText(firmwareText);
2020-09-20 01:21:28 +01:00
break;
case app:
2021-03-01 18:19:17 +00:00
links.push_back(std::make_pair("menus/main/latest_cheats"_i18n, APP_URL));
operation += "menus/main/app"_i18n ;
2020-09-20 01:21:28 +01:00
break;
case cfw:
2021-02-08 20:30:58 +00:00
links = getLinks(CFW_URL);
sxoslinks = getLinks(SXOS_URL);
links.insert(links.end(), sxoslinks.begin(), sxoslinks.end());
2021-03-01 18:19:17 +00:00
operation += "menus/main/cfw"_i18n ;
2020-09-20 01:21:28 +01:00
this->description->setText(
2021-03-01 18:19:17 +00:00
"menus/main/cfw_text"_i18n
2020-09-20 01:21:28 +01:00
);
break;
case cheats:
std::string cheatsVer = fetchTitle(CHEATS_RELEASE_URL);
if(cheatsVer != "-1"){
2021-02-10 16:28:47 +00:00
switch(running_cfw){
2020-09-20 01:21:28 +01:00
case sxos:
2021-03-01 18:19:17 +00:00
links.push_back(std::make_pair("menus/main/cheats_text"_i18n + cheatsVer + ")", CHEATS_URL_TITLES));
2020-09-20 01:21:28 +01:00
break;
case ams:
2021-03-01 18:19:17 +00:00
links.push_back(std::make_pair("menus/main/cheats_text"_i18n + cheatsVer + ")", CHEATS_URL_CONTENTS));
2020-09-20 01:21:28 +01:00
break;
case rnx:
2021-03-01 18:19:17 +00:00
links.push_back(std::make_pair("menus/main/cheats_text"_i18n + cheatsVer + ")", CHEATS_URL_CONTENTS));
2020-09-20 01:21:28 +01:00
break;
}
}
2021-03-01 18:19:17 +00:00
operation += "menus/main/cheats"_i18n ;
currentCheatsVer += readVersion(CHEATS_VERSION);
this->description->setText(currentCheatsVer);
2020-09-20 01:21:28 +01:00
break;
}
2020-09-20 01:21:28 +01:00
this->addView(description);
2021-02-06 18:42:14 +00:00
2021-02-08 20:30:58 +00:00
int nbLinks = links.size();
2021-02-06 18:42:14 +00:00
if(nbLinks){
for (int i = 0; i<nbLinks; i++){
2021-02-08 20:30:58 +00:00
std::string url = links[i].second;
2021-03-01 18:19:17 +00:00
std::string text("menus/common/download"_i18n + links[i].first + "menus/common/from"_i18n + url);
2021-02-08 20:30:58 +00:00
listItem = new brls::ListItem(links[i].first);
2021-02-06 18:42:14 +00:00
listItem->setHeight(LISTITEM_HEIGHT);
listItem->getClickEvent()->subscribe([&, text, url, type, operation](brls::View* view) {
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle(operation);
stagedFrame->addStage(
new ConfirmPage(stagedFrame, text)
);
stagedFrame->addStage(
2021-03-01 18:19:17 +00:00
new WorkerPage(stagedFrame, "menus/common/downloading"_i18n , [url, type](){downloadArchive(url, type);})
2021-02-06 18:42:14 +00:00
);
stagedFrame->addStage(
2021-03-01 18:19:17 +00:00
new WorkerPage(stagedFrame, "menus/common/extracting"_i18n , [type](){extractArchive(type);})
2021-02-06 18:42:14 +00:00
);
stagedFrame->addStage(
new ConfirmPage(stagedFrame,
(type == sigpatches) ?
2021-03-01 18:19:17 +00:00
"menus/common/all_done"_i18n + "\n" + "menus/sigpatches/reboot"_i18n :
"menus/common/all_done"_i18n,
true)
2021-02-06 18:42:14 +00:00
);
brls::Application::pushView(stagedFrame);
});
this->addView(listItem);
}
}
2021-02-06 20:08:51 +00:00
else{
notFound = new brls::Label(
brls::LabelStyle::DESCRIPTION,
2021-03-01 18:19:17 +00:00
"menus/main/links_not_found"_i18n ,
2021-02-06 20:08:51 +00:00
true
);
notFound->setHorizontalAlign(NVG_ALIGN_CENTER);
this->addView(notFound);
}
if(type == cheats){
2021-02-06 18:42:14 +00:00
cheatSlipLabel = new brls::Label(
brls::LabelStyle::DESCRIPTION,
2021-03-01 18:19:17 +00:00
"menus/cheats/cheatslips_label"_i18n ,
2021-02-06 18:42:14 +00:00
true
);
this->addView(cheatSlipLabel);
2021-03-01 18:19:17 +00:00
cheatslipsItem = new brls::ListItem("menus/cheats/get_cheatslips"_i18n);
cheatslipsItem->setHeight(LISTITEM_HEIGHT);
cheatslipsItem->getClickEvent()->subscribe([&](brls::View* view) {
if(std::filesystem::exists(TOKEN_PATH)) {
brls::Application::pushView(new AppPage(true));
return true;
}
else {
SwkbdConfig kbd;
char usr[0x100] = {0};
char pwd[0x100] = {0};
Result rc = swkbdCreate(&kbd, 0);
if (R_SUCCEEDED(rc)) {
swkbdConfigMakePresetDefault(&kbd);
swkbdConfigSetOkButtonText(&kbd, "Submit");
swkbdConfigSetGuideText(&kbd, "www.cheatslips.com e-mail");
swkbdShow(&kbd, usr, sizeof(usr));
swkbdClose(&kbd);
rc = swkbdCreate(&kbd, 0);
if(R_SUCCEEDED(rc)){
swkbdConfigMakePresetPassword(&kbd);
swkbdConfigSetOkButtonText(&kbd, "Submit");
swkbdConfigSetGuideText(&kbd, "www.cheatslips.com password");
swkbdShow(&kbd, pwd, sizeof(pwd));
swkbdClose(&kbd);
}
}
std::string body = "{\"email\":\"" + std::string(usr)
+ "\",\"password\":\"" + std::string(pwd) + "\"}";
nlohmann::json token = getRequest(CHEATSLIPS_TOKEN_URL,
{"Accept: application/json",
"Content-Type: application/json",
"charset: utf-8"},
body);
if(token.find("token") != token.end()) {
std::ofstream tokenFile(TOKEN_PATH);
tokenFile << token.dump();
tokenFile.close();
brls::Application::pushView(new AppPage(true));
return true;
}
else {
2021-03-01 18:19:17 +00:00
brls::Dialog* dialog = new brls::Dialog("menus/cheats/cheatslips_wrong_id"_i18n + "\n" + "menus/cheats/kb_error"_i18n);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/Ok_button"_i18n , callback);
dialog->setCancelable(true);
dialog->open();
return true;
}
}
});
this->addView(cheatslipsItem);
}
2020-09-20 01:21:28 +01:00
}
ListDownloadTab::~ListDownloadTab(){
}