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

239 lines
9 KiB
C++
Raw Normal View History

2020-09-20 01:21:28 +01:00
#include "tools_tab.hpp"
2021-02-10 16:28:47 +00:00
#include "confirm_page.hpp"
#include "worker_page.hpp"
#include "cheats_page.hpp"
#include "payload_page.hpp"
#include "download_payload_page.hpp"
#include "changelog_page.hpp"
#include "JC_page.hpp"
#include "PC_page.hpp"
#include "net_page.hpp"
#include "extract.hpp"
#include "utils.hpp"
#include "hide_tabs_page.hpp"
2021-02-12 22:20:16 +00:00
#include "json.hpp"
2021-02-10 16:28:47 +00:00
#include <filesystem>
2021-02-12 22:20:16 +00:00
#include <fstream>
#include <iostream>
2021-01-28 19:26:41 +00:00
namespace i18n = brls::i18n;
using namespace i18n::literals;
2021-02-12 22:20:16 +00:00
using json = nlohmann::json;
ToolsTab::ToolsTab(std::string tag) : brls::List()
2020-09-20 01:21:28 +01:00
{
2021-02-12 22:20:16 +00:00
if(!tag.empty() && tag != APP_VERSION){
updateApp = new brls::ListItem("menus/tool_update"_i18n + tag +")");
std::string text("menus/tool_DownLoad"_i18n + std::string(APP_URL));
updateApp->getClickEvent()->subscribe([&, text, tag](brls::View* view) {
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle("menus/tool_updating"_i18n );
stagedFrame->addStage(
new ConfirmPage(stagedFrame, text)
);
stagedFrame->addStage(
new WorkerPage(stagedFrame, "menus/tool_downloading"_i18n , [](){downloadArchive(APP_URL, app);})
);
stagedFrame->addStage(
new WorkerPage(stagedFrame, "menus/tool_extracting"_i18n , [tag](){extractArchive(app, tag);})
);
stagedFrame->addStage(
new ConfirmPage(stagedFrame, "menus/tool_all_done"_i18n , true)
);
brls::Application::pushView(stagedFrame);
});
updateApp->setHeight(LISTITEM_HEIGHT);
this->addView(updateApp);
}
cheats = new brls::ListItem("menus/tool_cheats"_i18n );
cheats->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new CheatsPage());
2020-09-20 01:21:28 +01:00
});
2020-10-05 16:14:10 +01:00
cheats->setHeight(LISTITEM_HEIGHT);
this->addView(cheats);
2020-09-20 01:21:28 +01:00
JCcolor = new brls::ListItem("menus/tool_change"_i18n );
2020-09-20 01:21:28 +01:00
JCcolor->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new JCPage());
});
2020-10-05 16:14:10 +01:00
JCcolor->setHeight(LISTITEM_HEIGHT);
2020-09-20 01:21:28 +01:00
this->addView(JCcolor);
PCcolor = new brls::ListItem("menus/tool_change_procon"_i18n );
2020-12-28 18:28:58 +00:00
PCcolor->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new PCPage());
});
PCcolor->setHeight(LISTITEM_HEIGHT);
this->addView(PCcolor);
downloadPayload = new brls::ListItem("menus/tool_download"_i18n + std::string(BOOTLOADER_PL_PATH));
downloadPayload->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new DownloadPayloadPage());
});
2020-10-06 14:19:19 +01:00
downloadPayload->setHeight(LISTITEM_HEIGHT);
this->addView(downloadPayload);
rebootPayload = new brls::ListItem("menus/tool_inject"_i18n );
rebootPayload->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new PayloadPage());
});
2020-10-05 16:14:10 +01:00
rebootPayload->setHeight(LISTITEM_HEIGHT);
this->addView(rebootPayload);
/* ntcp = new brls::ListItem("menus/ntcp"_i18n );
ntcp->getClickEvent()->subscribe([&](brls::View* view){
std::string res = syncTime();
brls::Dialog* dialog = new brls::Dialog(res);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/Ok_button"_i18n , callback);
dialog->setCancelable(true);
dialog->open();
});
ntcp->setHeight(LISTITEM_HEIGHT);
this->addView(ntcp); */
netSettings = new brls::ListItem("menus/tool_net_settings"_i18n );
netSettings->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new NetPage());
});
netSettings->setHeight(LISTITEM_HEIGHT);
this->addView(netSettings);
browser = new brls::ListItem("menus/tool_browser"_i18n );
browser->getClickEvent()->subscribe([&](brls::View* view){
char url[0xc00] = {0};
SwkbdConfig kbd;
Result rc = swkbdCreate(&kbd, 0);
if (R_SUCCEEDED(rc)) {
swkbdConfigMakePresetDefault(&kbd);
swkbdConfigSetGuideText(&kbd, "www.cheatslips.com e-mail");
swkbdConfigSetInitialText(&kbd, "https://duckduckgo.com");
swkbdShow(&kbd, url, sizeof(url));
swkbdClose(&kbd);
}
else {
strcpy(url, "https://duckduckgo.com");
}
int at = appletGetAppletType();
std::string error = "";
if(at == AppletType_Application) { // Running as a title
WebCommonConfig conf;
WebCommonReply out;
rc = webPageCreate(&conf, url);
if (R_FAILED(rc))
error += "\uE016 Error starting Browser\n\uE016 Lookup error code for more info " + rc;
webConfigSetJsExtension(&conf, true);
webConfigSetPageCache(&conf, true);
webConfigSetBootLoadingIcon(&conf, true);
webConfigSetWhitelist(&conf, ".*");
rc = webConfigShow(&conf, &out);
if (R_FAILED(rc))
error += "\uE016 Error starting Browser\n\uE016 Lookup error code for more info " + rc;
} else { // Running under applet
error += "\uE016 Running in applet mode.\n\uE016 Please launch hbmenu by holding [R] on a game";
}
if(!error.empty()){
brls::Dialog* dialog = new brls::Dialog(error);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/Ok_button"_i18n , callback);
dialog->setCancelable(true);
dialog->open();
}
});
browser->setHeight(LISTITEM_HEIGHT);
this->addView(browser);
2021-02-12 22:20:16 +00:00
moveFiles = new brls::ListItem("menus/tool_copyFiles"_i18n );
moveFiles->getClickEvent()->subscribe([&](brls::View* view){
chdir("/");
std::string error = "";
if(std::filesystem::exists(MOVE_FILES_JSON)){
json toMove;
std::ifstream f(MOVE_FILES_JSON);
f >> toMove;
f.close();
for (auto it = toMove.begin(); it != toMove.end(); ++it) {
if(std::filesystem::exists(it.key())) {
createTree(std::string(std::filesystem::path(it.value().get<std::string>()).parent_path()) + "/");
cp(it.key().c_str(), it.value().get<std::string>().c_str());
}
else {
error += it.key() + "\n";
}
}
if(error == "") {
error = "menus/All_done"_i18n;
}
else {
error = "menus/files_not_found"_i18n + error;
}
}
else{
error = "menus/move_files_not_found"_i18n;
}
brls::Dialog* dialog = new brls::Dialog(error);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/Ok_button"_i18n , callback);
dialog->setCancelable(true);
dialog->open();
});
moveFiles->setHeight(LISTITEM_HEIGHT);
this->addView(moveFiles);
cleanUp = new brls::ListItem("menus/tool_cleanUp"_i18n );
cleanUp->getClickEvent()->subscribe([&](brls::View* view){
std::filesystem::remove(AMS_ZIP_PATH);
std::filesystem::remove(APP_ZIP_PATH);
std::filesystem::remove(CFW_ZIP_PATH);
std::filesystem::remove(FW_ZIP_PATH);
std::filesystem::remove(CHEATS_ZIP_PATH);
std::filesystem::remove(SIGPATCHES_ZIP_PATH);
std::filesystem::remove_all(AMS_DIRECTORY_PATH);
rmdir(AMS_DIRECTORY_PATH);
std::filesystem::remove_all(SEPT_DIRECTORY_PATH);
rmdir(SEPT_DIRECTORY_PATH);
std::filesystem::remove_all(FW_DIRECTORY_PATH);
rmdir(FW_DIRECTORY_PATH);
brls::Dialog* dialog = new brls::Dialog("menus/All_done"_i18n);
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
dialog->close();
};
dialog->addButton("menus/Ok_button"_i18n , callback);
dialog->setCancelable(true);
dialog->open();
});
cleanUp->setHeight(LISTITEM_HEIGHT);
this->addView(cleanUp);
hideTabs = new brls::ListItem("menus/hide_tabs"_i18n );
hideTabs->getClickEvent()->subscribe([&](brls::View* view) {
brls::Application::pushView(new HideTabsPage());
});
hideTabs->setHeight(LISTITEM_HEIGHT);
this->addView(hideTabs);
changelog = new brls::ListItem("menus/tool_changelog"_i18n );
changelog->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new ChangelogPage());
});
2020-10-05 16:14:10 +01:00
changelog->setHeight(LISTITEM_HEIGHT);
this->addView(changelog);
/* language = new brls::ListItem("menus/Language_Option"_i18n );
language->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new LanguageOptionPage());
});
2020-10-05 16:14:10 +01:00
language->setHeight(LISTITEM_HEIGHT);
this->addView(language); */
}