This repository has been archived on 2021-12-25. You can view files and clone it, but cannot push or open issues or pull requests.
Awoo-Installer/source/nspInstall.cpp

101 lines
3.4 KiB
C++
Raw Normal View History

2019-10-23 00:14:37 +02:00
#include <cstring>
#include <sstream>
#include <filesystem>
2019-10-23 00:14:37 +02:00
#include "install/install_nsp.hpp"
#include "nx/fs.hpp"
#include "util/file_util.hpp"
#include "util/title_util.hpp"
#include "util/error.hpp"
#include "ui/MainApplication.hpp"
#include "nspInstall.hpp"
2019-10-29 00:47:49 +01:00
#include "util/config.hpp"
#include "util/util.hpp"
2019-10-23 00:14:37 +02:00
namespace inst::ui {
extern MainApplication *mainApp;
void setTopInstInfoText(std::string ourText){
2019-10-24 21:53:54 +02:00
mainApp->instpage->pageInfoText->SetText(ourText);
2019-10-23 00:14:37 +02:00
mainApp->CallForRender();
}
void setInstInfoText(std::string ourText){
mainApp->instpage->installInfoText->SetText(ourText);
mainApp->CallForRender();
}
void setInstBarPerc(double ourPercent){
mainApp->instpage->installBar->SetVisible(true);
mainApp->instpage->installBar->SetProgress(ourPercent);
mainApp->CallForRender();
}
2019-10-23 00:14:37 +02:00
void loadMainMenu(){
mainApp->LoadLayout(mainApp->mainPage);
}
2019-10-24 21:53:54 +02:00
void loadInstallScreen(){
mainApp->instpage->pageInfoText->SetText("");
mainApp->instpage->installInfoText->SetText("");
mainApp->instpage->installBar->SetProgress(0);
mainApp->instpage->installBar->SetVisible(false);
if (inst::config::gayMode) mainApp->instpage->awooImage->SetVisible(false);
else mainApp->instpage->awooImage->SetVisible(true);
2019-10-24 21:53:54 +02:00
mainApp->LoadLayout(mainApp->instpage);
mainApp->CallForRender();
}
2019-10-23 00:14:37 +02:00
}
namespace nspInstStuff {
FsStorageId m_destStorageId = FsStorageId_SdCard;
2019-10-24 21:53:54 +02:00
void installNspFromFile(std::string ourNsp, int whereToInstall)
2019-10-23 00:14:37 +02:00
{
appletLockExit();
2019-10-24 21:53:54 +02:00
inst::ui::loadInstallScreen();
2019-10-23 00:14:37 +02:00
std::vector<std::string> installList;
bool nspInstalled = false;
2019-10-23 00:14:37 +02:00
installList.push_back(ourNsp);
if (whereToInstall) m_destStorageId = FsStorageId_NandUser;
2019-10-23 00:14:37 +02:00
for (unsigned int i = 0; i < installList.size(); i++)
{
std::string path = "@Sdcard://" + installList[i];
try
{
inst::ui::setTopInstInfoText("Installing " + ourNsp + "...");
2019-10-23 00:14:37 +02:00
nx::fs::IFileSystem fileSystem;
fileSystem.OpenFileSystemWithId(path, FsFileSystemType_ApplicationPackage, 0);
tin::install::nsp::SimpleFileSystem simpleFS(fileSystem, "/", path + "/");
tin::install::nsp::NSPInstallTask task(simpleFS, m_destStorageId, inst::config::ignoreReqVers);
2019-10-23 00:14:37 +02:00
printf("Preparing installation\n");
2019-10-24 21:53:54 +02:00
inst::ui::setInstInfoText("Preparing installation...");
2019-10-23 00:14:37 +02:00
task.Prepare();
task.Begin();
nspInstalled = true;
2019-10-23 00:14:37 +02:00
}
catch (std::exception& e)
{
printf("Failed to install NSP");
printf("%s", e.what());
fprintf(stdout, "%s", e.what());
2019-10-29 00:47:49 +01:00
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);
2019-10-23 00:14:37 +02:00
}
}
2019-10-29 00:47:49 +01:00
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);
2019-10-23 00:14:37 +02:00
printf("Done");
appletUnlockExit();
inst::ui::loadMainMenu();
2019-10-24 21:53:54 +02:00
return;
2019-10-23 00:14:37 +02:00
}
}