diff --git a/include/util/config.hpp b/include/util/config.hpp index db20eb2..0efdb08 100755 --- a/include/util/config.hpp +++ b/include/util/config.hpp @@ -1,7 +1,7 @@ #pragma once #include -namespace config { +namespace inst::config { extern const std::string appDir; extern const std::string configPath; extern bool ignoreReqVers; diff --git a/include/util/curl.hpp b/include/util/curl.hpp index 7538d83..0f74673 100755 --- a/include/util/curl.hpp +++ b/include/util/curl.hpp @@ -1,5 +1,5 @@ #include -namespace curlStuff { +namespace inst::curl { bool downloadFile(const std::string ourUrl, const char *pagefilename); } \ No newline at end of file diff --git a/include/util/unzip.hpp b/include/util/unzip.hpp index 1929551..291210a 100755 --- a/include/util/unzip.hpp +++ b/include/util/unzip.hpp @@ -1,5 +1,6 @@ #include +#include -namespace zipStuff { +namespace inst::zip { bool extractFile(const std::string filename, const std::string destination); } \ No newline at end of file diff --git a/include/util/util.hpp b/include/util/util.hpp index cf670ad..5655018 100755 --- a/include/util/util.hpp +++ b/include/util/util.hpp @@ -2,10 +2,11 @@ #include #include -namespace util { +namespace inst::util { void initApp (); void deinitApp (); std::vector getDirectoryFiles(const std::string & dir, const std::vector & extensions); bool removeDirectory(std::string dir); bool copyFile(std::string inFile, std::string outFile); + std::string formatUrlString(std::string ourString); } \ No newline at end of file diff --git a/source/install/http_nsp.cpp b/source/install/http_nsp.cpp index 6bfa797..31c2f48 100755 --- a/source/install/http_nsp.cpp +++ b/source/install/http_nsp.cpp @@ -7,6 +7,7 @@ #include "util/error.hpp" #include "util/debug.h" #include "nspInstall.hpp" +#include "util/util.hpp" namespace tin::install::nsp { @@ -104,7 +105,7 @@ namespace tin::install::nsp int downloadProgress = (int)(((double)bufferedPlaceholderWriter.GetSizeBuffered() / (double)bufferedPlaceholderWriter.GetTotalDataSize()) * 100.0); printf("> Download Progress: %lu/%lu MB (%i%s) (%.2f MB/s)\r", downloadSizeMB, totalSizeMB, downloadProgress, "%", speed); - inst::ui::setInstInfoText("Downloading " + ncaFileName + " at " + std::to_string(speed).substr(0, std::to_string(speed).size()-4) + "MB/s"); + inst::ui::setInstInfoText("Downloading " + inst::util::formatUrlString(ncaFileName) + " at " + std::to_string(speed).substr(0, std::to_string(speed).size()-4) + "MB/s"); inst::ui::setInstBarPerc((double)downloadProgress); //consoleUpdate(NULL); } diff --git a/source/main.cpp b/source/main.cpp index 9597c93..3c6243f 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -6,7 +6,7 @@ using namespace pu::ui::render; int main(int argc, char* argv[]) { - util::initApp(); + inst::util::initApp(); try { auto renderer = Renderer::New(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER, RendererInitOptions::RendererNoSound, RendererHardwareFlags); @@ -24,6 +24,6 @@ int main(int argc, char* argv[]) kDown = hidKeysDown(CONTROLLER_P1_AUTO); } } - util::deinitApp(); + inst::util::deinitApp(); return 0; } diff --git a/source/netInstall.cpp b/source/netInstall.cpp index f461c53..c37054b 100755 --- a/source/netInstall.cpp +++ b/source/netInstall.cpp @@ -17,7 +17,8 @@ #include "ui/MainApplication.hpp" #include "netInstall.hpp" #include "nspInstall.hpp" -#include "config.hpp" +#include "util/config.hpp" +#include "util/util.hpp" const unsigned int MAX_URL_SIZE = 1024; const unsigned int MAX_URLS = 256; @@ -100,7 +101,7 @@ namespace netInstStuff{ printf("%s %s\n", "NSP_INSTALL_FROM", ourUrl.c_str()); // second var is ignoring required version --- add config for this - tin::install::nsp::RemoteNSPInstall install(m_destStorageId, config::ignoreReqVers, &httpNSP); + tin::install::nsp::RemoteNSPInstall install(m_destStorageId, inst::config::ignoreReqVers, &httpNSP); printf("%s\n", "NSP_INSTALL_PREPARING"); inst::ui::setInstInfoText("Preparing installation..."); @@ -108,7 +109,6 @@ namespace netInstStuff{ printf("Pre Install Records: \n"); // These crash sometimes, if they're not needed then don't worry about em //install.DebugPrintInstallData(); - inst::ui::setInstInfoText("Installing " + ourUrl + "..."); install.Begin(); printf("Post Install Records: \n"); //install.DebugPrintInstallData(); @@ -119,7 +119,7 @@ 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(ourUrl + " installed!", "", {"OK"}, true); + inst::ui::mainApp->CreateShowDialog(inst::util::formatUrlString(ourUrl) + " installed!", "", {"OK"}, true); } catch (std::exception& e) { printf("NSP_INSTALL_FAILED\n"); diff --git a/source/nspInstall.cpp b/source/nspInstall.cpp index d39de50..1297772 100755 --- a/source/nspInstall.cpp +++ b/source/nspInstall.cpp @@ -61,7 +61,7 @@ namespace nspInstStuff { fileSystem.OpenFileSystemWithId(path, FsFileSystemType_ApplicationPackage, 0); tin::install::nsp::SimpleFileSystem simpleFS(fileSystem, "/", path + "/"); //last arg is ignore required firm version, read from config for this - tin::install::nsp::NSPInstallTask task(simpleFS, m_destStorageId, config::ignoreReqVers); + tin::install::nsp::NSPInstallTask task(simpleFS, m_destStorageId, inst::config::ignoreReqVers); printf("NSP_INSTALL_PREPARING\n"); inst::ui::setInstInfoText("Preparing installation..."); @@ -75,7 +75,6 @@ namespace nspInstStuff { //tin::util::PrintTextCentred(ss.str()); //manager.m_printConsole->flags &= ~CONSOLE_COLOR_BOLD; - inst::ui::setInstInfoText("Installing " + ourNsp + "..."); task.Begin(); printf("Post Install Records: \n"); //task.DebugPrintInstallData(); diff --git a/source/sigInstall.cpp b/source/sigInstall.cpp index e66832b..23c6be4 100755 --- a/source/sigInstall.cpp +++ b/source/sigInstall.cpp @@ -12,13 +12,13 @@ namespace sig { void installSigPatches () { int ourResult = inst::ui::mainApp->CreateShowDialog("Install signature patches?", "Signature patches are required for installing and playing NSP contents!", {"Install", "Uninstall", "Cancel"}, true); if (ourResult == 0) { - if (!util::copyFile("sdmc:/bootloader/patches.ini", "sdmc:/bootloader/patches.ini.old")) { + if (!inst::util::copyFile("sdmc:/bootloader/patches.ini", "sdmc:/bootloader/patches.ini.old")) { if (inst::ui::mainApp->CreateShowDialog("Could not back up old Hekate patches.ini! Install anyway?", "", {"Yes", "No"}, false)) return; } - std::string ourPath = config::appDir + "patches.zip"; - bool didDownload = curlStuff::downloadFile("http://github.com/Joonie86/hekate/releases/download/5.0.0J/Kosmos_patches_10_09_2019.zip", ourPath.c_str()); + std::string ourPath = inst::config::appDir + "patches.zip"; + bool didDownload = inst::curl::downloadFile("http://github.com/Joonie86/hekate/releases/download/5.0.0J/Kosmos_patches_10_09_2019.zip", ourPath.c_str()); bool didExtract = false; - if (didDownload) didExtract = zipStuff::extractFile(ourPath, "sdmc:/"); + if (didDownload) didExtract = inst::zip::extractFile(ourPath, "sdmc:/"); else { inst::ui::mainApp->CreateShowDialog("Could not download signature patches!", "Check your internet connection and try again", {"OK"}, true); return; @@ -31,10 +31,10 @@ namespace sig { } return; } else if (ourResult == 1) { - if (!util::copyFile( "sdmc:/bootloader/patches.ini.old", "sdmc:/bootloader/patches.ini")) { + if (!inst::util::copyFile( "sdmc:/bootloader/patches.ini.old", "sdmc:/bootloader/patches.ini")) { if (inst::ui::mainApp->CreateShowDialog("Unable to restore original Hekate patches.ini! Continue uninstalling?", "", {"Yes", "No"}, false)) return; } else std::filesystem::remove("sdmc:/bootloader/patches.ini.old"); - if (util::removeDirectory("sdmc:/atmosphere/exefs_patches/es_patches")) inst::ui::mainApp->CreateShowDialog("Uninstall complete", "Restart your console to apply", {"OK"}, true); + if (inst::util::removeDirectory("sdmc:/atmosphere/exefs_patches/es_patches")) inst::ui::mainApp->CreateShowDialog("Uninstall complete", "Restart your console to apply", {"OK"}, true); else inst::ui::mainApp->CreateShowDialog("Unable to remove signature patches", "Files may have been renamed or deleted", {"OK"}, true); } else return; } diff --git a/source/ui/mainPage.cpp b/source/ui/mainPage.cpp index a10c0b6..2d86b06 100755 --- a/source/ui/mainPage.cpp +++ b/source/ui/mainPage.cpp @@ -36,7 +36,7 @@ namespace inst::ui { } void MainPage::installMenuItem_Click() { - if (util::getDirectoryFiles("sdmc:/", {".nsp"}).size()) { + if (inst::util::getDirectoryFiles("sdmc:/", {".nsp"}).size()) { mainApp->LoadLayout(mainApp->nspinstPage); } else { mainApp->CreateShowDialog("No NSP files found!", "NSPs can be placed on the root of your SD card!", {"OK"}, true); diff --git a/source/ui/netInstPage.cpp b/source/ui/netInstPage.cpp index 704ee10..3eade89 100755 --- a/source/ui/netInstPage.cpp +++ b/source/ui/netInstPage.cpp @@ -37,7 +37,7 @@ namespace inst::ui { } else { this->pageInfoText->SetText("Select a NSP to install! Press B to cancel!"); for (auto& url: ourUrls) { - pu::String itm = url; + pu::String itm = inst::util::formatUrlString(url); auto ourEntry = pu::ui::elm::MenuItem::New(itm); ourEntry->SetColor(COLOR("#FFFFFFFF")); this->menu->AddItem(ourEntry); @@ -49,7 +49,7 @@ namespace inst::ui { void netInstPage::startInstall() { std::string ourUrl = ourUrls[this->menu->GetSelectedIndex()]; - int dialogResult = mainApp->CreateShowDialog("Where should " + ourUrl + " be installed to?", "Press B to cancel", {"SD", "Internal Storage"}, false); + int dialogResult = mainApp->CreateShowDialog("Where should " + inst::util::formatUrlString(ourUrl) + " be installed to?", "Press B to cancel", {"SD", "Internal Storage"}, false); if (dialogResult == -1) return; netInstStuff::installNspLan(ourUrl, dialogResult); return; diff --git a/source/util/config.cpp b/source/util/config.cpp index a788f88..023c3e1 100755 --- a/source/util/config.cpp +++ b/source/util/config.cpp @@ -3,23 +3,23 @@ #include "util/INIReader.h" #include "config.hpp" -namespace config { +namespace inst::config { const std::string appDir = "sdmc:/switch/Awoo-Installer"; const std::string configPath = appDir + "/config.ini"; bool ignoreReqVers = true; bool gayMode = false; void parseConfig() { - INIReader reader(config::configPath); - config::ignoreReqVers = reader.GetBoolean("settings", "ignoreReqVers", true); - config::gayMode = reader.GetBoolean("settings", "gayMode", false); + INIReader reader(inst::config::configPath); + inst::config::ignoreReqVers = reader.GetBoolean("settings", "ignoreReqVers", true); + inst::config::gayMode = reader.GetBoolean("settings", "gayMode", false); return ; } void setConfig() { - std::filesystem::remove(config::appDir); - std::string data("[settings]\nignoreReqVers=" + std::to_string(config::ignoreReqVers) + "\ngayMode=" + std::to_string(config::gayMode) + "\n"); - FILE * configFile = fopen(config::appDir.c_str(), "w"); + std::filesystem::remove(inst::config::configPath); + std::string data("[settings]\nignoreReqVers=" + std::to_string(inst::config::ignoreReqVers) + "\ngayMode=" + std::to_string(inst::config::gayMode) + "\n"); + FILE * configFile = fopen(inst::config::configPath.c_str(), "w"); fwrite(data.c_str(), sizeof(char), data.size(), configFile); fflush(configFile); fsync(fileno(configFile)); diff --git a/source/util/curl.cpp b/source/util/curl.cpp index a1f01b0..5376a45 100755 --- a/source/util/curl.cpp +++ b/source/util/curl.cpp @@ -7,7 +7,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { return written; } -namespace curlStuff { +namespace inst::curl { bool downloadFile (const std::string ourUrl, const char *pagefilename) { CURL *curl_handle; CURLcode result; diff --git a/source/util/unzip.cpp b/source/util/unzip.cpp index 891dd18..e420765 100755 --- a/source/util/unzip.cpp +++ b/source/util/unzip.cpp @@ -110,7 +110,7 @@ int _extractFile(const char * path, unzFile unz, unz_file_info_s * fileInfo) { return 0; } -namespace zipStuff { +namespace inst::zip { bool extractFile(const std::string filename, const std::string destination) { unzFile unz = unzOpen(filename.c_str()); diff --git a/source/util/util.cpp b/source/util/util.cpp index acc3d92..72e8a58 100755 --- a/source/util/util.cpp +++ b/source/util/util.cpp @@ -3,17 +3,19 @@ #include #include #include +#include #include "switch.h" #include "util/util.hpp" #include "nx/ipc/tin_ipc.h" #include "util/INIReader.h" -#include "config.hpp" +#include "util/config.hpp" -namespace util { +namespace inst::util { void initApp () { if (!std::filesystem::exists("sdmc:/switch")) std::filesystem::create_directory("sdmc:/switch"); - if (!std::filesystem::exists(config::appDir)) std::filesystem::create_directory(config::appDir); - config::parseConfig(); + if (!std::filesystem::exists(inst::config::appDir)) std::filesystem::create_directory(inst::config::appDir); + if (std::filesystem::exists(inst::config::configPath)) inst::config::parseConfig(); + else inst::config::setConfig(); socketInitializeDefault(); #ifdef __DEBUG__ @@ -81,4 +83,21 @@ namespace util { while(f1 && f1.get(ch)) f2.put(ch); return true; } + + std::string formatUrlString(std::string ourString) { + std::stringstream ourStream(ourString); + std::string segment; + std::vector seglist; + + while(std::getline(ourStream, segment, '/')) { + seglist.push_back(segment); + } + + CURL *curl = curl_easy_init(); + int outlength; + std::string finalString = curl_easy_unescape(curl, seglist[seglist.size() - 1].c_str(), seglist[seglist.size() - 1].length(), &outlength); + curl_easy_cleanup(curl); + + return finalString; + } } \ No newline at end of file