From 5d3a90c6e877e09b773b8e4a549a673fc82ef590 Mon Sep 17 00:00:00 2001 From: mrdude2478 Date: Tue, 3 Oct 2023 04:00:19 +0100 Subject: [PATCH] add theme stuff to usb & hdd install pages --- source/ui/mainPage.cpp | 11 +++- source/ui/netInstPage.cpp | 125 ++++++++++++++++++++++++++------------ source/ui/usbInstPage.cpp | 87 ++++++++++++++++++++------ source/util/curl.cpp | 10 +++ 4 files changed, 175 insertions(+), 58 deletions(-) diff --git a/source/ui/mainPage.cpp b/source/ui/mainPage.cpp index f7ed11e..9dfafd3 100644 --- a/source/ui/mainPage.cpp +++ b/source/ui/mainPage.cpp @@ -126,6 +126,11 @@ namespace inst::ui { fsdevUnmountDevice("user"); std::string Info = ("usage.system_size"_lang + sdsize2 + "usage.gb"_lang + "usage.freespace"_lang + freespace2 + "usage.gb"_lang + "usage.percent_used"_lang + percent2 + "usage.percent"_lang + "usage.sd_size"_lang + sdsize + "usage.gb"_lang + "usage.sd_space"_lang + freespace + "usage.gb"_lang + "usage.sd_used"_lang + percent + "usage.percent_symbol"_lang); + + std::string drive = "romfs:/images/icons/drive.png"; + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(inst::config::appDir + "icons_others.drive"_theme)){ + drive = inst::config::appDir + "icons_others.drive"_theme; + } inst::ui::mainApp->CreateShowDialog("usage.space_info"_lang, Info, { "common.ok"_lang }, true, "romfs:/images/icons/drive.png"); } @@ -135,7 +140,11 @@ namespace inst::ui { tin::data::NUM_BUFFER_SEGMENTS = 2; if (menuLoaded) { inst::ui::appletFinished = true; - mainApp->CreateShowDialog("main.applet.title"_lang, "main.applet.desc"_lang, { "common.ok"_lang }, true, "romfs:/images/icons/information.png"); + std::string information = "romfs:/images/icons/information.png"; + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(inst::config::appDir + "icons_others.information"_theme)){ + information = inst::config::appDir + "icons_others.information"_theme; + } + mainApp->CreateShowDialog("main.applet.title"_lang, "main.applet.desc"_lang, { "common.ok"_lang }, true, information); } } else if (!appletFinished) { diff --git a/source/ui/netInstPage.cpp b/source/ui/netInstPage.cpp index 57cbd63..49dd623 100644 --- a/source/ui/netInstPage.cpp +++ b/source/ui/netInstPage.cpp @@ -8,6 +8,7 @@ #include "util/curl.hpp" #include "util/lang.hpp" #include "netInstall.hpp" +#include "util/theme.hpp" #include #define COLOR(hex) pu::ui::Color::FromHex(hex) @@ -21,26 +22,62 @@ namespace inst::ui { std::string sourceString = ""; netInstPage::netInstPage() : Layout::Layout() { - this->infoRect = Rectangle::New(0, 95, 1280, 60, COLOR("#00000080")); - this->SetBackgroundColor(COLOR("#000000FF")); - this->topRect = Rectangle::New(0, 0, 1280, 94, COLOR("#000000FF")); - this->botRect = Rectangle::New(0, 659, 1280, 61, COLOR("#000000FF")); + std::string infoRect_colour = "colour.inforect"_theme; + std::string bg_colour = "colour.background"_theme; + std::string tbar_colour = "colour.topbar"_theme; + std::string bbar_colour = "colour.bottombar"_theme; + std::string net_top = inst::config::appDir + "bg_images.net_top"_theme; + std::string default_background = inst::config::appDir + "bg_images.default_background"_theme; + std::string pageinfo_colour = "colour.pageinfo_text"_theme; + std::string bottombar_text = "colour.bottombar_text"_theme; + std::string background_overlay1 = "colour.background_overlay1"_theme; + std::string background_overlay2 = "colour.background_overlay2"_theme; + std::string focus = "colour.focus"_theme; + std::string scrollbar = "colour.scrollbar"_theme; + std::string waiting = inst::config::appDir + "icons_others.waiting_lan"_theme; + + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->infoRect = Rectangle::New(0, 95, 1280, 60, COLOR(infoRect_colour)); + else this->infoRect = Rectangle::New(0, 95, 1280, 60, COLOR("#00000080")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->SetBackgroundColor(COLOR(bg_colour)); + else this->SetBackgroundColor(COLOR("#000000FF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->topRect = Rectangle::New(0, 0, 1280, 94, COLOR(tbar_colour)); + else this->topRect = Rectangle::New(0, 0, 1280, 94, COLOR("#000000FF")); - if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/images/Net.png")) this->titleImage = Image::New(0, 0, (inst::config::appDir + "/theme/images/Net.png")); - else this->titleImage = Image::New(0, 0, "romfs:/images/Net.png"); + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->botRect = Rectangle::New(0, 659, 1280, 61, COLOR(bbar_colour)); + else this->botRect = Rectangle::New(0, 659, 1280, 61, COLOR("#000000FF")); - if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/images/Background.png")) this->SetBackgroundImage(inst::config::appDir + "/theme/images/Background.png"); + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(net_top)) this->titleImage = Image::New(0, 0, (net_top)); + else this->titleImage = Image::New(0, 0, "romfs:/images/net.png"); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(default_background)) this->SetBackgroundImage(default_background); else this->SetBackgroundImage("romfs:/images/Background.png"); - this->pageInfoText = TextBlock::New(10, 109, ""); + this->pageInfoText = TextBlock::New(10, 109, "inst.hd.top_info"_lang); this->pageInfoText->SetFont(pu::ui::MakeDefaultFontName(30)); - this->pageInfoText->SetColor(COLOR("#FFFFFFFF")); - this->butText = TextBlock::New(10, 678, ""); - this->butText->SetColor(COLOR("#FFFFFFFF")); - this->menu = pu::ui::elm::Menu::New(0, 156, 1280, COLOR("#FFFFFF00"), COLOR("#4f4f4d33"), 84, (506 / 84)); - this->menu->SetItemsFocusColor(COLOR("#4f4f4dAA")); - this->menu->SetScrollbarColor(COLOR("#1A1919FF")); - this->infoImage = Image::New(453, 292, "romfs:/images/icons/lan-connection-waiting.png"); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->pageInfoText->SetColor(COLOR(pageinfo_colour)); + else this->pageInfoText->SetColor(COLOR("#FFFFFFFF")); + + this->butText = TextBlock::New(10, 678, "inst.hd.buttons"_lang); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->butText->SetColor(COLOR(bottombar_text)); + else this->butText->SetColor(COLOR("#FFFFFFFF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->menu = pu::ui::elm::Menu::New(0, 156, 1280, COLOR(background_overlay1), COLOR(background_overlay2), 84, (506 / 84)); + else this->menu = pu::ui::elm::Menu::New(0, 156, 1280, COLOR("#FFFFFF00"), COLOR("#4f4f4d33"), 84, (506 / 84)); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->menu->SetItemsFocusColor(COLOR(focus)); + else this->menu->SetItemsFocusColor(COLOR("#4f4f4dAA")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->menu->SetScrollbarColor(COLOR(scrollbar)); + else this->menu->SetScrollbarColor(COLOR("#1A1919FF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(waiting)) this->infoImage = Image::New(453, 292, waiting); + else this->infoImage = Image::New(453, 292, "romfs:/images/icons/lan-connection-waiting.png"); + this->Add(this->topRect); this->Add(this->infoRect); this->Add(this->botRect); @@ -56,12 +93,16 @@ namespace inst::ui { if (clearItems) this->selectedUrls = {}; if (clearItems) this->alternativeNames = {}; std::string itm; + std::string text_colour = "colour.main_text"_theme; this->menu->ClearItems(); for (auto& urls : this->ourUrls) { itm = inst::util::shortenString(inst::util::formatUrlString(urls), 56, true); auto ourEntry = pu::ui::elm::MenuItem::New(itm); - ourEntry->SetColor(COLOR("#FFFFFFFF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) ourEntry->SetColor(COLOR(text_colour)); + else ourEntry->SetColor(COLOR("#FFFFFFFF")); + ourEntry->SetIcon("romfs:/images/icons/checkbox-blank-outline.png"); long unsigned int i; for (i = 0; i < this->selectedUrls.size(); i++) { @@ -79,6 +120,7 @@ namespace inst::ui { if (clearItems) this->selectedUrls = {}; if (clearItems) this->alternativeNames = {}; std::string itm; + std::string text_colour = "colour.main_text"_theme; //Degug code to print out and sort a list of the files on the http server. /* @@ -109,7 +151,10 @@ namespace inst::ui { itm = inst::util::shortenString(inst::util::formatUrlString(file_without_extension), 56, true); //itm = inst::util::shortenString(inst::util::formatUrlString(urls), 56, true); auto ourEntry = pu::ui::elm::MenuItem::New(itm); - ourEntry->SetColor(COLOR("#FFFFFFFF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) ourEntry->SetColor(COLOR(text_colour)); + else ourEntry->SetColor(COLOR("#FFFFFFFF")); + ourEntry->SetIcon("romfs:/images/icons/checkbox-blank-outline.png"); long unsigned int i; for (i = 0; i < this->selectedUrls.size(); i++) { @@ -135,7 +180,6 @@ namespace inst::ui { void netInstPage::startNetwork() { this->butText->SetText("inst.net.buttons"_lang); - //this->butText->SetText("inst.net.buttons"_lang + " \ue0f0 Install From HTTP Directory"); this->menu->SetVisible(false); this->menu->ClearItems(); this->infoImage->SetVisible(true); @@ -149,7 +193,11 @@ namespace inst::ui { else if (this->ourUrls[0] == "supplyUrl") { std::string keyboardResult; - switch (mainApp->CreateShowDialog("inst.net.src.title"_lang, "common.cancel_desc"_lang, { "inst.net.src.opt0"_lang, "inst.net.src.opt1"_lang }, false, "romfs:/images/icons/update.png")) { + std::string update = "romfs:/images/icons/update.png"; + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(inst::config::appDir + "icons_others.update"_theme)){ + update = inst::config::appDir + "icons_others.update"_theme; + } + switch (mainApp->CreateShowDialog("inst.net.src.title"_lang, "common.cancel_desc"_lang, { "inst.net.src.opt0"_lang, "inst.net.src.opt1"_lang }, false, update)) { case 0: keyboardResult = inst::util::softwareKeyboard("inst.net.url.hint"_lang, inst::config::httplastUrl, 500); if (keyboardResult.size() > 0) { @@ -164,7 +212,11 @@ namespace inst::ui { } if (inst::util::formatUrlString(keyboardResult) == "" || keyboardResult == "https://" || keyboardResult == "http://") { - mainApp->CreateShowDialog("inst.net.url.invalid"_lang, "", { "common.ok"_lang }, false, "romfs:/images/icons/fail.png"); + std::string fail = "romfs:/images/icons/fail.png"; + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(inst::config::appDir + "icons_others.fail"_theme)){ + fail = inst::config::appDir + "icons_others.fail"_theme; + } + mainApp->CreateShowDialog("inst.net.url.invalid"_lang, "", { "common.ok"_lang }, false, fail); break; } sourceString = "inst.net.url.source_string"_lang; @@ -207,13 +259,21 @@ namespace inst::ui { void netInstPage::startInstall(bool urlMode) { int dialogResult = -1; + std::string install = "romfs:/images/icons/install.png"; + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(inst::config::appDir + "icons_others.install"_theme)){ + install = inst::config::appDir + "icons_others.install"_theme; + } + if (this->selectedUrls.size() == 1) { std::string ourUrlString; if (this->alternativeNames.size() > 0) ourUrlString = inst::util::shortenString(this->alternativeNames[0], 32, true); - else ourUrlString = inst::util::shortenString(inst::util::formatUrlString(this->selectedUrls[0]), 32, true); - dialogResult = mainApp->CreateShowDialog("inst.target.desc0"_lang + ":\n\n" + ourUrlString + "\n\n" + "inst.target.desc1"_lang, "\n\n\n\n\n\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, "romfs:/images/icons/install.png"); + else { + ourUrlString = inst::util::shortenString(inst::util::formatUrlString(this->selectedUrls[0]), 32, true); + } + + dialogResult = mainApp->CreateShowDialog("inst.target.desc0"_lang + ":\n\n" + ourUrlString + "\n\n" + "inst.target.desc1"_lang, "\n\n\n\n\n\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, install); } - else dialogResult = mainApp->CreateShowDialog("inst.target.desc00"_lang + std::to_string(this->selectedUrls.size()) + "inst.target.desc01"_lang, "\n\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, "romfs:/images/icons/install.png"); + else dialogResult = mainApp->CreateShowDialog("inst.target.desc00"_lang + std::to_string(this->selectedUrls.size()) + "inst.target.desc01"_lang, "\n\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, install); if (dialogResult == -1 && !urlMode) return; else if (dialogResult == -1 && urlMode) { this->startNetwork(); @@ -241,10 +301,7 @@ namespace inst::ui { if (xxx != 1) { int var = this->menu->GetItems().size(); auto s = std::to_string(var); - if (s == "0") { - //do nothing here because there's no items in the list, that way the app won't freeze - } - else { + if (s != "0") { this->selectTitle(this->menu->GetSelectedIndex()); if (this->menu->GetItems().size() == 1 && this->selectedUrls.size() == 1) { this->startInstall(false); @@ -261,13 +318,7 @@ namespace inst::ui { if (xxx != 1) { int var = this->menu->GetItems().size(); auto s = std::to_string(var); - //std::string s = ourUrlString; //debug stuff - //this->appVersionText->SetText(s); //debug stuff - - if (s == "0") { - //do nothing here because there's no items in the list, that way the app won't freeze - } - else { + if (s != "0") { this->selectTitle(this->menu->GetSelectedIndex()); if (this->menu->GetItems().size() == 1 && this->selectedUrls.size() == 1) { this->startInstall(false); @@ -293,11 +344,7 @@ namespace inst::ui { int var = this->menu->GetItems().size(); auto s = std::to_string(var); - if (s == "0") { - //do nothing here because there's no items in the list, that way the app won't freeze - } - - else { + if (s != "0") { if (this->selectedUrls.size() == 0) { this->selectTitle(this->menu->GetSelectedIndex()); this->startInstall(false); diff --git a/source/ui/usbInstPage.cpp b/source/ui/usbInstPage.cpp index a05c344..212b64b 100644 --- a/source/ui/usbInstPage.cpp +++ b/source/ui/usbInstPage.cpp @@ -4,6 +4,7 @@ #include "util/config.hpp" #include "util/lang.hpp" #include "usbInstall.hpp" +#include "util/theme.hpp" #define COLOR(hex) pu::ui::Color::FromHex(hex) @@ -13,26 +14,62 @@ namespace inst::ui { s32 www = 0; //touchscreen variable usbInstPage::usbInstPage() : Layout::Layout() { - this->infoRect = Rectangle::New(0, 95, 1280, 60, COLOR("#00000080")); - this->SetBackgroundColor(COLOR("#000000FF")); - this->topRect = Rectangle::New(0, 0, 1280, 94, COLOR("#000000FF")); - this->botRect = Rectangle::New(0, 659, 1280, 61, COLOR("#000000FF")); + std::string infoRect_colour = "colour.inforect"_theme; + std::string bg_colour = "colour.background"_theme; + std::string tbar_colour = "colour.topbar"_theme; + std::string bbar_colour = "colour.bottombar"_theme; + std::string usb_top = inst::config::appDir + "bg_images.usb_top"_theme; + std::string default_background = inst::config::appDir + "bg_images.default_background"_theme; + std::string pageinfo_colour = "colour.pageinfo_text"_theme; + std::string bottombar_text = "colour.bottombar_text"_theme; + std::string background_overlay1 = "colour.background_overlay1"_theme; + std::string background_overlay2 = "colour.background_overlay2"_theme; + std::string focus = "colour.focus"_theme; + std::string scrollbar = "colour.scrollbar"_theme; + std::string waiting = inst::config::appDir + "icons_others.waiting_usb"_theme; + + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->infoRect = Rectangle::New(0, 95, 1280, 60, COLOR(infoRect_colour)); + else this->infoRect = Rectangle::New(0, 95, 1280, 60, COLOR("#00000080")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->SetBackgroundColor(COLOR(bg_colour)); + else this->SetBackgroundColor(COLOR("#000000FF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->topRect = Rectangle::New(0, 0, 1280, 94, COLOR(tbar_colour)); + else this->topRect = Rectangle::New(0, 0, 1280, 94, COLOR("#000000FF")); - if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/images/Usb.png")) this->titleImage = Image::New(0, 0, (inst::config::appDir + "/theme/images/Usb.png")); + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->botRect = Rectangle::New(0, 659, 1280, 61, COLOR(bbar_colour)); + else this->botRect = Rectangle::New(0, 659, 1280, 61, COLOR("#000000FF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(usb_top)) this->titleImage = Image::New(0, 0, (usb_top)); else this->titleImage = Image::New(0, 0, "romfs:/images/Usb.png"); - if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/images/Background.png")) this->SetBackgroundImage(inst::config::appDir + "/theme/images/Background.png"); + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(default_background)) this->SetBackgroundImage(default_background); else this->SetBackgroundImage("romfs:/images/Background.png"); - this->pageInfoText = TextBlock::New(10, 109, ""); - this->pageInfoText->SetColor(COLOR("#FFFFFFFF")); + this->pageInfoText = TextBlock::New(10, 109, "inst.hd.top_info"_lang); this->pageInfoText->SetFont(pu::ui::MakeDefaultFontName(30)); - this->butText = TextBlock::New(10, 678, ""); - this->butText->SetColor(COLOR("#FFFFFFFF")); - this->menu = pu::ui::elm::Menu::New(0, 156, 1280, COLOR("#FFFFFF00"), COLOR("#4f4f4d33"), 84, (506 / 84)); - this->menu->SetItemsFocusColor(COLOR("#4f4f4dAA")); - this->menu->SetScrollbarColor(COLOR("#1A1919FF")); - this->infoImage = Image::New(460, 332, "romfs:/images/icons/usb-connection-waiting.png"); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->pageInfoText->SetColor(COLOR(pageinfo_colour)); + else this->pageInfoText->SetColor(COLOR("#FFFFFFFF")); + + this->butText = TextBlock::New(10, 678, "inst.hd.buttons"_lang); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->butText->SetColor(COLOR(bottombar_text)); + else this->butText->SetColor(COLOR("#FFFFFFFF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->menu = pu::ui::elm::Menu::New(0, 156, 1280, COLOR(background_overlay1), COLOR(background_overlay2), 84, (506 / 84)); + else this->menu = pu::ui::elm::Menu::New(0, 156, 1280, COLOR("#FFFFFF00"), COLOR("#4f4f4d33"), 84, (506 / 84)); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->menu->SetItemsFocusColor(COLOR(focus)); + else this->menu->SetItemsFocusColor(COLOR("#4f4f4dAA")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) this->menu->SetScrollbarColor(COLOR(scrollbar)); + else this->menu->SetScrollbarColor(COLOR("#1A1919FF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(waiting)) this->infoImage = Image::New(453, 292, waiting); + else this->infoImage = Image::New(453, 292, "romfs:/images/icons/usb-connection-waiting.png"); + this->Add(this->topRect); this->Add(this->infoRect); this->Add(this->botRect); @@ -46,11 +83,15 @@ namespace inst::ui { void usbInstPage::drawMenuItems_withext(bool clearItems) { int myindex = this->menu->GetSelectedIndex(); //store index so when page redraws we can get the last item we checked. if (clearItems) this->selectedTitles = {}; + std::string text_colour = "colour.main_text"_theme; this->menu->ClearItems(); for (auto& url : this->ourTitles) { std::string itm = inst::util::shortenString(inst::util::formatUrlString(url), 56, true); auto ourEntry = pu::ui::elm::MenuItem::New(itm); - ourEntry->SetColor(COLOR("#FFFFFFFF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) ourEntry->SetColor(COLOR(text_colour)); + else ourEntry->SetColor(COLOR("#FFFFFFFF")); + ourEntry->SetIcon("romfs:/images/icons/checkbox-blank-outline.png"); for (long unsigned int i = 0; i < this->selectedTitles.size(); i++) { if (this->selectedTitles[i] == url) { @@ -65,6 +106,7 @@ namespace inst::ui { void usbInstPage::drawMenuItems(bool clearItems) { int myindex = this->menu->GetSelectedIndex(); //store index so when page redraws we can get the last item we checked. if (clearItems) this->selectedTitles = {}; + std::string text_colour = "colour.main_text"_theme; this->menu->ClearItems(); for (auto& url : this->ourTitles) { @@ -75,8 +117,11 @@ namespace inst::ui { //std::string itm = inst::util::shortenString(inst::util::formatUrlString(url), 56, true); auto ourEntry = pu::ui::elm::MenuItem::New(itm); - ourEntry->SetColor(COLOR("#FFFFFFFF")); + + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json")) ourEntry->SetColor(COLOR(text_colour)); + else ourEntry->SetColor(COLOR("#FFFFFFFF")); ourEntry->SetIcon("romfs:/images/icons/checkbox-blank-outline.png"); + for (long unsigned int i = 0; i < this->selectedTitles.size(); i++) { if (this->selectedTitles[i] == url) { ourEntry->SetIcon("romfs:/images/icons/check-box-outline.png"); @@ -125,11 +170,17 @@ namespace inst::ui { void usbInstPage::startInstall() { int dialogResult = -1; + + std::string install = "romfs:/images/icons/install.png"; + if (inst::config::useTheme && std::filesystem::exists(inst::config::appDir + "/theme/theme.json") && std::filesystem::exists(inst::config::appDir + "icons_others.install"_theme)){ + install = inst::config::appDir + "icons_others.install"_theme; + } + if (this->selectedTitles.size() == 1) { - dialogResult = mainApp->CreateShowDialog("inst.target.desc0"_lang + ":\n\n" + inst::util::shortenString(std::filesystem::path(this->selectedTitles[0]).filename().string(), 32, true) + "\n\n" + "inst.target.desc1"_lang, "\n\n\n\n\n\n\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, "romfs:/images/icons/install.png"); + dialogResult = mainApp->CreateShowDialog("inst.target.desc0"_lang + ":\n\n" + inst::util::shortenString(std::filesystem::path(this->selectedTitles[0]).filename().string(), 32, true) + "\n\n" + "inst.target.desc1"_lang, "\n\n\n\n\n\n\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, install); } //else dialogResult = mainApp->CreateShowDialog("inst.target.desc00"_lang + std::to_string(this->selectedTitles.size()) + "inst.target.desc01"_lang, "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false); - else dialogResult = mainApp->CreateShowDialog("inst.target.desc00"_lang + std::to_string(this->selectedTitles.size()) + "inst.target.desc01"_lang, "\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, "romfs:/images/icons/install.png"); + else dialogResult = mainApp->CreateShowDialog("inst.target.desc00"_lang + std::to_string(this->selectedTitles.size()) + "inst.target.desc01"_lang, "\n" + "common.cancel_desc"_lang, { "inst.target.opt0"_lang, "inst.target.opt1"_lang }, false, install); if (dialogResult == -1) return; usbInstStuff::installTitleUsb(this->selectedTitles, dialogResult); return; diff --git a/source/util/curl.cpp b/source/util/curl.cpp index 96b2bea..204546d 100644 --- a/source/util/curl.cpp +++ b/source/util/curl.cpp @@ -18,6 +18,7 @@ static size_t writeDataFile(void* ptr, size_t size, size_t nmemb, void* stream) size_t writeDataBuffer(char* ptr, size_t size, size_t nmemb, void* userdata) { std::ostringstream* stream = (std::ostringstream*)userdata; + //std::ofstream* stream = (std::ofstream*)userdata; size_t count = size * nmemb; stream->write(ptr, count); return count; @@ -92,6 +93,7 @@ namespace inst::curl { } std::string downloadToBuffer(const std::string ourUrl, int firstRange, int secondRange, long timeout) { + //https://www.php.net/manual/en/function.curl-setopt.php CURL* curl_handle; CURLcode result; std::ostringstream stream; @@ -99,6 +101,13 @@ namespace inst::curl { curl_global_init(CURL_GLOBAL_ALL); curl_handle = curl_easy_init(); + + curl_easy_setopt(curl_handle, CURLOPT_BUFFERSIZE, 240000L); + curl_easy_setopt(curl_handle, CURLOPT_ENCODING, "" ); + curl_easy_setopt(curl_handle, CURLOPT_TCP_FASTOPEN, 1L); + curl_easy_setopt(curl_handle, CURLOPT_STREAM_WEIGHT, 256L); + curl_easy_setopt(curl_handle, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(curl_handle, CURLOPT_MAX_RECV_SPEED_LARGE, 1L); curl_easy_setopt(curl_handle, CURLOPT_URL, url); curl_easy_setopt(curl_handle, CURLOPT_REFERER, url); @@ -111,6 +120,7 @@ namespace inst::curl { curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, timeout); curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, timeout); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeDataBuffer); + //curl_easy_setopt(curl_handle, CURLOPT_STDERR, fopen("sdmc://curl.txt", "a+")); if (firstRange && secondRange) { const char* ourRange = (std::to_string(firstRange) + "-" + std::to_string(secondRange)).c_str(); curl_easy_setopt(curl_handle, CURLOPT_RANGE, ourRange);