From 777c39d84db8ffc1d8c334d740cc4774c25972c8 Mon Sep 17 00:00:00 2001 From: mrdude2478 Date: Fri, 8 Sep 2023 03:11:50 +0100 Subject: [PATCH] add url max file limit option --- include/util/config.hpp | 1 + romfs/lang/de.json | 5 +++- romfs/lang/en.json | 5 +++- romfs/lang/es.json | 5 +++- romfs/lang/fr.json | 5 +++- romfs/lang/it.json | 5 +++- romfs/lang/jp.json | 5 +++- romfs/lang/ru.json | 5 +++- romfs/lang/tw.json | 5 +++- source/netInstall.cpp | 36 +++++++++++++++++++-------- source/ui/optionsPage.cpp | 52 ++++++++++++++++++++++++++++----------- source/util/config.cpp | 4 +++ source/util/curl.cpp | 2 -- 13 files changed, 101 insertions(+), 34 deletions(-) diff --git a/include/util/config.hpp b/include/util/config.hpp index 6ff91d9..385c502 100644 --- a/include/util/config.hpp +++ b/include/util/config.hpp @@ -22,6 +22,7 @@ namespace inst::config { extern bool gayMode; extern bool useSound; extern bool fixticket; + extern bool listoveride; extern bool httpkeyboard; void setConfig(); diff --git a/romfs/lang/de.json b/romfs/lang/de.json index ebeef64..9d4d411 100644 --- a/romfs/lang/de.json +++ b/romfs/lang/de.json @@ -54,7 +54,9 @@ "hint": "Gebe eine URL zu einer Datei ein", "invalid": "Die eingegebene URL ist ungültig", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": " per URL" + "source_string": " per URL", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "Gebe die ID einer öffentlichen Google Drive Datei ein", @@ -178,6 +180,7 @@ "gay_option": "Design verwenden", "useSound": "Nutzen von Benachrichtungstönen während Installation", "fixticket": "Convert temporary tickets to permanent", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Use keyboard during http server installs", "sig_url": "Signatur Patches URL: ", "http_url": "Http server source URL: ", diff --git a/romfs/lang/en.json b/romfs/lang/en.json index 04d0691..116e89a 100644 --- a/romfs/lang/en.json +++ b/romfs/lang/en.json @@ -54,7 +54,9 @@ "hint": "Enter the Internet address of a file", "invalid": "The URL specified is invalid!", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": " from URL" + "source_string": " from URL", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "Enter the file ID of a public Google Drive file", @@ -178,6 +180,7 @@ "gay_option": "Use Theme", "useSound": "Use sound notifications during installs", "fixticket": "Convert temporary tickets to permanent", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Use keyboard during http server installs", "sig_url": "Signature patches source URL: ", "http_url": "Http server source URL: ", diff --git a/romfs/lang/es.json b/romfs/lang/es.json index 5128fc7..0555422 100644 --- a/romfs/lang/es.json +++ b/romfs/lang/es.json @@ -54,7 +54,9 @@ "hint": "Ingrese la dirección de Internet de un archivo", "invalid": "¡La URL especificada no es válida!", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": "desde la URL" + "source_string": "desde la URL", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "Introduce el ID de un archivo público de Google Drive", @@ -178,6 +180,7 @@ "gay_option": "Usar tema", "useSound": "Usar notificaciones de sonido durante las instalaciones", "fixticket": "Convert temporary tickets to permanent", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Use keyboard during http server installs", "sig_url": "URL de origen de parches de firma: ", "http_url": "Http server source URL: ", diff --git a/romfs/lang/fr.json b/romfs/lang/fr.json index a4da995..4243def 100644 --- a/romfs/lang/fr.json +++ b/romfs/lang/fr.json @@ -54,7 +54,9 @@ "hint": "Entrez l'URL d'un fichier", "invalid": "L'URL spécifiée n'est pas valide !", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": " à partir d'un URL" + "source_string": " à partir d'un URL", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "Saisissez l'ID d'un fichier Google Drive public", @@ -178,6 +180,7 @@ "gay_option": "Utiliser le thème", "useSound": "Utiliser les notifications sonores lors des installations", "fixticket": "Convertir des billets temporaires en billets permanents", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Utiliser le clavier lors des installations du serveur http", "sig_url": "Patchs de signatures URL: ", "http_url": "URL source du serveur HTTP: ", diff --git a/romfs/lang/it.json b/romfs/lang/it.json index 3f79a2e..6815403 100644 --- a/romfs/lang/it.json +++ b/romfs/lang/it.json @@ -54,7 +54,9 @@ "hint": "Inserisci l'URL del file", "invalid": "L'URL specificato non è valido!", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": " da URL" + "source_string": " da URL", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "Inserisci l'ID di un file pubblico di Google Drive", @@ -178,6 +180,7 @@ "gay_option": "Usa tema", "useSound": "Use sound notifications during installs", "fixticket": "Convert temporary tickets to permanent", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Use keyboard during http server installs", "sig_url": "Fonte URL SigPatches: ", "http_url": "Http server source URL: ", diff --git a/romfs/lang/jp.json b/romfs/lang/jp.json index 3f49217..d3f7a9b 100644 --- a/romfs/lang/jp.json +++ b/romfs/lang/jp.json @@ -54,7 +54,9 @@ "hint": "ファイルのインターネットアドレスを入力してください", "invalid": "指定されたURLは無効です!", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": " URLから" + "source_string": " URLから", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "Googleドライブの公開ファイルのファイルIDを入力してください", @@ -178,6 +180,7 @@ "gay_option": "テーマを使用する", "useSound": "インストール時にサウンドで通知する", "fixticket": "Convert temporary tickets to permanent", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Use keyboard during http server installs", "sig_url": "署名パッチのソースURL: ", "http_url": "Http server source URL: ", diff --git a/romfs/lang/ru.json b/romfs/lang/ru.json index cf9dc04..a14860c 100644 --- a/romfs/lang/ru.json +++ b/romfs/lang/ru.json @@ -54,7 +54,9 @@ "hint": "Укажите ссылку на файл", "invalid": "Указан неверный URL!", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": " из URL" + "source_string": " из URL", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "Введите ID файла из общедоступного Google Drive", @@ -178,6 +180,7 @@ "gay_option": "Использовать тему", "useSound": "Use sound notifications during installs", "fixticket": "Convert temporary tickets to permanent", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Use keyboard during http server installs", "sig_url": "URL для скачивания Signature patches: ", "http_url": "Http server source URL: ", diff --git a/romfs/lang/tw.json b/romfs/lang/tw.json index 2b8e7cb..5c241db 100644 --- a/romfs/lang/tw.json +++ b/romfs/lang/tw.json @@ -54,7 +54,9 @@ "hint": "請輸入檔案的URL網路位址", "invalid": "URL網路位址無效!", "nolinks": "No XCI, XCZ, NSP, NSZ links found!\nDid you use the correct URL?", - "source_string": "來源為URL" + "source_string": "來源為URL", + "listwait": "Populating the list from a url can take some time.\nThe list default limit is purposely set to ", + "listwait2": " items.\nPress OK to load the list." }, "gdrive": { "hint": "請輸入Google網路硬碟的共享檔案ID", @@ -178,6 +180,7 @@ "gay_option": "套用主題", "useSound": "在安裝過程中使用音效提醒進度", "fixticket": "Convert temporary tickets to permanent", + "listoveride": "Disable URL list warning and file limit", "usehttpkeyboard": "Use keyboard during http server installs", "sig_url": "簽名修補程式來源URL: ", "http_url": "Http server source URL: ", diff --git a/source/netInstall.cpp b/source/netInstall.cpp index a83d8d2..e4360cd 100644 --- a/source/netInstall.cpp +++ b/source/netInstall.cpp @@ -101,6 +101,7 @@ namespace netInstStuff { if (c == '/') new_str += '/'; else if (c == '.') new_str += '.'; else if (c == ':') new_str += ':'; + else if (c == '\\') new_str += '/'; //windows paths break urls - change the path mod.. else if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') new_str += c; else { sprintf(bufHex, "%X", c); @@ -356,7 +357,10 @@ namespace netInstStuff { } if (kDown & HidNpadButton_Minus) { + if (std::filesystem::remove("temp.html")); std::string url; + unsigned short maxlist = 50; + unsigned short nowlist = 0; if (inst::config::httpkeyboard) { url = inst::util::softwareKeyboard("inst.net.url.hint"_lang, inst::config::httpIndexUrl, 500); @@ -398,7 +402,7 @@ namespace netInstStuff { } if (!response.empty()) { - if (response[0] == '{') { + if (response[0] == '*') { try { nlohmann::json j = nlohmann::json::parse(response); for (const auto& file : j["files"]) { @@ -414,6 +418,9 @@ namespace netInstStuff { } else if (!response.empty()) { std::size_t index = 0; + if (!inst::config::listoveride) { + inst::ui::mainApp->CreateShowDialog("inst.net.url.listwait"_lang + std::to_string(maxlist) + "inst.net.url.listwait2"_lang, "", { "common.ok"_lang }, false, "romfs:/images/icons/wait.png"); + } while (index < response.size()) { std::string link; auto found = findCaseInsensitive(response, "href=\"", index); @@ -429,17 +436,26 @@ namespace netInstStuff { Try to see if the href links contain http - if not add the own url defined in the settings page */ - if (link.find("http") == std::string::npos) { - std::string before_strip = stripfilename(url); - if (link[0] == '/'){ - tmp_array.push_back(before_strip + link); - } - else{ - tmp_array.push_back(before_strip + "/" + link); - } + if (!inst::config::listoveride && nowlist >= maxlist) { + break; } else { - tmp_array.push_back(link); + if (link.find("http") == std::string::npos) { + std::string before_strip = stripfilename(url); + if (link[0] == '/') { + tmp_array.push_back(before_strip + link); + nowlist++; + } + else { + tmp_array.push_back(before_strip + "/" + link); + nowlist++; + + } + } + else { + tmp_array.push_back(link); + nowlist++; + } } } break; //don't remove this or the net install screen will crash diff --git a/source/ui/optionsPage.cpp b/source/ui/optionsPage.cpp index f97f35c..b46a762 100644 --- a/source/ui/optionsPage.cpp +++ b/source/ui/optionsPage.cpp @@ -124,57 +124,77 @@ namespace inst::ui { void optionsPage::setMenuText() { this->menu->ClearItems(); + auto ignoreFirmOption = pu::ui::elm::MenuItem::New("options.menu_items.ignore_firm"_lang); ignoreFirmOption->SetColor(COLOR("#FFFFFFFF")); ignoreFirmOption->SetIcon(this->getMenuOptionIcon(inst::config::ignoreReqVers)); this->menu->AddItem(ignoreFirmOption); + auto validateOption = pu::ui::elm::MenuItem::New("options.menu_items.nca_verify"_lang); validateOption->SetColor(COLOR("#FFFFFFFF")); validateOption->SetIcon(this->getMenuOptionIcon(inst::config::validateNCAs)); this->menu->AddItem(validateOption); + auto overclockOption = pu::ui::elm::MenuItem::New("options.menu_items.boost_mode"_lang); overclockOption->SetColor(COLOR("#FFFFFFFF")); overclockOption->SetIcon(this->getMenuOptionIcon(inst::config::overClock)); this->menu->AddItem(overclockOption); + auto deletePromptOption = pu::ui::elm::MenuItem::New("options.menu_items.ask_delete"_lang); deletePromptOption->SetColor(COLOR("#FFFFFFFF")); deletePromptOption->SetIcon(this->getMenuOptionIcon(inst::config::deletePrompt)); this->menu->AddItem(deletePromptOption); + auto autoUpdateOption = pu::ui::elm::MenuItem::New("options.menu_items.auto_update"_lang); autoUpdateOption->SetColor(COLOR("#FFFFFFFF")); autoUpdateOption->SetIcon(this->getMenuOptionIcon(inst::config::autoUpdate)); this->menu->AddItem(autoUpdateOption); + auto gayModeOption = pu::ui::elm::MenuItem::New("options.menu_items.gay_option"_lang); gayModeOption->SetColor(COLOR("#FFFFFFFF")); gayModeOption->SetIcon(this->getMenuOptionIcon(inst::config::gayMode)); this->menu->AddItem(gayModeOption); + auto useSoundOption = pu::ui::elm::MenuItem::New("options.menu_items.useSound"_lang); useSoundOption->SetColor(COLOR("#FFFFFFFF")); useSoundOption->SetIcon(this->getMenuOptionIcon(inst::config::useSound)); this->menu->AddItem(useSoundOption); + auto fixticket = pu::ui::elm::MenuItem::New("options.menu_items.fixticket"_lang); fixticket->SetColor(COLOR("#FFFFFFFF")); fixticket->SetIcon(this->getMenuOptionIcon(inst::config::fixticket)); this->menu->AddItem(fixticket); + + auto listoveride = pu::ui::elm::MenuItem::New("options.menu_items.listoveride"_lang); + listoveride->SetColor(COLOR("#FFFFFFFF")); + listoveride->SetIcon(this->getMenuOptionIcon(inst::config::listoveride)); + this->menu->AddItem(listoveride); + auto httpkeyboard = pu::ui::elm::MenuItem::New("options.menu_items.usehttpkeyboard"_lang); httpkeyboard->SetColor(COLOR("#FFFFFFFF")); httpkeyboard->SetIcon(this->getMenuOptionIcon(inst::config::httpkeyboard)); this->menu->AddItem(httpkeyboard); + auto SigPatch = pu::ui::elm::MenuItem::New("main.menu.sig"_lang); SigPatch->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(SigPatch); + auto sigPatchesUrlOption = pu::ui::elm::MenuItem::New("options.menu_items.sig_url"_lang + inst::util::shortenString(inst::config::sigPatchesUrl, 42, false)); sigPatchesUrlOption->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(sigPatchesUrlOption); + auto httpServerUrlOption = pu::ui::elm::MenuItem::New("options.menu_items.http_url"_lang + inst::util::shortenString(inst::config::httpIndexUrl, 42, false)); httpServerUrlOption->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(httpServerUrlOption); + auto languageOption = pu::ui::elm::MenuItem::New("options.menu_items.language"_lang + this->getMenuLanguage(inst::config::languageSetting)); languageOption->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(languageOption); + auto updateOption = pu::ui::elm::MenuItem::New("options.menu_items.check_update"_lang); updateOption->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(updateOption); + auto creditsOption = pu::ui::elm::MenuItem::New("options.menu_items.credits"_lang); creditsOption->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(creditsOption); @@ -269,7 +289,6 @@ namespace inst::ui { thememessage(); inst::config::setConfig(); break; - case 6: if (inst::config::useSound) { inst::config::useSound = false; @@ -281,7 +300,6 @@ namespace inst::ui { this->menu->SetSelectedIndex(index); inst::config::setConfig(); break; - case 7: if (inst::config::fixticket) { inst::config::fixticket = false; @@ -292,9 +310,19 @@ namespace inst::ui { this->setMenuText(); this->menu->SetSelectedIndex(index); inst::config::setConfig(); - break; - + break; case 8: + if (inst::config::listoveride) { + inst::config::listoveride = false; + } + else { + inst::config::listoveride = true; + } + this->setMenuText(); + this->menu->SetSelectedIndex(index); + inst::config::setConfig(); + break; + case 9: if (inst::config::httpkeyboard) { inst::config::httpkeyboard = false; } @@ -305,12 +333,10 @@ namespace inst::ui { this->menu->SetSelectedIndex(index); inst::config::setConfig(); break; - - case 9: + case 10: sigPatchesMenuItem_Click(); break; - - case 10: + case 11: keyboardResult = inst::util::softwareKeyboard("options.sig_hint"_lang, inst::config::sigPatchesUrl.c_str(), 500); if (keyboardResult.size() > 0) { inst::config::sigPatchesUrl = keyboardResult; @@ -319,8 +345,7 @@ namespace inst::ui { this->menu->SetSelectedIndex(index); } break; - - case 11: + case 12: keyboardResult = inst::util::softwareKeyboard("inst.net.url.hint"_lang, inst::config::httpIndexUrl.c_str(), 500); if (keyboardResult.size() > 0) { inst::config::httpIndexUrl = keyboardResult; @@ -329,8 +354,7 @@ namespace inst::ui { this->menu->SetSelectedIndex(index); } break; - - case 12: + case 13: languageList = languageStrings; languageList.push_back("options.language.system_language"_lang); rc = inst::ui::mainApp->CreateShowDialog("options.language.title"_lang, "options.language.desc"_lang, languageList, false, flag ); @@ -367,7 +391,7 @@ namespace inst::ui { mainApp->FadeOut(); mainApp->Close(); break; - case 13: + case 14: if (inst::util::getIPAddress() == "1.0.0.127") { inst::ui::mainApp->CreateShowDialog("main.net.title"_lang, "main.net.desc"_lang, { "common.ok"_lang }, true, "romfs:/images/icons/update.png"); break; @@ -379,7 +403,7 @@ namespace inst::ui { } this->askToUpdate(downloadUrl); break; - case 14: + case 15: inst::ui::mainApp->CreateShowDialog("options.credits.title"_lang, "options.credits.desc"_lang, { "common.close"_lang }, true, "romfs:/images/icons/credits.png"); break; default: diff --git a/source/util/config.cpp b/source/util/config.cpp index 1da2ea3..2650116 100644 --- a/source/util/config.cpp +++ b/source/util/config.cpp @@ -19,6 +19,7 @@ namespace inst::config { bool usbAck; bool validateNCAs; bool fixticket; + bool listoveride; bool httpkeyboard; void setConfig() { @@ -37,6 +38,7 @@ namespace inst::config { {"httpIndexUrl", httpIndexUrl}, {"httplastUrl", httplastUrl}, {"fixticket", fixticket}, + {"listoveride", listoveride}, {"httpkeyboard", httpkeyboard} }; std::ofstream file(inst::config::configPath); @@ -50,6 +52,7 @@ namespace inst::config { file >> j; autoUpdate = j["autoUpdate"].get(); fixticket = j["fixticket"].get(); + listoveride = j["listoveride"].get(); httpkeyboard = j["httpkeyboard"].get(); deletePrompt = j["deletePrompt"].get(); gAuthKey = j["gAuthKey"].get(); @@ -76,6 +79,7 @@ namespace inst::config { gayMode = false; useSound = true; fixticket = true; + listoveride = false; httpkeyboard = false; ignoreReqVers = true; overClock = true; diff --git a/source/util/curl.cpp b/source/util/curl.cpp index 28b6362..29d1c47 100644 --- a/source/util/curl.cpp +++ b/source/util/curl.cpp @@ -126,8 +126,6 @@ namespace inst::curl { } std::string html_to_buffer(const std::string ourUrl) { - //best to remove "temp.html if it already exists!" - if (std::filesystem::remove("temp.html")); CURL* curl; FILE* fp; CURLcode res{};