Awoo-Installer/source/nspInstall.cpp

108 lines
3.7 KiB
C++
Raw Normal View History

2019-10-22 22:14:37 +00:00
#include <cstring>
#include <sstream>
#include <filesystem>
2019-10-22 22:14:37 +00: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 "nspInstall.hpp"
#include "ui/MainApplication.hpp"
2019-10-26 04:38:12 +00:00
#include "config.hpp"
2019-10-22 22:14:37 +00:00
namespace inst::ui {
extern MainApplication *mainApp;
void setTopInstInfoText(std::string ourText){
2019-10-24 19:53:54 +00:00
mainApp->instpage->pageInfoText->SetText(ourText);
2019-10-22 22:14:37 +00: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-22 22:14:37 +00:00
void loadMainMenu(){
mainApp->LoadLayout(mainApp->mainPage);
}
2019-10-24 19:53:54 +00:00
void loadInstallScreen(){
mainApp->instpage->pageInfoText->SetText("");
mainApp->instpage->installInfoText->SetText("");
mainApp->instpage->installBar->SetProgress(0);
mainApp->instpage->installBar->SetVisible(false);
2019-10-24 19:53:54 +00:00
mainApp->LoadLayout(mainApp->instpage);
mainApp->CallForRender();
}
2019-10-22 22:14:37 +00:00
}
namespace nspInstStuff {
FsStorageId m_destStorageId = FsStorageId_SdCard;
2019-10-24 19:53:54 +00:00
void installNspFromFile(std::string ourNsp, int whereToInstall)
2019-10-22 22:14:37 +00:00
{
appletLockExit();
2019-10-24 19:53:54 +00:00
inst::ui::loadInstallScreen();
2019-10-22 22:14:37 +00:00
std::vector<std::string> installList;
bool nspInstalled = false;
2019-10-22 22:14:37 +00:00
installList.push_back(ourNsp);
if (whereToInstall) m_destStorageId = FsStorageId_NandUser;
2019-10-22 22:14:37 +00:00
for (unsigned int i = 0; i < installList.size(); i++)
{
std::string path = "@Sdcard://" + installList[i];
try
{
inst::ui::setTopInstInfoText("Installing " + ourNsp + "...");
2019-10-22 22:14:37 +00: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-22 22:14:37 +00:00
printf("NSP_INSTALL_PREPARING\n");
2019-10-24 19:53:54 +00:00
inst::ui::setInstInfoText("Preparing installation...");
2019-10-22 22:14:37 +00:00
task.Prepare();
printf("Pre Install Records: \n");
//task.DebugPrintInstallData();
//std::stringstream ss;
//ss << translate(Translate::NSP_INSTALLING) << " " << tin::util::GetTitleName(task.GetTitleId(), task.GetContentMetaType()) << " (" << (i + 1) << "/" << installList.size() << ")";
//manager.m_printConsole->flags |= CONSOLE_COLOR_BOLD;
//tin::util::PrintTextCentred(ss.str());
//manager.m_printConsole->flags &= ~CONSOLE_COLOR_BOLD;
task.Begin();
printf("Post Install Records: \n");
//task.DebugPrintInstallData();
nspInstalled = true;
2019-10-22 22:14:37 +00:00
}
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);
2019-10-22 22:14:37 +00:00
}
}
if(nspInstalled) if(inst::ui::mainApp->CreateShowDialog(ourNsp + " installed! Delete NSP from SD card?", "", {"No","Yes"}, false) == 1) std::filesystem::remove("sdmc:/" + ourNsp);
2019-10-22 22:14:37 +00:00
printf("Done");
appletUnlockExit();
inst::ui::loadMainMenu();
2019-10-24 19:53:54 +00:00
return;
2019-10-22 22:14:37 +00:00
}
}