2020-09-20 01:21:28 +01:00
|
|
|
#include "app_page.hpp"
|
2021-02-10 16:28:47 +00:00
|
|
|
#include <switch.h>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
|
|
|
#include "current_cfw.hpp"
|
|
|
|
#include "worker_page.hpp"
|
|
|
|
#include "confirm_page.hpp"
|
|
|
|
#include "download_cheats_page.hpp"
|
2021-03-16 14:56:46 +00:00
|
|
|
#include "utils.hpp"
|
|
|
|
#include "fs.hpp"
|
|
|
|
|
2020-10-05 23:53:12 +01:00
|
|
|
namespace i18n = brls::i18n;
|
|
|
|
using namespace i18n::literals;
|
2021-06-05 18:10:51 +01:00
|
|
|
AppPage::AppPage(const appPageType type) : AppletFrame(true, true)
|
2020-09-20 01:21:28 +01:00
|
|
|
{
|
|
|
|
list = new brls::List();
|
2021-06-05 18:10:51 +01:00
|
|
|
switch(type){
|
|
|
|
case appPageType::base:
|
|
|
|
this->setTitle("menus/cheats/installed"_i18n);
|
|
|
|
label = new brls::Label(brls::LabelStyle::DESCRIPTION, "menus/cheats/label"_i18n, true);
|
|
|
|
break;
|
|
|
|
case appPageType::cheatSlips:
|
|
|
|
this->setTitle("menus/cheats/cheastlips_title"_i18n);
|
|
|
|
label = new brls::Label(brls::LabelStyle::DESCRIPTION, "menus/cheats/cheatslips_select"_i18n, true);
|
|
|
|
break;
|
|
|
|
case appPageType::gbatempCheats:
|
|
|
|
this->setTitle("menus/cheats/gbatemp_title"_i18n);
|
|
|
|
label = new brls::Label( brls::LabelStyle::DESCRIPTION,"menus/cheats/cheatslips_select"_i18n,true);
|
|
|
|
break;
|
|
|
|
}
|
2020-09-20 01:21:28 +01:00
|
|
|
list->addView(label);
|
|
|
|
|
|
|
|
NsApplicationRecord record;
|
|
|
|
uint64_t tid;
|
|
|
|
NsApplicationControlData controlData;
|
|
|
|
NacpLanguageEntry* langEntry = NULL;
|
|
|
|
|
|
|
|
Result rc;
|
|
|
|
size_t i = 0;
|
|
|
|
int recordCount = 0;
|
|
|
|
size_t controlSize = 0;
|
|
|
|
|
2021-03-16 14:56:46 +00:00
|
|
|
titles = fs::readLineByLine(UPDATED_TITLES_PATH);
|
2020-09-20 01:21:28 +01:00
|
|
|
|
2021-06-05 18:10:51 +01:00
|
|
|
if(!titles.empty() || type == appPageType::cheatSlips || type == appPageType::gbatempCheats) {
|
2020-09-20 01:21:28 +01:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
rc = nsListApplicationRecord(&record, sizeof(record), i, &recordCount);
|
|
|
|
if (R_FAILED(rc)) break;
|
2021-02-06 17:24:47 +00:00
|
|
|
if(recordCount <= 0) break;
|
2020-09-20 01:21:28 +01:00
|
|
|
|
|
|
|
tid = record.application_id;
|
|
|
|
rc = nsGetApplicationControlData(NsApplicationControlSource_Storage, tid, &controlData, sizeof(controlData), &controlSize);
|
|
|
|
if (R_FAILED(rc)) break;
|
|
|
|
rc = nacpGetLanguageEntry(&controlData.nacp, &langEntry);
|
|
|
|
if (R_FAILED(rc)) break;
|
2021-02-06 17:24:47 +00:00
|
|
|
|
|
|
|
if (!langEntry->name) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2021-06-05 18:10:51 +01:00
|
|
|
if(type == appPageType::base && titles.find(util::formatApplicationId(tid)) == titles.end()) {
|
2020-09-20 01:21:28 +01:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-16 02:04:21 +00:00
|
|
|
listItem = new brls::ListItem(std::string(langEntry->name), "", util::formatApplicationId(tid));
|
2021-02-06 17:24:47 +00:00
|
|
|
listItem->setThumbnail(controlData.icon, sizeof(controlData.icon));
|
2021-06-05 18:10:51 +01:00
|
|
|
|
|
|
|
switch(type){
|
|
|
|
case appPageType::cheatSlips:
|
|
|
|
listItem->getClickEvent()->subscribe([&, tid](brls::View* view) { brls::Application::pushView(new DownloadCheatsPage_CheatSlips(tid)); });
|
|
|
|
break;
|
|
|
|
case appPageType::gbatempCheats:
|
|
|
|
listItem->getClickEvent()->subscribe([&, tid](brls::View* view) { brls::Application::pushView(new DownloadCheatsPage_GbaTemp(tid)); });
|
|
|
|
break;
|
|
|
|
case appPageType::base:
|
|
|
|
break;
|
2021-02-06 17:24:47 +00:00
|
|
|
}
|
2020-09-20 01:21:28 +01:00
|
|
|
|
|
|
|
list->addView(listItem);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2021-03-01 18:19:17 +00:00
|
|
|
std::string text("menus/cheats/downloading"_i18n);
|
2020-09-20 01:21:28 +01:00
|
|
|
std::string url = "";
|
2021-03-16 02:04:21 +00:00
|
|
|
switch(CurrentCfw::running_cfw){
|
|
|
|
case CFW::ams:
|
2020-09-20 01:21:28 +01:00
|
|
|
url += CHEATS_URL_CONTENTS;
|
|
|
|
break;
|
2021-03-16 02:04:21 +00:00
|
|
|
case CFW::rnx:
|
2020-09-20 01:21:28 +01:00
|
|
|
url += CHEATS_URL_CONTENTS;
|
|
|
|
break;
|
2021-03-16 02:04:21 +00:00
|
|
|
case CFW::sxos:
|
2020-09-20 01:21:28 +01:00
|
|
|
url += CHEATS_URL_CONTENTS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
text += url;
|
2021-03-14 15:24:56 +00:00
|
|
|
download = new brls::ListItem("menus/cheats/dl_latest"_i18n);
|
2021-03-16 02:04:21 +00:00
|
|
|
download->getClickEvent()->subscribe([&, url, text](brls::View* view) {
|
2020-09-20 01:21:28 +01:00
|
|
|
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
|
2021-03-10 20:54:17 +00:00
|
|
|
stagedFrame->setTitle("menus/cheats/getting_cheats"_i18n);
|
2020-09-20 01:21:28 +01:00
|
|
|
stagedFrame->addStage(
|
|
|
|
new ConfirmPage(stagedFrame, text)
|
|
|
|
);
|
|
|
|
stagedFrame->addStage(
|
2021-03-16 02:04:21 +00:00
|
|
|
new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url](){util::downloadArchive(url, archiveType::cheats);})
|
2020-09-20 01:21:28 +01:00
|
|
|
);
|
|
|
|
stagedFrame->addStage(
|
2021-03-16 02:04:21 +00:00
|
|
|
new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [](){util::extractArchive(archiveType::cheats);})
|
2020-09-20 01:21:28 +01:00
|
|
|
);
|
|
|
|
stagedFrame->addStage(
|
2021-03-10 20:54:17 +00:00
|
|
|
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)
|
2020-09-20 01:21:28 +01:00
|
|
|
);
|
|
|
|
brls::Application::pushView(stagedFrame);
|
|
|
|
});
|
|
|
|
list->addView(download);
|
|
|
|
this->setContentView(list);
|
|
|
|
}
|