2020-09-20 01:21:28 +01:00
|
|
|
#include "list_download_tab.hpp"
|
2021-02-10 16:28:47 +00:00
|
|
|
#include <string>
|
2021-04-30 22:33:36 +01:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
|
|
|
#include "utils.hpp"
|
|
|
|
#include "fs.hpp"
|
2021-02-10 16:28:47 +00:00
|
|
|
#include "download.hpp"
|
|
|
|
#include "extract.hpp"
|
|
|
|
#include "confirm_page.hpp"
|
|
|
|
#include "worker_page.hpp"
|
|
|
|
#include "current_cfw.hpp"
|
|
|
|
#include "app_page.hpp"
|
2021-03-10 16:23:02 +00:00
|
|
|
|
2020-10-05 23:53:12 +01:00
|
|
|
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-06-27 23:46:00 +01:00
|
|
|
//std::vector<std::pair<std::string, std::string>> links, sxoslinks;
|
|
|
|
std::vector<std::pair<std::string, std::string>> links;
|
2021-03-10 20:43:00 +00:00
|
|
|
std::string operation("menus/main/getting"_i18n);
|
2021-03-01 18:19:17 +00:00
|
|
|
std::string firmwareText("menus/main/firmware_text"_i18n);
|
2020-09-29 15:41:43 +01:00
|
|
|
|
2021-03-10 20:54:17 +00:00
|
|
|
std::string currentCheatsVer = "menus/main/cheats_text"_i18n;
|
2021-02-06 17:24:47 +00:00
|
|
|
|
2020-09-20 01:21:28 +01:00
|
|
|
this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true);
|
|
|
|
switch(type){
|
2021-03-16 02:04:21 +00:00
|
|
|
case archiveType::ams_cfw:
|
|
|
|
case archiveType::sigpatches:
|
|
|
|
links = download::getLinks(SIGPATCHES_URL);
|
2021-03-10 20:54: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;
|
2021-03-16 02:04:21 +00:00
|
|
|
case archiveType::fw:
|
|
|
|
links = download::getLinks(FIRMWARE_URL);
|
2021-03-10 20:54:17 +00:00
|
|
|
operation += "menus/main/firmware"_i18n;
|
2020-09-29 15:41:43 +01:00
|
|
|
SetSysFirmwareVersion ver;
|
|
|
|
if (R_SUCCEEDED(setsysGetFirmwareVersion(&ver))) firmwareText += ver.display_version;
|
2021-03-10 20:54:17 +00:00
|
|
|
else firmwareText += "menus/main/not_found"_i18n;
|
2020-09-22 22:12:05 +01:00
|
|
|
this->description->setText(firmwareText);
|
2020-09-20 01:21:28 +01:00
|
|
|
break;
|
2021-03-16 02:04:21 +00:00
|
|
|
case archiveType::app:
|
2021-03-01 18:19:17 +00:00
|
|
|
links.push_back(std::make_pair("menus/main/latest_cheats"_i18n, APP_URL));
|
2021-03-10 20:54:17 +00:00
|
|
|
operation += "menus/main/app"_i18n;
|
2020-09-20 01:21:28 +01:00
|
|
|
break;
|
2021-03-16 02:04:21 +00:00
|
|
|
case archiveType::cfw:
|
|
|
|
links = download::getLinks(CFW_URL);
|
2021-06-27 23:46:00 +01:00
|
|
|
// sxos is dead anyways
|
|
|
|
/* sxoslinks = download::getLinks(SXOS_URL);
|
|
|
|
links.insert(links.end(), sxoslinks.begin(), sxoslinks.end()); */
|
2021-03-10 20:54:17 +00:00
|
|
|
operation += "menus/main/cfw"_i18n;
|
2020-09-20 01:21:28 +01:00
|
|
|
this->description->setText(
|
2021-06-27 23:46:00 +01:00
|
|
|
"menus/main/bootloaders_text"_i18n
|
2020-09-20 01:21:28 +01:00
|
|
|
);
|
|
|
|
break;
|
2021-03-16 02:04:21 +00:00
|
|
|
case archiveType::cheats:
|
2021-06-27 23:46:00 +01:00
|
|
|
std::string cheatsVer = util::downloadFileToString(CHEATS_URL_VERSION);
|
2021-03-10 16:23:02 +00:00
|
|
|
if(cheatsVer != ""){
|
2021-03-16 02:04:21 +00:00
|
|
|
switch(CurrentCfw::running_cfw){
|
|
|
|
case CFW::sxos:
|
2021-03-10 16:23:02 +00:00
|
|
|
links.push_back(std::make_pair("menus/main/get_cheats"_i18n + cheatsVer + ")", CHEATS_URL_TITLES));
|
2020-09-20 01:21:28 +01:00
|
|
|
break;
|
2021-03-16 02:04:21 +00:00
|
|
|
case CFW::ams:
|
2021-03-10 16:23:02 +00:00
|
|
|
links.push_back(std::make_pair("menus/main/get_cheats"_i18n + cheatsVer + ")", CHEATS_URL_CONTENTS));
|
2020-09-20 01:21:28 +01:00
|
|
|
break;
|
2021-03-16 02:04:21 +00:00
|
|
|
case CFW::rnx:
|
2021-03-10 16:23:02 +00:00
|
|
|
links.push_back(std::make_pair("menus/main/get_cheats"_i18n + cheatsVer + ")", CHEATS_URL_CONTENTS));
|
2020-09-20 01:21:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-10 20:54:17 +00:00
|
|
|
operation += "menus/main/cheats"_i18n;
|
2021-03-16 02:04:21 +00:00
|
|
|
currentCheatsVer += util::readVersion(CHEATS_VERSION);
|
2020-09-29 15:41:43 +01:00
|
|
|
this->description->setText(currentCheatsVer);
|
2020-09-20 01:21:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-02-06 17:24:47 +00:00
|
|
|
|
2020-09-20 01:21:28 +01:00
|
|
|
this->addView(description);
|
2021-02-06 18:42:14 +00:00
|
|
|
|
2021-04-15 12:24:11 +01:00
|
|
|
this->size = links.size();
|
|
|
|
if(this->size){
|
2021-03-16 14:56:46 +00:00
|
|
|
for (const auto& link : links){
|
|
|
|
std::string url = link.second;
|
|
|
|
std::string text("menus/common/download"_i18n + link.first + "menus/common/from"_i18n + url);
|
|
|
|
listItem = new brls::ListItem(link.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-16 02:04:21 +00:00
|
|
|
new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, type](){util::downloadArchive(url, type);})
|
2021-02-06 18:42:14 +00:00
|
|
|
);
|
|
|
|
stagedFrame->addStage(
|
2021-03-16 02:04:21 +00:00
|
|
|
new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type](){util::extractArchive(type);})
|
2021-02-06 18:42:14 +00:00
|
|
|
);
|
|
|
|
stagedFrame->addStage(
|
2021-02-09 14:10:12 +00:00
|
|
|
new ConfirmPage(stagedFrame,
|
2021-03-16 02:04:21 +00:00
|
|
|
(type == archiveType::sigpatches) ?
|
2021-03-01 18:19:17 +00:00
|
|
|
"menus/common/all_done"_i18n + "\n" + "menus/sigpatches/reboot"_i18n :
|
|
|
|
"menus/common/all_done"_i18n,
|
2021-02-09 14:10:12 +00:00
|
|
|
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(
|
2021-06-27 23:46:00 +01:00
|
|
|
brls::LabelStyle::SMALL,
|
2021-03-10 20:54: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);
|
|
|
|
}
|
|
|
|
|
2021-03-16 02:04:21 +00:00
|
|
|
if(type == archiveType::cheats){
|
2021-06-05 18:10:51 +01:00
|
|
|
cheatsLabel = new brls::Label(
|
|
|
|
brls::LabelStyle::DESCRIPTION,
|
|
|
|
"menus/cheats/cheats_label"_i18n,
|
|
|
|
true
|
2021-02-06 18:42:14 +00:00
|
|
|
);
|
2021-06-05 18:10:51 +01:00
|
|
|
this->addView(cheatsLabel);
|
|
|
|
creategbatempItem();
|
|
|
|
createCheatSlipItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListDownloadTab::createCheatSlipItem() {
|
|
|
|
this->size += 1;
|
|
|
|
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)) {
|
2021-06-27 23:46:00 +01:00
|
|
|
brls::Application::pushView(new AppPage_CheatSlips());
|
2021-06-05 18:10:51 +01:00
|
|
|
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);
|
2021-02-06 17:24:47 +00:00
|
|
|
swkbdConfigSetOkButtonText(&kbd, "Submit");
|
2021-06-05 18:10:51 +01:00
|
|
|
swkbdConfigSetGuideText(&kbd, "www.cheatslips.com password");
|
|
|
|
swkbdShow(&kbd, pwd, sizeof(pwd));
|
2021-02-06 17:24:47 +00:00
|
|
|
swkbdClose(&kbd);
|
|
|
|
}
|
|
|
|
}
|
2021-06-05 18:10:51 +01:00
|
|
|
std::string body = "{\"email\":\"" + std::string(usr)
|
|
|
|
+ "\",\"password\":\"" + std::string(pwd) + "\"}";
|
2021-06-27 23:46:00 +01:00
|
|
|
nlohmann::ordered_json token;
|
|
|
|
download::getRequest(CHEATSLIPS_TOKEN_URL, token,
|
2021-06-05 18:10:51 +01:00
|
|
|
{"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();
|
2021-06-27 23:46:00 +01:00
|
|
|
brls::Application::pushView(new AppPage_CheatSlips());
|
2021-06-05 18:10:51 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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/common/ok"_i18n, callback);
|
|
|
|
dialog->setCancelable(true);
|
|
|
|
dialog->open();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this->addView(cheatslipsItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ListDownloadTab::creategbatempItem() {
|
|
|
|
this->size += 1;
|
|
|
|
gbatempItem = new brls::ListItem("menus/cheats/get_gbatemp"_i18n);
|
|
|
|
gbatempItem->setHeight(LISTITEM_HEIGHT);
|
|
|
|
gbatempItem->getClickEvent()->subscribe([&](brls::View* view) {
|
2021-06-27 23:46:00 +01:00
|
|
|
brls::Application::pushView(new AppPage_Gbatemp());
|
2021-06-05 18:10:51 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
this->addView(gbatempItem);
|
2021-04-15 12:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
brls::View* ListDownloadTab::getDefaultFocus()
|
|
|
|
{
|
|
|
|
if(this->size)
|
|
|
|
return this->brls::List::getDefaultFocus();
|
|
|
|
else
|
|
|
|
return nullptr;
|
2020-09-20 01:21:28 +01:00
|
|
|
}
|