diff --git a/include/download_cheats_page.hpp b/include/download_cheats_page.hpp index 8e3e84c..4284b20 100644 --- a/include/download_cheats_page.hpp +++ b/include/download_cheats_page.hpp @@ -11,7 +11,6 @@ namespace show_cheats { void ShowCheatFiles(uint64_t tid, const std::string& name); void ShowCheatSheet(u64 tid, const std::string& bid, const std::string& name); bool CreateCheatList(const std::filesystem::path& path, brls::List** cheatsList); - void NoCheatsFoundPopup(); void DeleteCheats(u64 tid, const std::string& bid); } // namespace show_cheats diff --git a/include/utils.hpp b/include/utils.hpp index d0a23ca..08d6394 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -32,8 +32,9 @@ namespace util { std::vector fetchPayloads(); void shutDown(bool reboot = false); void rebootToPayload(const std::string& path); - int showDialogBox(const std::string& text, const std::string& opt); - int showDialogBox(const std::string& text, const std::string& opt1, const std::string& opt2); + void showDialogBoxInfo(const std::string& text); + int showDialogBoxBlocking(const std::string& text, const std::string& opt); + int showDialogBoxBlocking(const std::string& text, const std::string& opt1, const std::string& opt2); std::string getLatestTag(const std::string& url); std::string downloadFileToString(const std::string& url); std::string getCheatsVersion(); diff --git a/source/ams_tab.cpp b/source/ams_tab.cpp index c90e4ba..ea42110 100644 --- a/source/ams_tab.cpp +++ b/source/ams_tab.cpp @@ -180,14 +180,7 @@ void AmsTab::ShowCustomDeepseaBuilder(nlohmann::ordered_json& modules) } name_map.insert(std::pair(module_value.at("displayName"), module.key())); deepseaListItem->registerAction("menus/ams_update/show_module_description"_i18n, brls::Key::Y, [module_value] { - brls::Dialog* dialog; - dialog = new brls::Dialog(fmt::format("{}:\n{}", module_value.at("repo"), module_value.at("description"))); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(fmt::format("{}:\n{}", module_value.at("repo"), module_value.at("description"))); return true; }); list->addView(deepseaListItem); diff --git a/source/app_page.cpp b/source/app_page.cpp index 6cb55c3..35cb851 100644 --- a/source/app_page.cpp +++ b/source/app_page.cpp @@ -279,13 +279,7 @@ void AppPage_DownloadedCheats::DeclareGameListItem(const std::string& name, u64 if (titles.find(tid_str) != titles.end()) { listItem->getClickEvent()->subscribe([tid, name](brls::View* view) { show_cheats::ShowCheatFiles(tid, name); }); listItem->registerAction("menus/cheats/delete_cheats"_i18n, brls::Key::Y, [tid_str] { - brls::Dialog* dialog = new brls::Dialog(extract::removeCheatsDirectory(fmt::format("{}{}", util::getContentsPath(), tid_str)) ? "menus/common/all_done"_i18n : fmt::format("menus/cheats/deletion_error"_i18n, tid_str)); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(extract::removeCheatsDirectory(fmt::format("{}{}", util::getContentsPath(), tid_str)) ? "menus/common/all_done"_i18n : fmt::format("menus/cheats/deletion_error"_i18n, tid_str)); return true; }); AppPage::DeclareGameListItem(name, tid, controlData); diff --git a/source/changelog_page.cpp b/source/changelog_page.cpp index d2f30fe..f8b0bed 100644 --- a/source/changelog_page.cpp +++ b/source/changelog_page.cpp @@ -1,5 +1,7 @@ #include "changelog_page.hpp" +#include "utils.hpp" + namespace i18n = brls::i18n; using namespace i18n::literals; ChangelogPage::ChangelogPage() : AppletFrame(true, true) @@ -233,13 +235,7 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true) listItem = new brls::ListItem(verTitles[i]); change = changes[i]; listItem->getClickEvent()->subscribe([change](brls::View* view) { - brls::Dialog* dialog = new brls::Dialog(change); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(change); }); list->addView(listItem); } diff --git a/source/color_swapper.cpp b/source/color_swapper.cpp index 28e710d..d3f7faf 100644 --- a/source/color_swapper.cpp +++ b/source/color_swapper.cpp @@ -171,7 +171,7 @@ namespace JC { ProgressEvent::instance().setStep(1); int res = setColor(values); if (res != 0) { - util::showDialogBox("Could not change the Joy-Cons color. Make sure they're docked and try again.\nError :" + std::to_string(res), "Ok"); + util::showDialogBoxBlocking("Could not change the Joy-Cons color. Make sure they're docked and try again.\nError :" + std::to_string(res), "Ok"); } hiddbgExit(); hidsysExit(); @@ -329,7 +329,7 @@ namespace PC { ProgressEvent::instance().setStep(1); int res = setColor(values); if (res != 0) { - util::showDialogBox("Could not change the Pro-Con color. Make they're connected to P1. This feature may not work on unofficial controllers. \nError :" + std::to_string(res), "Ok"); + util::showDialogBoxBlocking("Could not change the Pro-Con color. Make they're connected to P1. This feature may not work on unofficial controllers. \nError :" + std::to_string(res), "Ok"); } hiddbgExit(); hidsysExit(); diff --git a/source/download_cheats_page.cpp b/source/download_cheats_page.cpp index 89075af..9f92cc9 100644 --- a/source/download_cheats_page.cpp +++ b/source/download_cheats_page.cpp @@ -25,19 +25,13 @@ namespace show_cheats { appView->setContentView(cheatsList); appView->registerAction("menus/cheats/delete_file"_i18n, brls::Key::X, [tid, bid] { DeleteCheats(tid, bid); - brls::Dialog* dialog = new brls::Dialog("menus/common/all_done"_i18n); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo("menus/common/all_done"_i18n); return true; }); brls::PopupFrame::open(name, appView, ""); } else { - NoCheatsFoundPopup(); + util::showDialogBoxInfo("menus/cheats/not_found"_i18n); } } @@ -61,21 +55,10 @@ namespace show_cheats { brls::PopupFrame::open(name, appView, ""); } else { - NoCheatsFoundPopup(); + util::showDialogBoxInfo("menus/cheats/not_found"_i18n); } } - void NoCheatsFoundPopup() - { - 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::List** cheatsList) { bool res = false; @@ -276,21 +259,16 @@ DownloadCheatsPage_CheatSlips::DownloadCheatsPage_CheatSlips(uint64_t tid, const } if (error != 0) { - brls::Dialog* dialog; + std::string error_message; switch (error) { case 1: - dialog = new brls::Dialog("menus/cheats/quota"_i18n); + error_message = "menus/cheats/quota"_i18n; break; case 2: - dialog = new brls::Dialog("menus/cheats/cheatslips_error"_i18n); + error_message = "menus/cheats/cheatslips_error"_i18n; break; } - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(error_message); } } if (error == 0) { @@ -361,13 +339,7 @@ DownloadCheatsPage_GbaTemp::DownloadCheatsPage_GbaTemp(uint64_t tid, const std:: this->listItem = new brls::ListItem(cheat.at("title")); listItem->registerAction("menus/cheats/gbatemp_dl_cheatcode"_i18n, brls::Key::A, [this, cheat] { WriteCheats(cheat.at("content")); - brls::Dialog* dialog = new brls::Dialog(fmt::format("menus/cheats/gbatemp_dl_successful_dl"_i18n, cheat.at("title"))); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(fmt::format("menus/cheats/gbatemp_dl_successful_dl"_i18n, cheat.at("title"))); return true; }); this->list->addView(listItem); diff --git a/source/extract.cpp b/source/extract.cpp index 5a8fc43..9a94540 100644 --- a/source/extract.cpp +++ b/source/extract.cpp @@ -80,7 +80,7 @@ namespace extract { unzipper.extractEntry(entry.name); if (entry.name.substr(0, 13) == "hekate_ctcaer") { fs::copyFile("/" + entry.name, UPDATE_BIN_PATH); - if (CurrentCfw::running_cfw == CFW::ams && util::showDialogBox(fmt::format("menus/utils/set_hekate_reboot_payload"_i18n, UPDATE_BIN_PATH, REBOOT_PAYLOAD_PATH), "menus/common/yes"_i18n, "menus/common/no"_i18n) == 0) { + if (CurrentCfw::running_cfw == CFW::ams && util::showDialogBoxBlocking(fmt::format("menus/utils/set_hekate_reboot_payload"_i18n, UPDATE_BIN_PATH, REBOOT_PAYLOAD_PATH), "menus/common/yes"_i18n, "menus/common/no"_i18n) == 0) { fs::copyFile(UPDATE_BIN_PATH, REBOOT_PAYLOAD_PATH); } } diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index 7971a69..5400fee 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -200,13 +200,7 @@ void ListDownloadTab::createCheatSlipItem() 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(); + util::showDialogBoxInfo("menus/cheats/cheatslips_wrong_id"_i18n + "\n" + "menus/cheats/kb_error"_i18n); return true; } } diff --git a/source/payload_page.cpp b/source/payload_page.cpp index 80b76ae..5158c30 100644 --- a/source/payload_page.cpp +++ b/source/payload_page.cpp @@ -57,13 +57,7 @@ void PayloadPage::RegisterCopyAction(brls::Key key, const std::string& payload_p std::string res = fs::copyFile(payload_path, payload_dest) ? fmt::format("menus/payloads/copy_success"_i18n, payload_path, payload_dest) : "Failed."; - brls::Dialog* dialog = new brls::Dialog(res); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(res); return true; }); } \ No newline at end of file diff --git a/source/tools_tab.cpp b/source/tools_tab.cpp index 35dd996..363a625 100644 --- a/source/tools_tab.cpp +++ b/source/tools_tab.cpp @@ -100,13 +100,7 @@ ToolsTab::ToolsTab(const std::string& tag, const nlohmann::ordered_json& payload error += "\uE016 Running in applet mode/through a forwarder.\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/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(error); } } }); @@ -122,13 +116,7 @@ ToolsTab::ToolsTab(const std::string& tag, const nlohmann::ordered_json& payload else { error = "menus/tools/batch_copy_config_not_found"_i18n; } - brls::Dialog* dialog = new brls::Dialog(error); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo(error); }); move->setHeight(LISTITEM_HEIGHT); @@ -144,13 +132,7 @@ ToolsTab::ToolsTab(const std::string& tag, const nlohmann::ordered_json& payload fs::removeDir(AMS_DIRECTORY_PATH); fs::removeDir(SEPT_DIRECTORY_PATH); fs::removeDir(FW_DIRECTORY_PATH); - brls::Dialog* dialog = new brls::Dialog("menus/common/all_done"_i18n); - brls::GenericEvent::Callback callback = [dialog](brls::View* view) { - dialog->close(); - }; - dialog->addButton("menus/common/ok"_i18n, callback); - dialog->setCancelable(true); - dialog->open(); + util::showDialogBoxInfo("menus/common/all_done"_i18n); }); cleanUp->setHeight(LISTITEM_HEIGHT); diff --git a/source/utils.cpp b/source/utils.cpp index 4a3b49f..77629ba 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -67,7 +67,19 @@ namespace util { ProgressEvent::instance().setStatusCode(status_code); } - int showDialogBox(const std::string& text, const std::string& opt) + void showDialogBoxInfo(const std::string& text) + { + brls::Dialog* dialog; + dialog = new brls::Dialog(text); + brls::GenericEvent::Callback callback = [dialog](brls::View* view) { + dialog->close(); + }; + dialog->addButton("menus/common/ok"_i18n, callback); + dialog->setCancelable(true); + dialog->open(); + } + + int showDialogBoxBlocking(const std::string& text, const std::string& opt) { int dialogResult = -1; int result = -1; @@ -86,7 +98,7 @@ namespace util { return result; } - int showDialogBox(const std::string& text, const std::string& opt1, const std::string& opt2) + int showDialogBoxBlocking(const std::string& text, const std::string& opt1, const std::string& opt2) { int dialogResult = -1; int result = -1; @@ -167,14 +179,14 @@ namespace util { brls::Application::quit(); break; case contentType::bootloaders: { - int overwriteInis = showDialogBox("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); + int overwriteInis = showDialogBoxBlocking("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); extract::extract(CFW_FILENAME, ROOT_PATH, overwriteInis); break; } case contentType::ams_cfw: { - int overwriteInis = showDialogBox("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); + int overwriteInis = showDialogBoxBlocking("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); usleep(800000); - int deleteContents = showDialogBox("menus/ams_update/delete_sysmodules_flags"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); + int deleteContents = showDialogBoxBlocking("menus/ams_update/delete_sysmodules_flags"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); if (deleteContents == 1) removeSysmodulesFlags(AMS_CONTENTS); extract::extract(AMS_FILENAME, ROOT_PATH, overwriteInis); @@ -273,7 +285,6 @@ namespace util { std::string readFile(const std::string& path) { - std::string text = ""; std::ifstream file(path); if (file.good()) {