mirror of
https://github.com/Huntereb/Awoo-Installer
synced 2024-11-10 14:14:21 +00:00
String shortening when needed
This commit is contained in:
parent
9a42a05a3f
commit
074491ff0e
7 changed files with 20 additions and 10 deletions
|
@ -9,4 +9,5 @@ namespace inst::util {
|
|||
bool removeDirectory(std::string dir);
|
||||
bool copyFile(std::string inFile, std::string outFile);
|
||||
std::string formatUrlString(std::string ourString);
|
||||
std::string shortenString(std::string ourString, int ourLength, bool isFile);
|
||||
}
|
|
@ -120,14 +120,14 @@ namespace netInstStuff{
|
|||
// Send 1 byte ack to close the server
|
||||
u8 ack = 0;
|
||||
tin::network::WaitSendNetworkData(m_clientSocket, &ack, sizeof(u8));
|
||||
inst::ui::mainApp->CreateShowDialog(inst::util::formatUrlString(ourUrl) + " installed!", "", {"OK"}, true);
|
||||
inst::ui::mainApp->CreateShowDialog(inst::util::shortenString(inst::util::formatUrlString(ourUrl), 64, true) + " installed!", "", {"OK"}, true);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
printf("NSP_INSTALL_FAILED\n");
|
||||
printf("Failed to install NSP");
|
||||
printf("%s", e.what());
|
||||
fprintf(stdout, "%s", e.what());
|
||||
inst::ui::mainApp->CreateShowDialog("Failed to install NSP!", (std::string)e.what(), {"OK"}, true);
|
||||
inst::ui::mainApp->CreateShowDialog("Failed to install NSP!", "Partially installed NSP contents can be removed from the System Settings applet.\n\n" + (std::string)e.what(), {"OK"}, true);
|
||||
}
|
||||
|
||||
printf("Done");
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
#include "nspInstall.hpp"
|
||||
#include "ui/MainApplication.hpp"
|
||||
#include "config.hpp"
|
||||
#include "util/config.hpp"
|
||||
#include "util/util.hpp"
|
||||
|
||||
namespace inst::ui {
|
||||
extern MainApplication *mainApp;
|
||||
|
@ -93,11 +94,11 @@ namespace nspInstStuff {
|
|||
printf("Failed to install NSP");
|
||||
printf("%s", e.what());
|
||||
fprintf(stdout, "%s", e.what());
|
||||
inst::ui::mainApp->CreateShowDialog("Failed to install NSP!", (std::string)e.what(), {"OK"}, true);
|
||||
inst::ui::mainApp->CreateShowDialog("Failed to install NSP!", "Partially installed NSP contents can be removed from the System Settings applet.\n\n" + (std::string)e.what(), {"OK"}, true);
|
||||
}
|
||||
}
|
||||
|
||||
if(nspInstalled) if(inst::ui::mainApp->CreateShowDialog(ourNsp + " installed! Delete NSP from SD card?", "", {"No","Yes"}, false) == 1) std::filesystem::remove("sdmc:/" + ourNsp);
|
||||
if(nspInstalled) if(inst::ui::mainApp->CreateShowDialog(inst::util::shortenString(ourNsp, 64, true) + " installed! Delete NSP from SD card?", "", {"No","Yes"}, false) == 1) std::filesystem::remove("sdmc:/" + ourNsp);
|
||||
|
||||
printf("Done");
|
||||
appletUnlockExit();
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace inst::ui {
|
|||
this->pageInfoText->SetText("Select a NSP to install!");
|
||||
this->butText->SetText("(A)-Install NSP (B)-Cancel");
|
||||
for (auto& url: ourUrls) {
|
||||
pu::String itm = inst::util::formatUrlString(url);
|
||||
pu::String itm = inst::util::shortenString(inst::util::formatUrlString(url), 64, true);
|
||||
auto ourEntry = pu::ui::elm::MenuItem::New(itm);
|
||||
ourEntry->SetColor(COLOR("#FFFFFFFF"));
|
||||
ourEntry->SetIcon("romfs:/package-down.png");
|
||||
|
@ -82,7 +82,7 @@ namespace inst::ui {
|
|||
|
||||
void netInstPage::startInstall(bool urlMode) {
|
||||
std::string ourUrl = ourUrls[this->menu->GetSelectedIndex()];
|
||||
int dialogResult = mainApp->CreateShowDialog("Where should " + inst::util::formatUrlString(ourUrl) + " be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
int dialogResult = mainApp->CreateShowDialog("Where should " + inst::util::shortenString(inst::util::formatUrlString(ourUrl), 64, true) + " be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
if (dialogResult == -1 && !urlMode) return;
|
||||
else if (dialogResult == -1 && urlMode) {
|
||||
mainApp->LoadLayout(mainApp->mainPage);
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace inst::ui {
|
|||
this->menu->SetScrollbarColor(COLOR("#17090980"));
|
||||
ourFiles = util::getDirectoryFiles("sdmc:/", {".nsp"});
|
||||
for (auto& file: ourFiles) {
|
||||
pu::String itm = file.string().erase(0, 6);
|
||||
pu::String itm = inst::util::shortenString(file.string().erase(0, 6), 64, true);
|
||||
auto ourEntry = pu::ui::elm::MenuItem::New(itm);
|
||||
ourEntry->SetColor(COLOR("#FFFFFFFF"));
|
||||
ourEntry->SetIcon("romfs:/package.png");
|
||||
|
@ -45,7 +45,7 @@ namespace inst::ui {
|
|||
|
||||
void nspInstPage::startInstall() {
|
||||
std::string ourNsp = ourFiles[this->menu->GetSelectedIndex()].string().erase(0, 6);
|
||||
int dialogResult = mainApp->CreateShowDialog("Where should " + ourNsp + " be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
int dialogResult = mainApp->CreateShowDialog("Where should " + inst::util::shortenString(ourNsp, 64, true) + " be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
if (dialogResult == -1) return;
|
||||
nspInstStuff::installNspFromFile(ourNsp, dialogResult);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace inst::ui {
|
|||
gayModeOption->SetColor(COLOR("#FFFFFFFF"));
|
||||
gayModeOption->SetIcon(optionsPage::getMenuOptionIcon(inst::config::gayMode));
|
||||
this->menu->AddItem(gayModeOption);
|
||||
auto sigPatchesUrlOption = pu::ui::elm::MenuItem::New(ourMenuEntries[2] + inst::config::sigPatchesUrl);
|
||||
auto sigPatchesUrlOption = pu::ui::elm::MenuItem::New(ourMenuEntries[2] + inst::util::shortenString(inst::config::sigPatchesUrl, 42, false));
|
||||
sigPatchesUrlOption->SetColor(COLOR("#FFFFFFFF"));
|
||||
this->menu->AddItem(sigPatchesUrlOption);
|
||||
auto creditsOption = pu::ui::elm::MenuItem::New("Credits");
|
||||
|
|
|
@ -100,4 +100,12 @@ namespace inst::util {
|
|||
|
||||
return finalString;
|
||||
}
|
||||
|
||||
std::string shortenString(std::string ourString, int ourLength, bool isFile) {
|
||||
std::filesystem::path ourStringAsAPath = ourString;
|
||||
if (ourString.size() > (unsigned long)ourLength) {
|
||||
if(isFile) return (std::string)ourString.substr(0,ourLength) + "(...)" + ourStringAsAPath.extension().string();
|
||||
else return (std::string)ourString.substr(0,ourLength) + "...";
|
||||
} else return ourString;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue