From 4e02841839c885fc269248ad8a495bb44dd532ba Mon Sep 17 00:00:00 2001 From: flb Date: Sat, 6 Feb 2021 19:42:14 +0100 Subject: [PATCH] handle quota exceeded for cheatslips --- README.md | 4 --- include/list_download_tab.hpp | 1 + resources/i18n/en-US/menus.json | 4 ++- source/download_cheats_page.cpp | 24 +++++++++++-- source/list_download_tab.cpp | 64 ++++++++++++++++++--------------- 5 files changed, 61 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index b4bcb6b..1253daa 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,8 @@ ![GitHub](https://img.shields.io/github/license/HamletDuFromage/aio-switch-updater) [![btc](https://img.shields.io/badge/BTC-1CoFc1bY5AHLP6Noe1zmqnJnp7ZWBxyo79-yellow)](https://github.com/HamletDuFromage/aio-switch-updater#like-the-app) - [![eth](https://img.shields.io/badge/ETH-0xf68f568e21a15934e0e9a6949288c3ca009140ba-purple)](https://github.com/HamletDuFromage/aio-switch-updater#like-the-app) -[![eth](https://img.shields.io/badge/LINK-0xf68f568e21a15934e0e9a6949288c3ca009140ba-lightblue -)](https://github.com/HamletDuFromage/aio-switch-updater#like-the-app) - [//]: ([![ko-fi](https://img.shields.io/badge/ko--fi-buy%20me%20a%20coffee-ff69b4)](https://ko-fi.com/hamletdufromage)) diff --git a/include/list_download_tab.hpp b/include/list_download_tab.hpp index 9514612..357e8c7 100644 --- a/include/list_download_tab.hpp +++ b/include/list_download_tab.hpp @@ -14,6 +14,7 @@ class ListDownloadTab : public brls::List brls::ListItem *cheatslipsItem; brls::Label *notFound; brls::Label *description; + brls::Label *cheatSlipLabel; public: ListDownloadTab(archiveType type); ~ListDownloadTab(); diff --git a/resources/i18n/en-US/menus.json b/resources/i18n/en-US/menus.json index ac0adbd..f85ec1a 100644 --- a/resources/i18n/en-US/menus.json +++ b/resources/i18n/en-US/menus.json @@ -77,9 +77,11 @@ "cheat_All_done": "All done!", "get_cheatslips": "Download CheatSlips.com cheat sheets", + "cheatslips_label": "\uE016 Log into CheatSlips.com and download cheat sheets for your games.", "download_cheatslips": "Download a selection of cheat sheets from CheatSlips.com.\nThose cheat codes will be added to the end of your existing cheat file.", "delete_cheat": "Delete existing cheat file", - "couldnt_dl_cheats": "Could not fetch selected cheat codes/invalid token.\nYou may have reached your daily download quota. Head on to 'https://www.cheatslips.com/subscriptions' to see increase it.\n", + "couldnt_dl_cheats": "Could not fetch selected cheat codes/invalid token.", + "quota_cheatslips": "Quota exceeded for today!\nHead on to 'https://www.cheatslips.com/subscriptions' to see increase it.", "cheat_cheat_content": "Cheatsheet content: ", "app_cheatslips_label": "Select a game to download cheats for.", "/wrong_cheatslips_id": "Couldn't retrieve token, make you enter you login properly", diff --git a/source/download_cheats_page.cpp b/source/download_cheats_page.cpp index 70e6986..9b0b65f 100644 --- a/source/download_cheats_page.cpp +++ b/source/download_cheats_page.cpp @@ -56,6 +56,7 @@ DownloadCheatsPage::DownloadCheatsPage(uint64_t tid) : AppletFrame(true, true) ids.push_back(e.second); } } + int error = 0; if(!ids.empty()) { json token; std::ifstream tokenFile(TOKEN_PATH); @@ -69,12 +70,29 @@ DownloadCheatsPage::DownloadCheatsPage(uint64_t tid) : AppletFrame(true, true) if(cheatsInfo.find("cheats") != cheatsInfo.end()) { for (const auto& p : cheatsInfo["cheats"].items()) { if(std::find(ids.begin(), ids.end(), p.value()["id"]) != ids.end()) { - WriteCheats(tid, bid, p.value()["content"]); + if(p.value()["content"].get() == "Quota exceeded for today !"){ + error = 1; + } + else { + WriteCheats(tid, bid, p.value()["content"]); + } } } } else { - brls::Dialog* dialog = new brls::Dialog("menus/couldnt_dl_cheats"_i18n); + error = 2; + } + + if(error != 0){ + brls::Dialog* dialog; + switch(error){ + case 1: + dialog = new brls::Dialog("menus/quota_cheatslips"_i18n); + break; + case 2: + dialog = new brls::Dialog("menus/couldnt_dl_cheats"_i18n); + break; + } brls::GenericEvent::Callback callback = [dialog](brls::View* view) { dialog->close(); }; @@ -83,7 +101,7 @@ DownloadCheatsPage::DownloadCheatsPage(uint64_t tid) : AppletFrame(true, true) dialog->open(); } } - brls::Application::popView(); + if(error == 0) brls::Application::popView(); return true; }); diff --git a/source/list_download_tab.cpp b/source/list_download_tab.cpp index 81f9306..2611984 100644 --- a/source/list_download_tab.cpp +++ b/source/list_download_tab.cpp @@ -65,7 +65,43 @@ ListDownloadTab::ListDownloadTab(archiveType type) : } this->addView(description); + + int nbLinks = std::get<0>(links).size(); + if(nbLinks){ + for (int i = 0; i(links)[i]; + std::string text("menus/list_down"_i18n + std::get<0>(links)[i] + "menus/list_from"_i18n + url); + listItem = new brls::ListItem(std::get<0>(links)[i]); + listItem->setHeight(LISTITEM_HEIGHT); + listItem->getClickEvent()->subscribe([&, text, url, type, operation](brls::View* view) { + brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); + stagedFrame->setTitle(operation); + stagedFrame->addStage( + new ConfirmPage(stagedFrame, text) + ); + stagedFrame->addStage( + new WorkerPage(stagedFrame, "menus/list_downing"_i18n , [url, type](){downloadArchive(url, type);}) + ); + stagedFrame->addStage( + new WorkerPage(stagedFrame, "menus/list_extracting"_i18n , [type](){extractArchive(type);}) + ); + stagedFrame->addStage( + new ConfirmPage(stagedFrame, "menus/list_All"_i18n , true) + ); + brls::Application::pushView(stagedFrame); + }); + this->addView(listItem); + } + + } + if(type == cheats){ + cheatSlipLabel = new brls::Label( + brls::LabelStyle::DESCRIPTION, + "menus/cheatslips_label"_i18n , + true + ); + this->addView(cheatSlipLabel); cheatslipsItem = new brls::ListItem("menus/get_cheatslips"_i18n); cheatslipsItem->setHeight(LISTITEM_HEIGHT); cheatslipsItem->getClickEvent()->subscribe([&](brls::View* view) { @@ -122,34 +158,6 @@ ListDownloadTab::ListDownloadTab(archiveType type) : this->addView(cheatslipsItem); } - int nbLinks = std::get<0>(links).size(); - if(nbLinks){ - for (int i = 0; i(links)[i]; - std::string text("menus/list_down"_i18n + std::get<0>(links)[i] + "menus/list_from"_i18n + url); - listItem = new brls::ListItem(std::get<0>(links)[i]); - listItem->setHeight(LISTITEM_HEIGHT); - listItem->getClickEvent()->subscribe([&, text, url, type, operation](brls::View* view) { - brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); - stagedFrame->setTitle(operation); - stagedFrame->addStage( - new ConfirmPage(stagedFrame, text) - ); - stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/list_downing"_i18n , [url, type](){downloadArchive(url, type);}) - ); - stagedFrame->addStage( - new WorkerPage(stagedFrame, "menus/list_extracting"_i18n , [type](){extractArchive(type);}) - ); - stagedFrame->addStage( - new ConfirmPage(stagedFrame, "menus/list_All"_i18n , true) - ); - brls::Application::pushView(stagedFrame); - }); - this->addView(listItem); - } - - } else{ notFound = new brls::Label( brls::LabelStyle::DESCRIPTION,