mirror of
https://github.com/Huntereb/Awoo-Installer
synced 2024-11-25 13:10:22 +00:00
better namespaces, more config stuff, url decoding strings
This commit is contained in:
parent
0c3a7120cf
commit
2700f478ce
15 changed files with 56 additions and 35 deletions
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace config {
|
||||
namespace inst::config {
|
||||
extern const std::string appDir;
|
||||
extern const std::string configPath;
|
||||
extern bool ignoreReqVers;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <string>
|
||||
|
||||
namespace curlStuff {
|
||||
namespace inst::curl {
|
||||
bool downloadFile(const std::string ourUrl, const char *pagefilename);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include <minizip/unzip.h>
|
||||
#include <string>
|
||||
|
||||
namespace zipStuff {
|
||||
namespace inst::zip {
|
||||
bool extractFile(const std::string filename, const std::string destination);
|
||||
}
|
|
@ -2,10 +2,11 @@
|
|||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
namespace util {
|
||||
namespace inst::util {
|
||||
void initApp ();
|
||||
void deinitApp ();
|
||||
std::vector<std::filesystem::path> getDirectoryFiles(const std::string & dir, const std::vector<std::string> & extensions);
|
||||
bool removeDirectory(std::string dir);
|
||||
bool copyFile(std::string inFile, std::string outFile);
|
||||
std::string formatUrlString(std::string ourString);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -3,17 +3,19 @@
|
|||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
#include <curl/curl.h>
|
||||
#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<std::string> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue