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

95 lines
3.3 KiB
C++
Raw Normal View History

2019-10-23 00:14:37 +02:00
#include <cstring>
#include <sstream>
#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"
namespace inst::ui {
extern MainApplication *mainApp;
2019-10-24 21:53:54 +02:00
void setInstInfoText(std::string ourText){
mainApp->instpage->pageInfoText->SetText(ourText);
2019-10-23 00:14:37 +02:00
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->installBar->SetProgress(0);
mainApp->instpage->installBar->SetVisible(false);
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
{
2019-10-24 21:53:54 +02:00
inst::ui::loadInstallScreen();
2019-10-23 00:14:37 +02:00
std::vector<std::string> installList;
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
{
nx::fs::IFileSystem fileSystem;
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, 1);
printf("NSP_INSTALL_PREPARING\n");
2019-10-24 21:53:54 +02:00
inst::ui::setInstInfoText("Preparing installation...");
2019-10-23 00:14:37 +02: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;
2019-10-24 21:53:54 +02:00
inst::ui::setInstInfoText("Installing " + ourNsp + "...");
2019-10-23 00:14:37 +02:00
task.Begin();
printf("Post Install Records: \n");
//task.DebugPrintInstallData();
2019-10-24 21:53:54 +02:00
inst::ui::mainApp->CreateShowDialog(ourNsp + " installed!", "", {"OK"}, true);
2019-10-23 00:14:37 +02: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-23 00:14:37 +02:00
}
}
printf("Done");
inst::ui::loadMainMenu();
2019-10-24 21:53:54 +02:00
return;
2019-10-23 00:14:37 +02:00
}
}