Add install info page

This commit is contained in:
Huntereb 2019-10-24 15:53:54 -04:00
parent 021e4f4d63
commit 049004bea4
10 changed files with 112 additions and 55 deletions

View File

@ -1,4 +1,4 @@
namespace netInstStuff {
bool installNspLan(std::string ourUrl, int ourStorage);
void installNspLan(std::string ourUrl, int ourStorage);
std::vector<std::string> OnSelected();
}

View File

@ -1,11 +1,12 @@
#pragma once
#include <string>
namespace inst::ui {
void setNspInfoText(std::string ourText);
void setNetInfoText(std::string ourText);
void setInstInfoText(std::string ourText);
void loadMainMenu();
void loadInstallScreen();
}
namespace nspInstStuff {
bool installNspFromFile(std::string ourNsp, int whereToInstall);
void installNspFromFile(std::string ourNsp, int whereToInstall);
}

View File

@ -3,6 +3,7 @@
#include "ui/mainPage.hpp"
#include "ui/netInstPage.hpp"
#include "ui/nspInstPage.hpp"
#include "ui/instPage.hpp"
namespace inst::ui {
class MainApplication : public pu::ui::Application {
@ -13,5 +14,6 @@ namespace inst::ui {
MainPage::Ref mainPage;
netInstPage::Ref netinstPage;
nspInstPage::Ref nspinstPage;
instPage::Ref instpage;
};
}

16
include/ui/instPage.hpp Executable file
View File

@ -0,0 +1,16 @@
#pragma once
#include <pu/Plutonium>
using namespace pu::ui::elm;
namespace inst::ui {
class instPage : public pu::ui::Layout
{
public:
instPage();
PU_SMART_CTOR(instPage)
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
TextBlock::Ref pageInfoText;
private:
TextBlock::Ref topText;
};
}

View File

@ -43,7 +43,7 @@ namespace netInstStuff{
if (m_serverSocket < -1)
{
inst::ui::setNetInfoText("Failed to create a server socket.");
inst::ui::mainApp->CreateShowDialog("Failed to create a server socket.", "", {"OK"}, true);
THROW_FORMAT("Failed to create a server socket. Error code: %u\n", errno);
}
@ -54,7 +54,7 @@ namespace netInstStuff{
if (bind(m_serverSocket, (struct sockaddr*) &server, sizeof(server)) < 0)
{
inst::ui::setNetInfoText("Failed to bind server socket.");
inst::ui::mainApp->CreateShowDialog("Failed to bind server socket.", "", {"OK"}, true);
THROW_FORMAT("Failed to bind server socket. Error code: %u\n", errno);
}
@ -63,13 +63,13 @@ namespace netInstStuff{
if (listen(m_serverSocket, 5) < 0)
{
inst::ui::setNetInfoText("Failed to listen on server socket.");
inst::ui::mainApp->CreateShowDialog("Failed to listen on server socket.", "", {"OK"}, true);
THROW_FORMAT("Failed to listen on server socket. Error code: %u\n", errno);
}
}
catch (std::exception& e)
{
inst::ui::setNetInfoText("Failed to initialize server socket!");
inst::ui::mainApp->CreateShowDialog("Failed to initialize server socket!", "", {"OK"}, true);
printf("Failed to initialize server socket!\n");
fprintf(stdout, "%s", e.what());
@ -92,34 +92,47 @@ namespace netInstStuff{
curl_global_cleanup();
}
bool installNspLan(std::string ourUrl, int ourStorage)
void installNspLan(std::string ourUrl, int ourStorage)
{
inst::ui::loadInstallScreen();
if (ourStorage) m_destStorageId = FsStorageId_NandUser;
tin::install::nsp::HTTPNSP httpNSP(ourUrl);
try {
tin::install::nsp::HTTPNSP httpNSP(ourUrl);
printf("%s %s\n", "NSP_INSTALL_FROM", ourUrl.c_str());
// second var is ignoring required version
tin::install::nsp::RemoteNSPInstall install(m_destStorageId, true, &httpNSP);
printf("%s %s\n", "NSP_INSTALL_FROM", ourUrl.c_str());
// second var is ignoring required version
tin::install::nsp::RemoteNSPInstall install(m_destStorageId, true, &httpNSP);
printf("%s\n", "NSP_INSTALL_PREPARING");
install.Prepare();
printf("Pre Install Records: \n");
// These crash sometimes, if they're not needed then don't worry about em
//install.DebugPrintInstallData();
inst::ui::setNetInfoText("Installing NSP for real right now. Figure out how to get percentages");
install.Begin();
printf("Post Install Records: \n");
//install.DebugPrintInstallData();
printf("\n");
printf("%s\n", "NSP_INSTALL_NETWORK_SENDING_ACK");
// Send 1 byte ack to close the server
u8 ack = 0;
tin::network::WaitSendNetworkData(m_clientSocket, &ack, sizeof(u8));
printf("%s\n", "NSP_INSTALL_PREPARING");
inst::ui::setInstInfoText("Preparing installation...");
install.Prepare();
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();
printf("\n");
printf("%s\n", "NSP_INSTALL_NETWORK_SENDING_ACK");
inst::ui::setInstInfoText("Sending acknowledgment of install to server...");
// 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);
}
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!", "", {"OK"}, true);
}
printf("Done");
inst::ui::loadMainMenu();
return true;
return;
}
std::vector<std::string> OnSelected()
@ -136,7 +149,7 @@ namespace netInstStuff{
if (m_serverSocket <= 0)
{
inst::ui::setNetInfoText("Server socket failed to initialize.");
inst::ui::mainApp->CreateShowDialog("Server socket failed to initialize.", "", {"OK"}, true);
THROW_FORMAT("Server socket failed to initialize.\n");
}
}
@ -161,7 +174,6 @@ namespace netInstStuff{
if (kDown & KEY_B)
{
inst::ui::loadMainMenu();
break;
}
@ -181,7 +193,7 @@ namespace netInstStuff{
if (size > MAX_URL_SIZE * MAX_URLS)
{
inst::ui::setNetInfoText("URL size is too large!");
inst::ui::mainApp->CreateShowDialog("URL size is too large!", "", {"OK"}, true);
THROW_FORMAT("URL size %x is too large!\n", size);
}
@ -206,7 +218,7 @@ namespace netInstStuff{
}
else if (errno != EAGAIN)
{
inst::ui::setNetInfoText("Failed to open client socket");
inst::ui::mainApp->CreateShowDialog("Failed to open client socket", "", {"OK"}, true);
THROW_FORMAT("Failed to open client socket with code %u\n", errno);
}
}
@ -216,7 +228,7 @@ namespace netInstStuff{
}
catch (std::runtime_error& e)
{
inst::ui::setNetInfoText("Failed to perform remote install!");
inst::ui::mainApp->CreateShowDialog("Failed to perform remote install!", "", {"OK"}, true);
printf("Failed to perform remote install!\n");
printf("%s", e.what());
fprintf(stdout, "%s", e.what());

View File

@ -12,21 +12,28 @@
namespace inst::ui {
extern MainApplication *mainApp;
void setNspInfoText(std::string ourText){
mainApp->nspinstPage->pageInfoText->SetText(ourText);
void setInstInfoText(std::string ourText){
mainApp->instpage->pageInfoText->SetText(ourText);
mainApp->CallForRender();
}
void loadMainMenu(){
mainApp->LoadLayout(mainApp->mainPage);
}
void loadInstallScreen(){
mainApp->instpage->pageInfoText->SetText("");
mainApp->LoadLayout(mainApp->instpage);
mainApp->CallForRender();
}
}
namespace nspInstStuff {
FsStorageId m_destStorageId = FsStorageId_SdCard;
bool installNspFromFile(std::string ourNsp, int whereToInstall)
void installNspFromFile(std::string ourNsp, int whereToInstall)
{
inst::ui::loadInstallScreen();
std::vector<std::string> installList;
installList.push_back(ourNsp);
@ -45,6 +52,7 @@ namespace nspInstStuff {
tin::install::nsp::NSPInstallTask task(simpleFS, m_destStorageId, 1);
printf("NSP_INSTALL_PREPARING\n");
inst::ui::setInstInfoText("Preparing installation...");
task.Prepare();
printf("Pre Install Records: \n");
//task.DebugPrintInstallData();
@ -55,24 +63,24 @@ namespace nspInstStuff {
//tin::util::PrintTextCentred(ss.str());
//manager.m_printConsole->flags &= ~CONSOLE_COLOR_BOLD;
inst::ui::setNspInfoText("Installing " + ourNsp + "...");
inst::ui::setInstInfoText("Installing " + ourNsp + "...");
task.Begin();
printf("Post Install Records: \n");
//task.DebugPrintInstallData();
inst::ui::mainApp->CreateShowDialog(ourNsp + " installed!", "", {"OK"}, true);
}
catch (std::exception& e)
{
inst::ui::setNspInfoText("Failed to install NSP");
printf("NSP_INSTALL_FAILED\n");
printf("Failed to install NSP");
printf("%s", e.what());
fprintf(stdout, "%s", e.what());
return false;
inst::ui::mainApp->CreateShowDialog("Failed to install NSP!", "", {"OK"}, true);
}
}
printf("Done");
inst::ui::loadMainMenu();
return true;
return;
}
}

View File

@ -9,9 +9,11 @@ namespace inst::ui {
this->mainPage = MainPage::New();
this->netinstPage = netInstPage::New();
this->nspinstPage = nspInstPage::New();
this->instpage = instPage::New();
this->mainPage->SetOnInput(std::bind(&MainPage::onInput, this->mainPage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
this->netinstPage->SetOnInput(std::bind(&netInstPage::onInput, this->netinstPage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
this->nspinstPage->SetOnInput(std::bind(&nspInstPage::onInput, this->nspinstPage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
this->instpage->SetOnInput(std::bind(&instPage::onInput, this->instpage, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
this->LoadLayout(this->mainPage);
}
}

24
source/ui/instPage.cpp Executable file
View File

@ -0,0 +1,24 @@
#include <filesystem>
#include "ui/MainApplication.hpp"
#include "ui/mainPage.hpp"
#include "ui/instPage.hpp"
#include "util.hpp"
#define COLOR(hex) pu::ui::Color::FromHex(hex)
namespace inst::ui {
extern MainApplication *mainApp;
instPage::instPage() : Layout::Layout() {
this->SetBackgroundColor(COLOR("#670000FF"));
this->topText = TextBlock::New(10, 2, "Awoo Installer", 35);
this->topText->SetColor(COLOR("#FFFFFFFF"));
this->pageInfoText = TextBlock::New(10, 45, "", 35);
this->pageInfoText->SetColor(COLOR("#FFFFFFFF"));
this->Add(this->topText);
this->Add(this->pageInfoText);
}
void instPage::onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos) {
}
}

View File

@ -26,14 +26,16 @@ namespace inst::ui {
}
void netInstPage::startNetwork() {
this->pageInfoText->SetText("");
this->menu->SetVisible(false);
this->menu->ClearItems();
mainApp->LoadLayout(mainApp->netinstPage);
mainApp->CallForRender();
ourUrls = netInstStuff::OnSelected();
if (!ourUrls.size()) {
mainApp->LoadLayout(mainApp->mainPage);
return;
} else {
this->pageInfoText->SetText("Select a NSP to install! Press B to cancel!");
for (auto& url: ourUrls) {
pu::String itm = url;
auto ourEntry = pu::ui::elm::MenuItem::New(itm);
@ -42,7 +44,6 @@ namespace inst::ui {
}
}
this->menu->SetVisible(true);
this->pageInfoText->SetText("Select a NSP to install! Press B to cancel!");
return;
}
@ -50,11 +51,7 @@ namespace inst::ui {
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);
if (dialogResult == -1) return;
this->pageInfoText->SetText("installing: " + ourUrl);
mainApp->CallForRender();
if (netInstStuff::installNspLan(ourUrl, dialogResult)) {
mainApp->CreateShowDialog(ourUrls[0] + " installed!", "", {"OK"}, true);
}
netInstStuff::installNspLan(ourUrl, dialogResult);
return;
}

View File

@ -36,20 +36,15 @@ namespace inst::ui {
std::string ourNsp = ourFiles[this->menu->GetSelectedIndex()].string().erase(0, 6);
int dialogResult = mainApp->CreateShowDialog("Where should " + ourNsp + " be installed to?", "Press B to cancel", {"SD", "Internal Storage"}, false);
if (dialogResult == -1) return;
if (nspInstStuff::installNspFromFile(ourNsp, dialogResult)) {
mainApp->CreateShowDialog(ourNsp + " installed!", "", {"OK"}, true);
return;
} else return;
nspInstStuff::installNspFromFile(ourNsp, dialogResult);
}
void nspInstPage::onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos) {
if (Down & KEY_B) {
mainApp->LoadLayout(mainApp->mainPage);
this->pageInfoText->SetText("Select a NSP to install! Put NSP files on the root of your SD!");
}
if (Down & KEY_A) {
nspInstPage::startInstall();
this->pageInfoText->SetText("Select a NSP to install! Put NSP files on the root of your SD!");
}
}
}