1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-08 11:31:43 +00:00

Added ability to view existing cheats when downloading cheat codes/sheets. Fixed wrong tid for theme detection.

This commit is contained in:
flb 2021-07-16 17:33:57 +02:00
parent 29238448bc
commit 13cc1ff4e2
8 changed files with 81 additions and 60 deletions

View file

@ -22,7 +22,7 @@ DATA := data
INCLUDES := include lib/zipper/include /lib/borealis/library/include/borealis/extern/nlohmann INCLUDES := include lib/zipper/include /lib/borealis/library/include/borealis/extern/nlohmann
APP_TITLE := All-in-One Switch Updater APP_TITLE := All-in-One Switch Updater
APP_AUTHOR := HamletDuFromage APP_AUTHOR := HamletDuFromage
APP_VERSION := 2.11.0 APP_VERSION := 2.11.1
TARGET := $(notdir $(CURDIR)) TARGET := $(notdir $(CURDIR))
ROMFS := resources ROMFS := resources

View file

@ -73,8 +73,6 @@ class AppPage_DownloadedCheats : public AppPage
void CreateLabel() override; void CreateLabel() override;
void DeclareGameListItem(const std::string& name, uint64_t tid, NsApplicationControlData **controlData) override; void DeclareGameListItem(const std::string& name, uint64_t tid, NsApplicationControlData **controlData) override;
void GetExistingCheatsTids(); void GetExistingCheatsTids();
void ShowCheatFiles(uint64_t tid, const std::string& name);
bool CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView);
public: public:
AppPage_DownloadedCheats(); AppPage_DownloadedCheats();

View file

@ -3,6 +3,14 @@
#include <borealis.hpp> #include <borealis.hpp>
#include <switch.h> #include <switch.h>
#include <json.hpp> #include <json.hpp>
#include <filesystem>
namespace show_cheats {
void ShowCheatFiles(uint64_t tid, const std::string& name);
bool CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView);
}
class DownloadCheatsPage : public brls::AppletFrame class DownloadCheatsPage : public brls::AppletFrame
{ {

View file

@ -42,7 +42,8 @@
"gbatemp_dl_successful_dl": "Successfully downloaded the following cheat code:\n{}", "gbatemp_dl_successful_dl": "Successfully downloaded the following cheat code:\n{}",
"applet_mode_not_supported": "Due to memory constraints, in applet mode you may only fetch cheat codes for the game you're currently playing. Please launch aio-switch-updater through title redirection to download cheat codes for any game you own.", "applet_mode_not_supported": "Due to memory constraints, in applet mode you may only fetch cheat codes for the game you're currently playing. Please launch aio-switch-updater through title redirection to download cheat codes for any game you own.",
"cheatfile_label": "Here are the cheat codes listed in file {}", "cheatfile_label": "Here are the cheat codes listed in file {}",
"not_found": "No proper cheat codes could be found for this game" "not_found": "No proper cheat codes could be found for this game",
"show_existing": "Show existing"
}, },
"common": { "common": {
"downloading": "Downloading...", "downloading": "Downloading...",

View file

@ -277,7 +277,7 @@ void AppPage_DownloadedCheats::CreateLabel()
void AppPage_DownloadedCheats::DeclareGameListItem(const std::string& name, u64 tid, NsApplicationControlData **controlData) void AppPage_DownloadedCheats::DeclareGameListItem(const std::string& name, u64 tid, NsApplicationControlData **controlData)
{ {
if (titles.find(util::formatApplicationId(tid)) != titles.end()) { if (titles.find(util::formatApplicationId(tid)) != titles.end()) {
listItem->getClickEvent()->subscribe([this, tid, name](brls::View* view) { ShowCheatFiles(tid, name); }); listItem->getClickEvent()->subscribe([this, tid, name](brls::View* view) { show_cheats::ShowCheatFiles(tid, name); });
AppPage::DeclareGameListItem(name, tid, controlData); AppPage::DeclareGameListItem(name, tid, controlData);
} }
} }
@ -297,53 +297,3 @@ void AppPage_DownloadedCheats::GetExistingCheatsTids() {
} }
} }
void AppPage_DownloadedCheats::ShowCheatFiles(u64 tid, const std::string& name) {
std::string path = util::getContentsPath();
path += util::formatApplicationId(tid) + "/cheats/";
brls::TabFrame* appView = new brls::TabFrame();
bool is_populated = false;
if(std::filesystem::exists(path)) {
for(const auto& cheatFile : std::filesystem::directory_iterator(path)){
is_populated |= CreateCheatList(cheatFile.path(), &appView);
}
}
if(is_populated) {
brls::PopupFrame::open(name, appView, "");
}
else {
brls::Dialog* dialog = new brls::Dialog("menus/cheats/not_found"_i18n);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/common/ok"_i18n, callback);
dialog->setCancelable(true);
dialog->open();
}
}
bool AppPage_DownloadedCheats::CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView) {
bool res = false;
brls::List* cheatsList = new brls::List();
if(extract::isBID(path.filename().stem())) {
cheatsList->addView(new brls::Label(brls::LabelStyle::DESCRIPTION, fmt::format("menus/cheats/cheatfile_label"_i18n, path.filename().string()), true));
std::string str;
std::regex cheats_expr(R"(\[.+\])");
std::ifstream in(path);
if(in) {
while (std::getline(in, str)) {
if(str.size() > 0) {
if(std::regex_search(str, cheats_expr)) {
cheatsList->addView(new brls::ListItem(str));
res = true;
}
}
}
}
}
if(res) {
(*appView)->addTab(util::upperCase(path.filename().stem()), cheatsList);
}
return res;
}

View file

@ -181,6 +181,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true)
verTitles.push_back("v2.11.0"); verTitles.push_back("v2.11.0");
changes.push_back("\uE016 Borealis changes for visual tweaks (tickering labels, scroll bar etc).\n\uE016 When needed, issue a warning about custom themes after downloading a new firmware.\n\uE016 Abort AMS update process for Mariko Switches when payload.bin cannot be found."); changes.push_back("\uE016 Borealis changes for visual tweaks (tickering labels, scroll bar etc).\n\uE016 When needed, issue a warning about custom themes after downloading a new firmware.\n\uE016 Abort AMS update process for Mariko Switches when payload.bin cannot be found.");
verTitles.push_back("v2.11.1");
changes.push_back("\uE016 Added ability to view existing cheats when downloading cheat codes/sheets.\n\uE016 Fixed wrong tid for theme detection.");
for(int i = verTitles.size() -1 ; i >= 0; i--){ for(int i = verTitles.size() -1 ; i >= 0; i--){
listItem = new brls::ListItem(verTitles[i]); listItem = new brls::ListItem(verTitles[i]);
change = changes[i]; change = changes[i];

View file

@ -12,13 +12,71 @@ namespace i18n = brls::i18n;
using namespace i18n::literals; using namespace i18n::literals;
using json = nlohmann::json; using json = nlohmann::json;
namespace show_cheats {
void ShowCheatFiles(u64 tid, const std::string& name) {
std::string path = util::getContentsPath();
path += util::formatApplicationId(tid) + "/cheats/";
brls::TabFrame* appView = new brls::TabFrame();
bool is_populated = false;
if(std::filesystem::exists(path)) {
for(const auto& cheatFile : std::filesystem::directory_iterator(path)){
is_populated |= CreateCheatList(cheatFile.path(), &appView);
}
}
if(is_populated) {
brls::PopupFrame::open(name, appView, "");
}
else {
brls::Dialog* dialog = new brls::Dialog("menus/cheats/not_found"_i18n);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/common/ok"_i18n, callback);
dialog->setCancelable(true);
dialog->open();
}
}
bool CreateCheatList(const std::filesystem::path& path, brls::TabFrame** appView) {
bool res = false;
brls::List* cheatsList = new brls::List();
if(extract::isBID(path.filename().stem())) {
cheatsList->addView(new brls::Label(brls::LabelStyle::DESCRIPTION, fmt::format("menus/cheats/cheatfile_label"_i18n, path.filename().string()), true));
std::string str;
std::regex cheats_expr(R"(\[.+\])");
std::ifstream in(path);
if(in) {
while (std::getline(in, str)) {
if(str.size() > 0) {
if(std::regex_search(str, cheats_expr)) {
cheatsList->addView(new brls::ListItem(str));
res = true;
}
}
}
}
}
if(res) {
(*appView)->addTab(util::upperCase(path.filename().stem()), cheatsList);
}
return res;
}
}
DownloadCheatsPage::DownloadCheatsPage(uint64_t tid, const std::string& name) : AppletFrame(true, true), tid(tid) DownloadCheatsPage::DownloadCheatsPage(uint64_t tid, const std::string& name) : AppletFrame(true, true), tid(tid)
{ {
list = new brls::List(); list = new brls::List();
GetVersion(); GetVersion();
GetBuildID(); GetBuildID();
this->setTitle(name); this->setTitle(name);
this->setFooterText("Game version: v" + std::to_string(this->version / 0x10000)); this->setFooterText("v" + std::to_string(this->version / 0x10000));
this->registerAction("menus/cheats/show_existing"_i18n , brls::Key::X, [this, tid, name] {
show_cheats::ShowCheatFiles(tid, name);
return true;
});
} }
void DownloadCheatsPage::GetBuildID() { void DownloadCheatsPage::GetBuildID() {

View file

@ -99,16 +99,19 @@ ListDownloadTab::ListDownloadTab(const archiveType type) :
new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type](){util::extractArchive(type);}) new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type](){util::extractArchive(type);})
); );
std::string doneMsg = "menus/common/all_done"_i18n; std::string doneMsg = "menus/common/all_done"_i18n;
std::string themePath; std::string contentsPath;
switch(type){ switch(type){
case archiveType::ams_cfw: case archiveType::ams_cfw:
case archiveType::app: case archiveType::app:
case archiveType::cfw: case archiveType::cfw:
case archiveType::cheats: case archiveType::cheats:
case archiveType::fw: case archiveType::fw:
themePath = util::getContentsPath() + "0100000000010000"; contentsPath = util::getContentsPath();
if(std::filesystem::exists(themePath) && !std::filesystem::is_empty(themePath)) { for (const auto& tid : {"0100000000001000", "0100000000001007", "0100000000001013"}) {
if(std::filesystem::exists(contentsPath + tid) && !std::filesystem::is_empty(contentsPath + tid)) {
doneMsg += "\n" + "menus/main/theme_warning"_i18n; doneMsg += "\n" + "menus/main/theme_warning"_i18n;
break;
}
} }
break; break;
case archiveType::sigpatches: case archiveType::sigpatches: