1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-09-16 20:13:35 +01:00

add payload downloads to bootloader tab

This commit is contained in:
flb 2021-09-27 21:56:41 +02:00
parent 1da56da064
commit cf9ad1d51a
24 changed files with 161 additions and 144 deletions

View file

@ -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,

View file

@ -7,8 +7,8 @@ constexpr int OFF = 0;
namespace download {
long downloadFile(const std::string& url, std::vector<std::uint8_t>& 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<std::uint8_t>& res, const std::string& output = "", int api = OFF);
long downloadFile(const std::string& url, const std::string& output = "", int api = OFF);
std::vector<std::pair<std::string, std::string>> getLinks(const std::string& url);
std::vector<std::pair<std::string, std::string>> getLinksFromJson(const nlohmann::ordered_json& json_object);
std::string fetchTitle(const std::string& url);

View file

@ -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;
};

View file

@ -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<std::string> fetchPayloads();

View file

@ -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 ",

View file

@ -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 ",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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 ",

View file

@ -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 ",

View file

@ -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",

View file

@ -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": "数字签名",

View file

@ -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金手指資料庫(版本 ",

View file

@ -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));

View file

@ -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);

View file

@ -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(

View file

@ -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<std::uint8_t> dummy;
return downloadFile(url, dummy, output, api);
}
long downloadFile(const std::string& url, std::vector<std::uint8_t>& res, const char* output, int api)
long downloadFile(const std::string& url, std::vector<std::uint8_t>& 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<u_int8_t*>(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);
}

View file

@ -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);

View file

@ -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<zipper::ZipEntry>& 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

View file

@ -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<std::pair<std::string, std::string>> links, sxoslinks;
std::vector<std::pair<std::string, std::string>> 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<std::pair<std::string, std::string>> 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()

View file

@ -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));

View file

@ -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);

View file

@ -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<std::string> 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);
}