From cf9ad1d51a1fd347bcd221b01f80433e6f395c71 Mon Sep 17 00:00:00 2001 From: flb Date: Mon, 27 Sep 2021 21:56:41 +0200 Subject: [PATCH] add payload downloads to bootloader tab --- include/constants.hpp | 5 +- include/download.hpp | 4 +- include/list_download_tab.hpp | 12 ++- include/utils.hpp | 6 +- resources/i18n/de/menus.json | 2 +- resources/i18n/en-US/menus.json | 2 +- resources/i18n/es/menus.json | 2 +- resources/i18n/fr/menus.json | 2 +- resources/i18n/it/menus.json | 2 +- resources/i18n/ja/menus.json | 2 +- resources/i18n/pl/menus.json | 2 +- resources/i18n/pt-BR/menus.json | 2 +- resources/i18n/zh-CN/menus.json | 2 +- resources/i18n/zh-TW/menus.json | 2 +- source/ams_tab.cpp | 8 +- source/app_page.cpp | 4 +- source/cheats_page.cpp | 2 +- source/download.cpp | 13 +-- source/download_payload_page.cpp | 2 +- source/extract.cpp | 18 ++-- source/list_download_tab.cpp | 162 ++++++++++++++++--------------- source/main_frame.cpp | 8 +- source/tools_tab.cpp | 4 +- source/utils.cpp | 37 ++++--- 24 files changed, 161 insertions(+), 144 deletions(-) diff --git a/include/constants.hpp b/include/constants.hpp index 0be044a..90b3402 100644 --- a/include/constants.hpp +++ b/include/constants.hpp @@ -103,7 +103,7 @@ constexpr const char HIDDEN_AIO_FILE[] = "/config/aio-switch-updater/.aio-switch constexpr const int LISTITEM_HEIGHT = 50; -enum class archiveType +enum class contentType { sigpatches, cheats, @@ -111,8 +111,11 @@ enum class archiveType app, bootloaders, ams_cfw, + payloads, }; +constexpr std::string_view contentTypeNames[7]{"sigpatches", "cheats", "firmwares", "app", "bootloaders", "cfws", "payloads"}; + enum class CFW { rnx, diff --git a/include/download.hpp b/include/download.hpp index 236de40..67ead7a 100644 --- a/include/download.hpp +++ b/include/download.hpp @@ -7,8 +7,8 @@ constexpr int OFF = 0; namespace download { - long downloadFile(const std::string& url, std::vector& res, const char* output = "", int api = OFF); - long downloadFile(const std::string& url, const char* output = "", int api = OFF); + long downloadFile(const std::string& url, std::vector& res, const std::string& output = "", int api = OFF); + long downloadFile(const std::string& url, const std::string& output = "", int api = OFF); std::vector> getLinks(const std::string& url); std::vector> getLinksFromJson(const nlohmann::ordered_json& json_object); std::string fetchTitle(const std::string& url); diff --git a/include/list_download_tab.hpp b/include/list_download_tab.hpp index a1eec3a..bbb3c69 100644 --- a/include/list_download_tab.hpp +++ b/include/list_download_tab.hpp @@ -11,14 +11,18 @@ private: brls::ListItem* listItem; brls::ListItem* cheatslipsItem; brls::ListItem* gbatempItem; - brls::Label* notFound; - brls::Label* description; - brls::Label* cheatsLabel; + nlohmann::ordered_json nxlinks; + std::string currentCheatsVer = ""; + std::string newCheatsVer = ""; + contentType type; int size = 0; + void createList(contentType type); void createCheatSlipItem(); void creategbatempItem(); + void setDescription(); + void displayNotFound(); public: - ListDownloadTab(const archiveType type, const nlohmann::ordered_json& nxlinks = nlohmann::ordered_json::object()); + ListDownloadTab(const contentType type, const nlohmann::ordered_json& nxlinks = nlohmann::ordered_json::object()); brls::View* getDefaultFocus() override; }; \ No newline at end of file diff --git a/include/utils.hpp b/include/utils.hpp index 259875f..4d306ea 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -24,9 +24,9 @@ namespace util { void clearConsole(); bool isArchive(const std::string& path); - void downloadArchive(const std::string& url, archiveType type); - void downloadArchive(const std::string& url, archiveType type, long& status_code); - void extractArchive(archiveType type, const std::string& tag = "0"); + void downloadArchive(const std::string& url, contentType type); + void downloadArchive(const std::string& url, contentType type, long& status_code); + void extractArchive(contentType type, const std::string& tag = "0"); std::string formatListItemTitle(const std::string& str, size_t maxScore = 140); std::string formatApplicationId(u64 ApplicationId); std::vector fetchPayloads(); diff --git a/resources/i18n/de/menus.json b/resources/i18n/de/menus.json index 1247270..b25e41e 100644 --- a/resources/i18n/de/menus.json +++ b/resources/i18n/de/menus.json @@ -89,7 +89,7 @@ "all_done": "Fertig! Du musst dn Pro Controler vielleicht trennen und anschließen um den Effekt zu sehen." }, "main": { - "getting": "Herunterladen: ", + "getting": "Herunterladen: {}", "firmware_text": "\ue016 firmware von: 'https://darthsternie.net/switch-firmwares/'. Sobald runtergeladen, wird sie in '/firmware' entpackt . Danach kannst du das Update mit Daybreak installieren.\n\ue016 Mometnane FW: ", "cheats_text": "\uE016 Lade ein täglich geupdatetes Archiv von 'gbatemp.net' runter. Cheats von Spielen die du nicht besitzt, werden nicht entpackt. Du kannst updates für ausgewählte Spiele unter 'Tools->Cheat menu' deaktivieren.\n\uE016 Momentane Cheatversion: ", "get_cheats": "Lade GBAtemp.net Cheatarchiv herunter (ver ", diff --git a/resources/i18n/en-US/menus.json b/resources/i18n/en-US/menus.json index 0250a21..9579f63 100644 --- a/resources/i18n/en-US/menus.json +++ b/resources/i18n/en-US/menus.json @@ -105,7 +105,7 @@ "changing": "Changing color. Make sure the Pro-Con is set to player 1." }, "main": { - "getting": "Getting ", + "getting": "Getting {}", "firmware_text": "\ue016 Firmware dumps from 'https://darthsternie.net/switch-firmwares/'. Once downloaded, it will be extracted in '/firmware'. You can then install the update through Daybreak.\n\ue016 Current FW: ", "cheats_text": "\uE016 This will download a daily updated archive of cheat codes from 'gbatemp.net'. Cheat codes for games you don't have installed won't be extracted to your SD card. You can turn off cheat updates for specific games in 'Tools->Cheat menu'.\n\uE016 Current cheats version: ", "get_cheats": "Download GBAtemp.net cheat archive (ver ", diff --git a/resources/i18n/es/menus.json b/resources/i18n/es/menus.json index e0ce130..df84cef 100644 --- a/resources/i18n/es/menus.json +++ b/resources/i18n/es/menus.json @@ -60,7 +60,7 @@ "all_done": "¡Finalizado! Puede que necesites desacoplar y acoplar tus Joy-Cons para que el cambio surta efecto." }, "main": { - "getting": "Obteniendo ", + "getting": "Obteniendo {}", "firmware_text": "\ue016 Firmwares de 'https://darthsternie.net/switch-firmwares/'. Una vez descargado, será extraído en '/firmware'. Entonces podrás instalar la actualización a través de Daybreak.\n\ue016 FW actual: ", "cheats_text": "\ue016 Esto descargará un paquete actualizado diario de trucos de 'gbatemp.net'. Los trucos de juegos que no tienes instalados no se extraerán a tu tarjeta SD. Puedes desactivar los trucos actualizados en 'Herramientas->Menú de trucos'.\n\ue016 Versión de trucos actual: ", "sigpatches": "sigpatches", diff --git a/resources/i18n/fr/menus.json b/resources/i18n/fr/menus.json index 96609a9..6c228d0 100644 --- a/resources/i18n/fr/menus.json +++ b/resources/i18n/fr/menus.json @@ -60,7 +60,7 @@ "all_done": "Fini ! Vous devrez peut-être ancrer/détacher votre Joy-Cons pour que le changement prenne effet" }, "main": { - "getting": "Téléchargement du ", + "getting": "Téléchargement de {}", "firmware_text": "\ue016 Firmware depuis 'https://darthsternie.net/switch-firmwares/'. Une fois téléchargés, ils seront dans '/firmware'. Vous pouvez ensuite les installer avec Daybreak.\n\ue016 FW actuel : ", "cheats_text": "\ue016 Archive mise à jour quotidiennement des codes de triche de 'gbatemp.net'. Les codes de triche pour les jeux que vous ne possedez pas ne seront pas extraits sur votre carte SD. Vous pouvez désactiver les mises à jour pour pour une sélection de jeux dans le menu 'Outils->Menu de cheat'.\n\ue016 Version actuelle des cheats : ", "sigpatches": "sigpatches", diff --git a/resources/i18n/it/menus.json b/resources/i18n/it/menus.json index f0b81f6..fa823ae 100644 --- a/resources/i18n/it/menus.json +++ b/resources/i18n/it/menus.json @@ -60,7 +60,7 @@ "all_done": "Finito! Potrebbe essere necessario scollegare/collegare i Joy-Cons perchè i cambiamenti abbiano effetto." }, "main": { - "getting": "Ottengo ", + "getting": "Ottengo {}", "firmware_text": "\ue016 il dump del Firmware da 'https://darthsternie.net/switch-firmwares/'. Una volta scaricato, sarà estratto in '/firmware'. Puoi installare l'aggiornamento tramite Daybreak.\n\ue016 FW attuale: ", "cheats_text": "\ue016 Questo scaricherà quotidianamente un archivio di cheat da 'gbatemp.net'. I cheat per i giochi non installati non saranno estratti sulla tua scheda SD. Puoi disabilitare l'aggiornamento dei cheat in 'Tools->Cheat menu'.\n\ue016 Current cheats version: ", "sigpatches": "sigpatches", diff --git a/resources/i18n/ja/menus.json b/resources/i18n/ja/menus.json index f0d1905..5ac097c 100644 --- a/resources/i18n/ja/menus.json +++ b/resources/i18n/ja/menus.json @@ -102,7 +102,7 @@ "changing": "色を変える。 プロコントローラーがプレーヤー1に設定されていることを確認してください。" }, "main": { - "getting": "取得中 ", + "getting": "取得中 {}", "firmware_text": "\ue016 ファームウェアは'https://darthsternie.net/switch-firmwares/'からダンプされます。 ダウンロードすると、「/firmware」に抽出されます。その後、Daybreakを介してアップデートをインストールできます。\n\ue016 現在のファームウェア: ", "cheats_text": "Download GBAtemp.net チートアーカイブ (ver ", "get_cheats": "GBAtemp.netチートアーカイブをダウンロード (ver ", diff --git a/resources/i18n/pl/menus.json b/resources/i18n/pl/menus.json index 8b06369..b4e03c6 100644 --- a/resources/i18n/pl/menus.json +++ b/resources/i18n/pl/menus.json @@ -90,7 +90,7 @@ "changing": "Zmieniam kolor. Upewnij się, że kontroler jest podłączony jako Player 1." }, "main": { - "getting": "Pobieranie ", + "getting": "Pobieranie {}", "firmware_text": "\ue016 Oprogramowanie z 'https://darthsternie.net/switch-firmwares/'. Po pobraniu zostanie rozpakowane do '/firmware'. Możesz je później zainstalować korzystając z Daybreak.\n\ue016 Bieżący FW: ", "cheats_text": "\uE016 Pobierze aktualizowaną codziennie paczkę cheatów z 'gbatemp.net'. Cheaty dla gier których nie masz zainstalowanych nie zostaną wypakowane na twoją kartę SD. Możesz wyłączyć aktualizację cheatów dla poszczególnych gier w 'Narzędzia->Menu cheatów'.\n\uE016 Bieżąca wersja cheatów: ", "get_cheats": "Pobierz archiwum cheatów GBAtemp.net (wersja ", diff --git a/resources/i18n/pt-BR/menus.json b/resources/i18n/pt-BR/menus.json index 1164eb3..79e4ce1 100644 --- a/resources/i18n/pt-BR/menus.json +++ b/resources/i18n/pt-BR/menus.json @@ -60,7 +60,7 @@ "all_done": "Finalizado! Pode ser necessário desencaixar e encaixar o Joy-Cons para que a alteração tenha efeito." }, "main": { - "getting": "Baixando ", + "getting": "Baixando {}", "firmware_text": "\ue016 Firmwares de 'https://darthsternie.net/switch-firmwares/'. Depois de baixado, ele será extraído para '/firmware'. Você pode então instalar a atualização por meio do Daybreak ou.\n\ue016 FW atual: ", "cheats_text": "\ue016 Isso irá baixar um pacote de cheat atualizado diariamente do 'gbatemp.net'. Os cheats do jogo que você não instalou não serão extraídos para o seu cartão SD. Você pode desabilitar cheats atualizados em 'Ferramentas->Trapaças'.\n\ue016 Versão das trapaças atual: ", "sigpatches": "sigpatches", diff --git a/resources/i18n/zh-CN/menus.json b/resources/i18n/zh-CN/menus.json index 1a0d01c..0dd72cb 100644 --- a/resources/i18n/zh-CN/menus.json +++ b/resources/i18n/zh-CN/menus.json @@ -62,7 +62,7 @@ "all_done": "完成,你可能需要拔插手柄来启动刚才的颜色更新" }, "main": { - "getting": "获取 ", + "getting": "获取 {}", "firmware_text": "\ue016 固件从 'https://darthsternie.net/switch-firmwares/ 下载'. 下载之后,文件会被解压到 '/firmware'. 您可以使用 Daybreak 来安装它 .\n\ue016 当前FW版本: ", "cheats_text": "\ue016 这个金手指的下载和更新地址是 'gbatemp.net'. 你的机器中没有的游戏,这些金手指不会解压到你的SD卡中 你可以在'工具->金手指菜单' 关闭金手指更新.\n\ue016 当前金手指版本: ", "sigpatches": "数字签名", diff --git a/resources/i18n/zh-TW/menus.json b/resources/i18n/zh-TW/menus.json index 0f116e9..974465a 100644 --- a/resources/i18n/zh-TW/menus.json +++ b/resources/i18n/zh-TW/menus.json @@ -103,7 +103,7 @@ "changing": "正在變更控制器顏色,請確認Pro-Con的玩家指示燈顯示為第一位玩家" }, "main": { - "getting": "正在擷取 ", + "getting": "正在擷取 {}", "firmware_text": "\ue016 韌體檔案從'https://darthsternie.net/switch-firmwares/'進行轉存。當下載完成後,檔案會放置於資料夾'/firmware'內。你可以透過Daybreak來安裝更新韌體。\n\ue016 目前FW: ", "cheats_text": "\uE016 下載'gbatemp.net'每日更新的金手指檔案到記憶卡時,並不會複製到主機未安裝的遊戲金手指檔案。你可以從設定的 '工具->金手指選單' 內停用金手指更新。\n\uE016 目前金手指資料庫版本: ", "get_cheats:": "下載GBAtemp.net金手指資料庫(版本 ", diff --git a/source/ams_tab.cpp b/source/ams_tab.cpp index 18d461a..62e6c6e 100644 --- a/source/ams_tab.cpp +++ b/source/ams_tab.cpp @@ -100,16 +100,16 @@ void AmsTab::CreateStagedFrames(const std::string& text, const std::string& url, stagedFrame->addStage( new ConfirmPage(stagedFrame, text)); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url]() { util::downloadArchive(url, archiveType::ams_cfw); })); + new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url]() { util::downloadArchive(url, contentType::ams_cfw); })); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(archiveType::ams_cfw); })); + new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(contentType::ams_cfw); })); if (hekate) { stagedFrame->addStage( new DialoguePage_ams(stagedFrame, text_hekate, erista)); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [hekate_url]() { util::downloadArchive(hekate_url, archiveType::bootloaders); })); + new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [hekate_url]() { util::downloadArchive(hekate_url, contentType::bootloaders); })); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(archiveType::bootloaders); })); + new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(contentType::bootloaders); })); } stagedFrame->addStage( new ConfirmPage(stagedFrame, "menus/ams_update/reboot_rcm"_i18n, false, true, erista)); diff --git a/source/app_page.cpp b/source/app_page.cpp index 027a94b..eaac9dd 100644 --- a/source/app_page.cpp +++ b/source/app_page.cpp @@ -90,9 +90,9 @@ void AppPage::CreateDownloadAllButton() stagedFrame->addStage( new ConfirmPage(stagedFrame, text)); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url]() { util::downloadArchive(url, archiveType::cheats); })); + new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url]() { util::downloadArchive(url, contentType::cheats); })); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(archiveType::cheats); })); + new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { util::extractArchive(contentType::cheats); })); stagedFrame->addStage( new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); brls::Application::pushView(stagedFrame); diff --git a/source/cheats_page.cpp b/source/cheats_page.cpp index ca8dcd1..e81550f 100644 --- a/source/cheats_page.cpp +++ b/source/cheats_page.cpp @@ -63,7 +63,7 @@ CheatsPage::CheatsPage() : AppletFrame(true, true) stagedFrame->addStage( new ConfirmPage(stagedFrame, text)); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url]() { util::downloadArchive(url, archiveType::cheats); })); + new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url]() { util::downloadArchive(url, contentType::cheats); })); stagedFrame->addStage( new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, []() { extract::extractAllCheats(CHEATS_ZIP_PATH, CurrentCfw::running_cfw); })); stagedFrame->addStage( diff --git a/source/download.cpp b/source/download.cpp index dd6d578..0192f45 100644 --- a/source/download.cpp +++ b/source/download.cpp @@ -127,14 +127,15 @@ namespace download { } } // namespace - long downloadFile(const std::string& url, const char* output, int api) + long downloadFile(const std::string& url, const std::string& output, int api) { std::vector dummy; return downloadFile(url, dummy, output, api); } - long downloadFile(const std::string& url, std::vector& res, const char* output, int api) + long downloadFile(const std::string& url, std::vector& res, const std::string& output, int api) { + const char* out = output.c_str(); CURL* curl = curl_easy_init(); ntwrk_struct_t chunk = {0}; long status_code; @@ -143,13 +144,13 @@ namespace download { bool can_download = true; if (curl) { - FILE* fp = fopen(output, "wb"); - if (fp || *output == 0) { + FILE* fp = fopen(out, "wb"); + if (fp || *out == 0) { chunk.data = static_cast(malloc(_1MiB)); chunk.data_size = _1MiB; chunk.out = fp; - if (*output != 0) { + if (*out != 0) { can_download = checkSize(curl, url); } @@ -187,7 +188,7 @@ namespace download { res = {}; } - if (*output == 0) { + if (*out == 0) { res.assign(chunk.data, chunk.data + chunk.offset); } diff --git a/source/download_payload_page.cpp b/source/download_payload_page.cpp index 2ed49d2..c725e25 100644 --- a/source/download_payload_page.cpp +++ b/source/download_payload_page.cpp @@ -32,7 +32,7 @@ DownloadPayloadPage::DownloadPayloadPage(const nlohmann::ordered_json& payloads) stagedFrame->addStage( new ConfirmPage(stagedFrame, text)); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, path]() { download::downloadFile(url, path.c_str(), OFF); })); + new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, path]() { download::downloadFile(url, path, OFF); })); stagedFrame->addStage( new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); brls::Application::pushView(stagedFrame); diff --git a/source/extract.cpp b/source/extract.cpp index 7a9a3c1..5a50f95 100644 --- a/source/extract.cpp +++ b/source/extract.cpp @@ -27,7 +27,7 @@ namespace extract { namespace { bool caselessCompare(const std::string& a, const std::string& b) { - return strcasecmp(a.c_str(), b.c_str()) < 0; + return strcasecmp(a.c_str(), b.c_str()) == 0; } void preWork(zipper::Unzipper& unzipper, const std::string& workingPath, std::vector& entries) @@ -79,6 +79,7 @@ namespace extract { unzipper.extractEntry(entry.name); if (entry.name.substr(0, 13) == "hekate_ctcaer") { fs::copyFile("/" + entry.name, UPDATE_BIN_PATH); + fs::copyFile("/" + entry.name, REBOOT_PAYLOAD_PATH); } } ProgressEvent::instance().incrementStep(1); @@ -217,7 +218,7 @@ namespace extract { break; } auto matches = entries | std::views::filter([&title, offset](zipper::ZipEntry entry) { - return strcasecmp((title.substr(0, 13)).c_str(), entry.name.substr(offset, 13).c_str()) == 0 && strcasecmp(entry.name.substr(offset + 16, 7).c_str(), "/cheats") == 0; + return caselessCompare((title.substr(0, 13)), entry.name.substr(offset, 13)) && caselessCompare(entry.name.substr(offset + 16, 7), "/cheats"); }); for (const auto& match : matches) { unzipper.extractEntry(match.name); @@ -275,7 +276,7 @@ namespace extract { void removeCheats() { std::string path = util::getContentsPath(); - ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator())); + ProgressEvent::instance().setTotalSteps(std::distance(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator()) + 1); for (const auto& entry : std::filesystem::directory_iterator(path)) { if (ProgressEvent::instance().getInterupt()) { break; @@ -291,14 +292,9 @@ namespace extract { { bool res = true; std::string cheatsPath = fmt::format("{}/cheats", entry); - if (std::filesystem::exists(cheatsPath)) { - res &= fs::removeDir(cheatsPath); - if (std::filesystem::is_empty(entry)) { - res &= fs::removeDir(entry); - } - return res; - } - return false; + if (std::filesystem::exists(cheatsPath)) res &= fs::removeDir(cheatsPath); + if (std::filesystem::is_empty(entry)) res &= fs::removeDir(entry); + return res; } } // namespace extract \ No newline at end of file diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index ee7b541..41c9ddd 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -17,84 +17,67 @@ namespace i18n = brls::i18n; using namespace i18n::literals; -ListDownloadTab::ListDownloadTab(const archiveType type, const nlohmann::ordered_json& nxlinks) : brls::List() +ListDownloadTab::ListDownloadTab(const contentType type, const nlohmann::ordered_json& nxlinks) : brls::List(), type(type), nxlinks(nxlinks) { - //std::vector> links, sxoslinks; - std::vector> links = download::getLinksFromJson(nxlinks); - std::string operation("menus/main/getting"_i18n); - std::string firmwareText("menus/main/firmware_text"_i18n); + this->setDescription(); - std::string currentCheatsVer = ""; - std::string newCheatsVer = ""; + this->createList(this->type); - this->description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true); - switch (type) { - case archiveType::sigpatches: - operation += "menus/main/sigpatches"_i18n; - this->description->setText( - "menus/main/sigpatches_text"_i18n); - break; - case archiveType::fw: - operation += "menus/main/firmware"_i18n; - SetSysFirmwareVersion ver; - if (R_SUCCEEDED(setsysGetFirmwareVersion(&ver))) - firmwareText += ver.display_version; - else - firmwareText += "menus/main/not_found"_i18n; - this->description->setText(firmwareText); - break; - case archiveType::app: - links.push_back(std::make_pair("menus/main/latest_cheats"_i18n, APP_URL)); - operation += "menus/main/app"_i18n; - break; - case archiveType::bootloaders: - operation += "menus/main/cfw"_i18n; - this->description->setText( - "menus/main/bootloaders_text"_i18n); - break; - case archiveType::cheats: - newCheatsVer = util::downloadFileToString(CHEATS_URL_VERSION); - if (newCheatsVer != "") { - switch (CurrentCfw::running_cfw) { - case CFW::sxos: - links.push_back(std::make_pair("menus/main/get_cheats"_i18n + newCheatsVer + ")", CHEATS_URL_TITLES)); - break; - case CFW::ams: - links.push_back(std::make_pair("menus/main/get_cheats"_i18n + newCheatsVer + ")", CHEATS_URL_CONTENTS)); - break; - case CFW::rnx: - links.push_back(std::make_pair("menus/main/get_cheats"_i18n + newCheatsVer + ")", CHEATS_URL_CONTENTS)); - break; - } - } - operation += "menus/main/cheats"_i18n; - currentCheatsVer = util::readVersion(CHEATS_VERSION); - this->description->setText("menus/main/cheats_text"_i18n + currentCheatsVer); - break; - default: - break; + if (this->type == contentType::cheats) { + brls::Label* cheatsLabel = new brls::Label( + brls::LabelStyle::DESCRIPTION, + "menus/cheats/cheats_label"_i18n, + true); + this->addView(cheatsLabel); + creategbatempItem(); + createCheatSlipItem(); } - this->addView(description); + if (this->type == contentType::bootloaders) { + brls::Label* payloadsLabel = new brls::Label( + brls::LabelStyle::DESCRIPTION, + "menus/cheats/cheats_label"_i18n, + true); + this->addView(payloadsLabel); + createList(contentType::payloads); + } +} + +void ListDownloadTab::createList(contentType type) +{ + std::vector> links; + if (this->type == contentType::cheats && this->newCheatsVer != "") + links.push_back(std::make_pair(fmt::format("{}{})", "menus/main/get_cheats"_i18n, this->newCheatsVer), CurrentCfw::running_cfw == CFW::sxos ? CHEATS_URL_TITLES : CHEATS_URL_CONTENTS)); + else + links = download::getLinksFromJson(util::getValueFromKey(this->nxlinks, contentTypeNames[(int)type].data())); this->size = links.size(); if (this->size) { for (const auto& link : links) { + std::string title = link.first; std::string url = link.second; std::string text("menus/common/download"_i18n + link.first + "menus/common/from"_i18n + url); listItem = new brls::ListItem(link.first); listItem->setHeight(LISTITEM_HEIGHT); - listItem->getClickEvent()->subscribe([&, text, url, type, operation, newCheatsVer, currentCheatsVer](brls::View* view) { + listItem->getClickEvent()->subscribe([&, text, url, title, type](brls::View* view) { brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); - stagedFrame->setTitle(operation); + stagedFrame->setTitle(fmt::format("menus/main/getting"_i18n, contentTypeNames[(int)type].data())); stagedFrame->addStage(new ConfirmPage(stagedFrame, text)); - if (type != archiveType::cheats || newCheatsVer != currentCheatsVer || !std::filesystem::exists(CHEATS_ZIP_PATH)) { - stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, type]() { util::downloadArchive(url, type); })); + if (type != contentType::payloads || type != contentType::cheats || this->newCheatsVer != this->currentCheatsVer || !std::filesystem::exists(CHEATS_ZIP_PATH)) { + stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [type, url]() { util::downloadArchive(url, type); })); + } + if (type == contentType::payloads) { + fs::createTree(BOOTLOADER_PL_PATH); + std::string path = std::string(BOOTLOADER_PL_PATH) + title; + // TODO figure out why this doesn't work lol + stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, path]() { download::downloadFile(url, path, OFF); })); + } + else { + stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type]() { util::extractArchive(type); })); } - stagedFrame->addStage(new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [type]() { util::extractArchive(type); })); std::string doneMsg = "menus/common/all_done"_i18n; switch (type) { - case archiveType::fw: { + case contentType::fw: { std::string contentsPath = util::getContentsPath(); for (const auto& tid : {"0100000000001000", "0100000000001007", "0100000000001013"}) { if (std::filesystem::exists(contentsPath + tid) && !std::filesystem::is_empty(contentsPath + tid)) { @@ -110,7 +93,7 @@ ListDownloadTab::ListDownloadTab(const archiveType type, const nlohmann::ordered } break; } - case archiveType::sigpatches: + case contentType::sigpatches: doneMsg += "\n" + "menus/sigpatches/reboot"_i18n; stagedFrame->addStage(new ConfirmPage(stagedFrame, doneMsg, true)); break; @@ -123,25 +106,50 @@ ListDownloadTab::ListDownloadTab(const archiveType type, const nlohmann::ordered this->addView(listItem); } } - else { - notFound = new brls::Label( - brls::LabelStyle::SMALL, - "menus/main/links_not_found"_i18n, - true); - notFound->setHorizontalAlign(NVG_ALIGN_CENTER); - this->addView(notFound); + this->displayNotFound(); + } +} + +void ListDownloadTab::displayNotFound() +{ + brls::Label* notFound = new brls::Label( + brls::LabelStyle::SMALL, + "menus/main/links_not_found"_i18n, + true); + notFound->setHorizontalAlign(NVG_ALIGN_CENTER); + this->addView(notFound); +} + +void ListDownloadTab::setDescription() +{ + brls::Label* description = new brls::Label(brls::LabelStyle::DESCRIPTION, "", true); + + switch (this->type) { + case contentType::sigpatches: + description->setText( + "menus/main/sigpatches_text"_i18n); + break; + case contentType::fw: { + SetSysFirmwareVersion ver; + description->setText(fmt::format("{}{}", "menus/main/firmware_text"_i18n, R_SUCCEEDED(setsysGetFirmwareVersion(&ver)) ? ver.display_version : "menus/main/not_found"_i18n)); + break; + } + case contentType::bootloaders: + description->setText( + "menus/main/bootloaders_text"_i18n); + break; + case contentType::cheats: + + this->newCheatsVer = util::downloadFileToString(CHEATS_URL_VERSION); + this->currentCheatsVer = util::readVersion(CHEATS_VERSION); + description->setText("menus/main/cheats_text"_i18n + this->currentCheatsVer); + break; + default: + break; } - if (type == archiveType::cheats) { - cheatsLabel = new brls::Label( - brls::LabelStyle::DESCRIPTION, - "menus/cheats/cheats_label"_i18n, - true); - this->addView(cheatsLabel); - creategbatempItem(); - createCheatSlipItem(); - } + this->addView(description); } void ListDownloadTab::createCheatSlipItem() diff --git a/source/main_frame.cpp b/source/main_frame.cpp index 49583ae..de26e9c 100644 --- a/source/main_frame.cpp +++ b/source/main_frame.cpp @@ -44,16 +44,16 @@ MainFrame::MainFrame() : TabFrame() this->addTab("menus/main/update_ams"_i18n, new AmsTab(nxlinks, erista, util::getBoolValue(hideStatus, "atmosphereentries"))); if (!util::getBoolValue(hideStatus, "cfw")) - this->addTab("menus/main/update_bootloaders"_i18n, new ListDownloadTab(archiveType::bootloaders, util::getValueFromKey(nxlinks, "bootloaders"))); + this->addTab("menus/main/update_bootloaders"_i18n, new ListDownloadTab(contentType::bootloaders, nxlinks)); if (!util::getBoolValue(hideStatus, "sigpatches")) - this->addTab("menus/main/update_sigpatches"_i18n, new ListDownloadTab(archiveType::sigpatches, util::getValueFromKey(nxlinks, "sigpatches"))); + this->addTab("menus/main/update_sigpatches"_i18n, new ListDownloadTab(contentType::sigpatches, nxlinks)); if (!util::getBoolValue(hideStatus, "firmwares")) - this->addTab("menus/main/download_firmware"_i18n, new ListDownloadTab(archiveType::fw, util::getValueFromKey(nxlinks, "firmwares"))); + this->addTab("menus/main/download_firmware"_i18n, new ListDownloadTab(contentType::fw, nxlinks)); if (!util::getBoolValue(hideStatus, "cheats")) - this->addTab("menus/main/download_cheats"_i18n, new ListDownloadTab(archiveType::cheats)); + this->addTab("menus/main/download_cheats"_i18n, new ListDownloadTab(contentType::cheats)); if (!util::getBoolValue(hideStatus, "tools")) this->addTab("menus/main/tools"_i18n, new ToolsTab(tag, util::getValueFromKey(nxlinks, "payloads"), erista, hideStatus)); diff --git a/source/tools_tab.cpp b/source/tools_tab.cpp index 1e4a643..1a3cc75 100644 --- a/source/tools_tab.cpp +++ b/source/tools_tab.cpp @@ -36,9 +36,9 @@ ToolsTab::ToolsTab(const std::string& tag, const nlohmann::ordered_json& payload stagedFrame->addStage( new ConfirmPage(stagedFrame, text)); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, []() { util::downloadArchive(APP_URL, archiveType::app); })); + new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, []() { util::downloadArchive(APP_URL, contentType::app); })); stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [tag]() { util::extractArchive(archiveType::app, tag); })); + new WorkerPage(stagedFrame, "menus/common/extracting"_i18n, [tag]() { util::extractArchive(contentType::app, tag); })); stagedFrame->addStage( new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true)); brls::Application::pushView(stagedFrame); diff --git a/source/utils.cpp b/source/utils.cpp index e8f0bf5..2145ae4 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -30,33 +30,36 @@ namespace util { return fileContent.find("DOCTYPE") == std::string::npos; } - void downloadArchive(const std::string& url, archiveType type) + void downloadArchive(const std::string& url, contentType type) { long status_code; downloadArchive(url, type, status_code); } - void downloadArchive(const std::string& url, archiveType type, long& status_code) + void downloadArchive(const std::string& url, contentType type, long& status_code) { fs::createTree(DOWNLOAD_PATH); switch (type) { - case archiveType::sigpatches: + case contentType::sigpatches: status_code = download::downloadFile(url, SIGPATCHES_FILENAME, OFF); break; - case archiveType::cheats: + case contentType::cheats: status_code = download::downloadFile(url, CHEATS_FILENAME, OFF); break; - case archiveType::fw: + case contentType::fw: status_code = download::downloadFile(url, FIRMWARE_FILENAME, OFF); break; - case archiveType::app: + case contentType::app: status_code = download::downloadFile(url, APP_FILENAME, OFF); break; - case archiveType::bootloaders: + case contentType::bootloaders: status_code = download::downloadFile(url, CFW_FILENAME, OFF); break; - case archiveType::ams_cfw: + case contentType::ams_cfw: status_code = download::downloadFile(url, AMS_FILENAME, OFF); + break; + default: + break; } ProgressEvent::instance().setStatusCode(status_code); } @@ -104,12 +107,12 @@ namespace util { return result; } - void extractArchive(archiveType type, const std::string& tag) + void extractArchive(contentType type, const std::string& tag) { int overwriteInis = 0; chdir(ROOT_PATH); switch (type) { - case archiveType::sigpatches: + case contentType::sigpatches: if (isArchive(SIGPATCHES_FILENAME)) { /* if(std::filesystem::exists(HEKATE_IPL_PATH)){ overwriteInis = showDialogBox("menus/utils/overwrite"_i18n + std::string(HEKATE_IPL_PATH) +"?", "menus/common/no"_i18n, "menus/common/yes"_i18n); @@ -128,13 +131,13 @@ namespace util { brls::Application::crash("menus/utils/wrong_type_sigpatches"_i18n); } break; - case archiveType::cheats: { + case contentType::cheats: { std::vector titles = extract::getInstalledTitlesNs(); titles = extract::excludeTitles(CHEATS_EXCLUDE, titles); extract::extractCheats(CHEATS_FILENAME, titles, CurrentCfw::running_cfw); break; } - case archiveType::fw: + case contentType::fw: if (std::filesystem::file_size(FIRMWARE_FILENAME) < 200000) { brls::Application::crash("menus/utils/wrong_type_sigpatches_downloaded"_i18n); } @@ -144,14 +147,14 @@ namespace util { extract::extract(FIRMWARE_FILENAME, FIRMWARE_PATH); } break; - case archiveType::app: + case contentType::app: extract::extract(APP_FILENAME, CONFIG_PATH); fs::copyFile(ROMFS_FORWARDER, FORWARDER_PATH); envSetNextLoad(FORWARDER_PATH, fmt::format("\"{}\"", FORWARDER_PATH).c_str()); romfsExit(); brls::Application::quit(); break; - case archiveType::bootloaders: + case contentType::bootloaders: if (isArchive(CFW_FILENAME)) { overwriteInis = showDialogBox("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); extract::extract(CFW_FILENAME, ROOT_PATH, overwriteInis); @@ -160,7 +163,7 @@ namespace util { brls::Application::crash("menus/utils/wrong_type_cfw"_i18n); } break; - case archiveType::ams_cfw: + case contentType::ams_cfw: if (isArchive(AMS_FILENAME)) { overwriteInis = showDialogBox("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); usleep(800000); @@ -170,8 +173,10 @@ namespace util { extract::extract(AMS_FILENAME, ROOT_PATH, overwriteInis); } break; + default: + break; } - if (type == archiveType::ams_cfw || type == archiveType::bootloaders) + if (type == contentType::ams_cfw || type == contentType::bootloaders) fs::copyFiles(COPY_FILES_TXT); }