2020-09-20 01:21:28 +01:00
|
|
|
#include "list_download_tab.hpp"
|
2021-09-11 14:48:13 +01:00
|
|
|
|
2021-04-30 22:33:36 +01:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
2021-09-11 14:48:13 +01:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "app_page.hpp"
|
|
|
|
#include "confirm_page.hpp"
|
|
|
|
#include "current_cfw.hpp"
|
2021-09-12 14:01:40 +01:00
|
|
|
#include "dialogue_page.hpp"
|
2021-02-10 16:28:47 +00:00
|
|
|
#include "download.hpp"
|
|
|
|
#include "extract.hpp"
|
2021-09-11 14:48:13 +01:00
|
|
|
#include "fs.hpp"
|
|
|
|
#include "utils.hpp"
|
2021-02-10 16:28:47 +00:00
|
|
|
#include "worker_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-09-27 20:56:41 +01:00
|
|
|
ListDownloadTab::ListDownloadTab(const contentType type, const nlohmann::ordered_json& nxlinks) : brls::List(), type(type), nxlinks(nxlinks)
|
2020-09-20 01:21:28 +01:00
|
|
|
{
|
2021-09-27 20:56:41 +01:00
|
|
|
this->setDescription();
|
2020-09-29 15:41:43 +01:00
|
|
|
|
2021-10-21 22:12:29 +01:00
|
|
|
this->createList();
|
2021-02-06 17:24:47 +00:00
|
|
|
|
2021-09-27 20:56:41 +01:00
|
|
|
if (this->type == contentType::cheats) {
|
|
|
|
brls::Label* cheatsLabel = new brls::Label(
|
|
|
|
brls::LabelStyle::DESCRIPTION,
|
|
|
|
"menus/cheats/cheats_label"_i18n,
|
|
|
|
true);
|
|
|
|
this->addView(cheatsLabel);
|
2021-10-21 22:12:29 +01:00
|
|
|
this->creategbatempItem();
|
|
|
|
this->createCheatSlipItem();
|
2020-09-20 01:21:28 +01:00
|
|
|
}
|
2021-02-06 17:24:47 +00:00
|
|
|
|
2021-09-27 20:56:41 +01:00
|
|
|
if (this->type == contentType::bootloaders) {
|
2021-10-21 22:12:29 +01:00
|
|
|
this->setDescription(contentType::payloads);
|
|
|
|
this->createList(contentType::payloads);
|
2021-09-27 20:56:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 22:12:29 +01:00
|
|
|
void ListDownloadTab::createList() {
|
|
|
|
ListDownloadTab::createList(this->type);
|
|
|
|
}
|
|
|
|
|
2021-09-27 20:56:41 +01:00
|
|
|
void ListDownloadTab::createList(contentType type)
|
|
|
|
{
|
|
|
|
std::vector<std::pair<std::string, std::string>> links;
|
2021-10-21 22:12:29 +01:00
|
|
|
if (type == contentType::cheats && this->newCheatsVer != "")
|
2021-09-27 20:56:41 +01:00
|
|
|
links.push_back(std::make_pair(fmt::format("{}{})", "menus/main/get_cheats"_i18n, this->newCheatsVer), CurrentCfw::running_cfw == CFW::sxos ? CHEATS_URL_TITLES : CHEATS_URL_CONTENTS));
|
|
|
|
else
|
|
|
|
links = download::getLinksFromJson(util::getValueFromKey(this->nxlinks, contentTypeNames[(int)type].data()));
|
2021-02-06 18:42:14 +00:00
|
|
|
|
2021-10-08 20:53:38 +01:00
|
|
|
if (links.size()) {
|
2021-09-11 14:48:13 +01:00
|
|
|
for (const auto& link : links) {
|
2021-10-03 18:54:09 +01:00
|
|
|
const std::string title = link.first;
|
|
|
|
const std::string url = link.second;
|
|
|
|
const std::string text("menus/common/download"_i18n + link.first + "menus/common/from"_i18n + url);
|
2021-03-16 14:56:46 +00:00
|
|
|
listItem = new brls::ListItem(link.first);
|
2021-02-06 18:42:14 +00:00
|
|
|
listItem->setHeight(LISTITEM_HEIGHT);
|
2021-10-21 22:12:29 +01:00
|
|
|
listItem->getClickEvent()->subscribe([this, type, text, url, title](brls::View* view) {
|
2021-02-06 18:42:14 +00:00
|
|
|
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
|
2021-09-27 20:56:41 +01:00
|
|
|
stagedFrame->setTitle(fmt::format("menus/main/getting"_i18n, contentTypeNames[(int)type].data()));
|
2021-09-12 14:01:40 +01:00
|
|
|
stagedFrame->addStage(new ConfirmPage(stagedFrame, text));
|
2021-09-28 13:43:48 +01:00
|
|
|
if (type != contentType::payloads) {
|
|
|
|
if (type != contentType::cheats || this->newCheatsVer != this->currentCheatsVer || !std::filesystem::exists(CHEATS_ZIP_PATH)) {
|
2021-10-21 22:12:29 +01:00
|
|
|
stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [this, type, url]() { util::downloadArchive(url, type); }));
|
2021-09-28 13:43:48 +01:00
|
|
|
}
|
2021-10-21 22:12:29 +01:00
|
|
|
stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [this, type]() { util::extractArchive(type); }));
|
2021-09-27 20:56:41 +01:00
|
|
|
}
|
2021-09-28 13:43:48 +01:00
|
|
|
else {
|
2021-09-27 20:56:41 +01:00
|
|
|
fs::createTree(BOOTLOADER_PL_PATH);
|
|
|
|
std::string path = std::string(BOOTLOADER_PL_PATH) + title;
|
|
|
|
stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, path]() { download::downloadFile(url, path, OFF); }));
|
|
|
|
}
|
2021-09-28 13:43:48 +01:00
|
|
|
|
2021-07-15 18:56:59 +01:00
|
|
|
std::string doneMsg = "menus/common/all_done"_i18n;
|
2021-09-11 14:48:13 +01:00
|
|
|
switch (type) {
|
2021-09-27 20:56:41 +01:00
|
|
|
case contentType::fw: {
|
2021-08-03 15:27:06 +01:00
|
|
|
std::string contentsPath = util::getContentsPath();
|
2021-07-16 16:33:57 +01:00
|
|
|
for (const auto& tid : {"0100000000001000", "0100000000001007", "0100000000001013"}) {
|
2021-09-11 14:48:13 +01:00
|
|
|
if (std::filesystem::exists(contentsPath + tid) && !std::filesystem::is_empty(contentsPath + tid)) {
|
2021-07-16 16:33:57 +01:00
|
|
|
doneMsg += "\n" + "menus/main/theme_warning"_i18n;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-15 18:56:59 +01:00
|
|
|
}
|
2021-09-12 14:01:40 +01:00
|
|
|
if (std::filesystem::exists(DAYBREAK_PATH)) {
|
|
|
|
stagedFrame->addStage(new DialoguePage_fw(stagedFrame, doneMsg));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stagedFrame->addStage(new ConfirmPage(stagedFrame, doneMsg, true));
|
|
|
|
}
|
2021-07-15 18:56:59 +01:00
|
|
|
break;
|
2021-08-03 15:27:06 +01:00
|
|
|
}
|
2021-09-27 20:56:41 +01:00
|
|
|
case contentType::sigpatches:
|
2021-07-15 18:56:59 +01:00
|
|
|
doneMsg += "\n" + "menus/sigpatches/reboot"_i18n;
|
2021-09-12 14:01:40 +01:00
|
|
|
stagedFrame->addStage(new ConfirmPage(stagedFrame, doneMsg, true));
|
2021-07-15 18:56:59 +01:00
|
|
|
break;
|
2021-08-03 15:27:06 +01:00
|
|
|
default:
|
2021-09-12 14:01:40 +01:00
|
|
|
stagedFrame->addStage(new ConfirmPage(stagedFrame, doneMsg, true));
|
2021-08-03 15:27:06 +01:00
|
|
|
break;
|
2021-07-15 18:56:59 +01:00
|
|
|
}
|
2021-02-06 18:42:14 +00:00
|
|
|
brls::Application::pushView(stagedFrame);
|
|
|
|
});
|
|
|
|
this->addView(listItem);
|
|
|
|
}
|
|
|
|
}
|
2021-09-11 14:48:13 +01:00
|
|
|
else {
|
2021-09-27 20:56:41 +01:00
|
|
|
this->displayNotFound();
|
2021-02-06 20:08:51 +00:00
|
|
|
}
|
2021-09-27 20:56:41 +01:00
|
|
|
}
|
2021-02-06 20:08:51 +00:00
|
|
|
|
2021-09-27 20:56:41 +01:00
|
|
|
void ListDownloadTab::displayNotFound()
|
|
|
|
{
|
|
|
|
brls::Label* notFound = new brls::Label(
|
|
|
|
brls::LabelStyle::SMALL,
|
|
|
|
"menus/main/links_not_found"_i18n,
|
|
|
|
true);
|
|
|
|
notFound->setHorizontalAlign(NVG_ALIGN_CENTER);
|
|
|
|
this->addView(notFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListDownloadTab::setDescription()
|
2021-10-21 22:12:29 +01:00
|
|
|
{
|
|
|
|
this->setDescription(this->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListDownloadTab::setDescription(contentType type)
|
2021-09-27 20:56:41 +01:00
|
|
|
{
|
|
|
|
brls::Label* description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true);
|
|
|
|
|
2021-10-21 22:12:29 +01:00
|
|
|
switch (type) {
|
2021-09-27 20:56:41 +01:00
|
|
|
case contentType::sigpatches:
|
2021-10-21 22:12:29 +01:00
|
|
|
description->setText("menus/main/sigpatches_text"_i18n);
|
2021-09-27 20:56:41 +01:00
|
|
|
break;
|
|
|
|
case contentType::fw: {
|
|
|
|
SetSysFirmwareVersion ver;
|
|
|
|
description->setText(fmt::format("{}{}", "menus/main/firmware_text"_i18n, R_SUCCEEDED(setsysGetFirmwareVersion(&ver)) ? ver.display_version : "menus/main/not_found"_i18n));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case contentType::bootloaders:
|
|
|
|
description->setText(
|
|
|
|
"menus/main/bootloaders_text"_i18n);
|
|
|
|
break;
|
|
|
|
case contentType::cheats:
|
|
|
|
this->newCheatsVer = util::downloadFileToString(CHEATS_URL_VERSION);
|
|
|
|
this->currentCheatsVer = util::readVersion(CHEATS_VERSION);
|
|
|
|
description->setText("menus/main/cheats_text"_i18n + this->currentCheatsVer);
|
|
|
|
break;
|
2021-10-21 22:12:29 +01:00
|
|
|
case contentType::payloads:
|
|
|
|
description->setText("menus/main/payloads_label"_i18n);
|
|
|
|
break;
|
2021-09-27 20:56:41 +01:00
|
|
|
default:
|
|
|
|
break;
|
2021-06-05 18:10:51 +01:00
|
|
|
}
|
2021-09-27 20:56:41 +01:00
|
|
|
|
|
|
|
this->addView(description);
|
2021-06-05 18:10:51 +01:00
|
|
|
}
|
|
|
|
|
2021-09-11 14:48:13 +01:00
|
|
|
void ListDownloadTab::createCheatSlipItem()
|
|
|
|
{
|
2021-10-21 22:12:29 +01:00
|
|
|
brls::ListItem* cheatslipsItem = new brls::ListItem("menus/cheats/get_cheatslips"_i18n);
|
2021-06-05 18:10:51 +01:00
|
|
|
cheatslipsItem->setHeight(LISTITEM_HEIGHT);
|
2021-10-01 18:22:52 +01:00
|
|
|
cheatslipsItem->getClickEvent()->subscribe([](brls::View* view) {
|
2021-09-11 14:48:13 +01:00
|
|
|
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 {
|
2021-07-19 22:06:40 +01:00
|
|
|
std::string usr, pwd;
|
|
|
|
//Result rc = swkbdCreate(&kbd, 0);
|
2021-10-01 18:22:52 +01:00
|
|
|
brls::Swkbd::openForText([&usr](std::string text) { usr = text; }, "cheatslips.com e-mail", "", 64, "", 0, "Submit", "cheatslips.com e-mail");
|
|
|
|
brls::Swkbd::openForText([&pwd](std::string text) { pwd = text; }, "cheatslips.com password", "", 64, "", 0, "Submit", "cheatslips.com password", true);
|
2021-09-11 14:48:13 +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-09-11 14:48:13 +01:00
|
|
|
{"Accept: application/json",
|
|
|
|
"Content-Type: application/json",
|
|
|
|
"charset: utf-8"},
|
|
|
|
body);
|
|
|
|
if (token.find("token") != token.end()) {
|
2021-06-05 18:10:51 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-09-11 14:48:13 +01:00
|
|
|
void ListDownloadTab::creategbatempItem()
|
|
|
|
{
|
2021-10-21 22:12:29 +01:00
|
|
|
brls::ListItem* gbatempItem = new brls::ListItem("menus/cheats/get_gbatemp"_i18n);
|
2021-06-05 18:10:51 +01:00
|
|
|
gbatempItem->setHeight(LISTITEM_HEIGHT);
|
2021-10-01 18:22:52 +01:00
|
|
|
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);
|
2020-09-20 01:21:28 +01:00
|
|
|
}
|