2020-09-26 15:55:24 +01:00
|
|
|
#include "exclude_page.hpp"
|
2021-09-11 14:48:13 +01:00
|
|
|
|
2021-02-10 16:28:47 +00:00
|
|
|
#include <switch.h>
|
2021-09-11 14:48:13 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
2021-02-10 16:28:47 +00:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
2021-09-11 14:48:13 +01:00
|
|
|
|
2021-03-16 02:04:21 +00:00
|
|
|
#include "extract.hpp"
|
2021-03-16 14:56:46 +00:00
|
|
|
#include "fs.hpp"
|
2021-09-11 14:48:13 +01:00
|
|
|
#include "utils.hpp"
|
2021-03-16 02:04:21 +00:00
|
|
|
|
2020-10-05 23:53:12 +01:00
|
|
|
namespace i18n = brls::i18n;
|
|
|
|
using namespace i18n::literals;
|
2020-09-26 15:55:24 +01:00
|
|
|
ExcludePage::ExcludePage() : AppletFrame(true, true)
|
|
|
|
{
|
2021-03-10 20:54:17 +00:00
|
|
|
this->setTitle("menus/cheats/exclude_titles"_i18n);
|
2020-09-26 15:55:24 +01:00
|
|
|
list = new brls::List();
|
|
|
|
label = new brls::Label(
|
|
|
|
brls::LabelStyle::DESCRIPTION,
|
2021-03-10 20:54:17 +00:00
|
|
|
"menus/cheats/exclude_titles_desc"_i18n,
|
2021-09-11 14:48:13 +01:00
|
|
|
true);
|
2020-09-26 15:55:24 +01:00
|
|
|
list->addView(label);
|
|
|
|
|
|
|
|
NsApplicationRecord record;
|
|
|
|
uint64_t tid;
|
|
|
|
NsApplicationControlData controlData;
|
|
|
|
NacpLanguageEntry* langEntry = NULL;
|
|
|
|
|
|
|
|
Result rc;
|
2021-09-11 14:48:13 +01:00
|
|
|
size_t i = 0;
|
|
|
|
int recordCount = 0;
|
|
|
|
size_t controlSize = 0;
|
2020-09-26 15:55:24 +01:00
|
|
|
|
2021-03-16 14:56:46 +00:00
|
|
|
titles = fs::readLineByLine(CHEATS_EXCLUDE);
|
2020-09-26 15:55:24 +01:00
|
|
|
|
2021-09-11 14:48:13 +01:00
|
|
|
while (true) {
|
2020-09-26 15:55:24 +01:00
|
|
|
rc = nsListApplicationRecord(&record, sizeof(record), i, &recordCount);
|
|
|
|
if (R_FAILED(rc)) break;
|
|
|
|
|
2021-09-11 14:48:13 +01:00
|
|
|
if (recordCount <= 0)
|
2020-09-26 15:55:24 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
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-09-11 14:48:13 +01:00
|
|
|
if (!langEntry->name) {
|
2020-09-26 15:55:24 +01:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-11 14:48:13 +01:00
|
|
|
util::app* app = (util::app*)malloc(sizeof(util::app));
|
2020-09-26 15:55:24 +01:00
|
|
|
app->tid = tid;
|
|
|
|
|
|
|
|
memset(app->name, 0, sizeof(app->name));
|
2021-09-11 14:48:13 +01:00
|
|
|
strncpy(app->name, langEntry->name, sizeof(app->name) - 1);
|
2020-09-26 15:55:24 +01:00
|
|
|
|
|
|
|
memcpy(app->icon, controlData.icon, sizeof(app->icon));
|
|
|
|
|
2021-09-11 14:48:13 +01:00
|
|
|
brls::ToggleListItem* listItem;
|
|
|
|
if (titles.find(util::formatApplicationId(tid)) != titles.end())
|
2021-07-09 12:49:17 +01:00
|
|
|
listItem = new brls::ToggleListItem(std::string(app->name), 0);
|
2020-09-26 15:55:24 +01:00
|
|
|
else
|
2021-07-09 12:49:17 +01:00
|
|
|
listItem = new brls::ToggleListItem(std::string(app->name), 1);
|
2020-09-26 15:55:24 +01:00
|
|
|
|
|
|
|
listItem->setThumbnail(app->icon, sizeof(app->icon));
|
2021-03-16 02:04:21 +00:00
|
|
|
items.insert(std::make_pair(listItem, util::formatApplicationId(app->tid)));
|
2020-09-26 15:55:24 +01:00
|
|
|
list->addView(listItem);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2021-09-11 14:48:13 +01:00
|
|
|
list->registerAction("menus/cheats/exclude_titles_save"_i18n, brls::Key::B, [this] {
|
2021-03-16 02:04:21 +00:00
|
|
|
std::set<std::string> exclude;
|
|
|
|
for (const auto& item : items) {
|
2021-09-11 14:48:13 +01:00
|
|
|
if (!item.first->getToggleState()) {
|
2021-03-16 02:04:21 +00:00
|
|
|
exclude.insert(item.second);
|
2020-09-26 15:55:24 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-16 02:04:21 +00:00
|
|
|
extract::writeTitlesToFile(exclude, CHEATS_EXCLUDE);
|
2020-09-26 15:55:24 +01:00
|
|
|
brls::Application::popView();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
this->setContentView(list);
|
|
|
|
}
|