mirror of
https://github.com/Huntereb/Awoo-Installer
synced 2024-11-26 05:30:19 +00:00
tidy up usb install stuff a bit
This commit is contained in:
parent
3909194a4a
commit
53671a9e42
4 changed files with 104 additions and 53 deletions
17
source/install/usb_nsp.cpp
Normal file → Executable file
17
source/install/usb_nsp.cpp
Normal file → Executable file
|
@ -10,6 +10,8 @@
|
|||
#include "util/usb_util.hpp"
|
||||
#include "error.hpp"
|
||||
#include "debug.h"
|
||||
#include "nspInstall.hpp"
|
||||
#include "util/util.hpp"
|
||||
|
||||
namespace tin::install::nsp
|
||||
{
|
||||
|
@ -113,13 +115,15 @@ namespace tin::install::nsp
|
|||
|
||||
startTime = newTime;
|
||||
startSizeBuffered = newSizeBuffered;
|
||||
|
||||
u64 totalSizeMB = bufferedPlaceholderWriter.GetTotalDataSize() / 1000000;
|
||||
u64 downloadSizeMB = bufferedPlaceholderWriter.GetSizeBuffered() / 1000000;
|
||||
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 " + inst::util::formatUrlString(ncaFileName) + " at " + std::to_string(speed).substr(0, std::to_string(speed).size()-4) + "MB/s");
|
||||
inst::ui::setInstBarPerc((double)downloadProgress);
|
||||
}
|
||||
|
||||
u64 totalSizeMB = bufferedPlaceholderWriter.GetTotalDataSize() / 1000000;
|
||||
u64 downloadSizeMB = bufferedPlaceholderWriter.GetSizeBuffered() / 1000000;
|
||||
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);
|
||||
}
|
||||
|
||||
u64 totalSizeMB = bufferedPlaceholderWriter.GetTotalDataSize() / 1000000;
|
||||
|
@ -130,6 +134,7 @@ namespace tin::install::nsp
|
|||
int installProgress = (int)(((double)bufferedPlaceholderWriter.GetSizeWrittenToPlaceholder() / (double)bufferedPlaceholderWriter.GetTotalDataSize()) * 100.0);
|
||||
|
||||
//printf("> Install Progress: %lu/%lu MB (%i%s)\r", installSizeMB, totalSizeMB, installProgress, "%");
|
||||
inst::ui::setInstBarPerc((double)installProgress);
|
||||
}
|
||||
|
||||
thrd_join(usbThread, NULL);
|
||||
|
|
54
source/ui/usbInstPage.cpp
Normal file → Executable file
54
source/ui/usbInstPage.cpp
Normal file → Executable file
|
@ -14,7 +14,6 @@ namespace inst::ui {
|
|||
std::vector<std::string> usbInstPage::selectedNsps;
|
||||
|
||||
usbInstPage::usbInstPage() : Layout::Layout() {
|
||||
usbCommsInitialize();
|
||||
this->SetBackgroundColor(COLOR("#670000FF"));
|
||||
this->SetBackgroundImage("romfs:/background.jpg");
|
||||
this->topRect = Rectangle::New(0, 0, 1280, 93, COLOR("#170909FF"));
|
||||
|
@ -41,15 +40,15 @@ namespace inst::ui {
|
|||
}
|
||||
|
||||
void usbInstPage::drawMenuItems(bool clearItems) {
|
||||
if (clearItems) usbInstPage::selectedNsps = {};
|
||||
if (clearItems) this->selectedNsps = {};
|
||||
this->menu->ClearItems();
|
||||
for (auto& url: usbInstPage::ourNsps) {
|
||||
for (auto& url: this->ourNsps) {
|
||||
pu::String itm = inst::util::shortenString(inst::util::formatUrlString(url), 56, true);
|
||||
auto ourEntry = pu::ui::elm::MenuItem::New(itm);
|
||||
ourEntry->SetColor(COLOR("#FFFFFFFF"));
|
||||
ourEntry->SetIcon("romfs:/checkbox-blank-outline.png");
|
||||
for (long unsigned int i = 0; i < usbInstPage::selectedNsps.size(); i++) {
|
||||
if (usbInstPage::selectedNsps[i] == url) {
|
||||
for (long unsigned int i = 0; i < this->selectedNsps.size(); i++) {
|
||||
if (this->selectedNsps[i] == url) {
|
||||
ourEntry->SetIcon("romfs:/check-box-outline.png");
|
||||
}
|
||||
}
|
||||
|
@ -59,27 +58,27 @@ namespace inst::ui {
|
|||
|
||||
void usbInstPage::selectNsp(int selectedIndex) {
|
||||
if (this->menu->GetItems()[selectedIndex]->GetIcon() == "romfs:/check-box-outline.png") {
|
||||
for (long unsigned int i = 0; i < usbInstPage::selectedNsps.size(); i++) {
|
||||
if (usbInstPage::selectedNsps[i] == usbInstPage::ourNsps[selectedIndex]) usbInstPage::selectedNsps.erase(usbInstPage::selectedNsps.begin() + i);
|
||||
for (long unsigned int i = 0; i < this->selectedNsps.size(); i++) {
|
||||
if (this->selectedNsps[i] == this->ourNsps[selectedIndex]) this->selectedNsps.erase(this->selectedNsps.begin() + i);
|
||||
}
|
||||
} else usbInstPage::selectedNsps.push_back(usbInstPage::ourNsps[selectedIndex]);
|
||||
usbInstPage::drawMenuItems(false);
|
||||
} else this->selectedNsps.push_back(this->ourNsps[selectedIndex]);
|
||||
this->drawMenuItems(false);
|
||||
}
|
||||
|
||||
void usbInstPage::startUsb() {
|
||||
this->pageInfoText->SetText("");
|
||||
this->butText->SetText("\ue0e2 Help \ue0e1 Cancel ");
|
||||
this->butText->SetText("");
|
||||
this->menu->SetVisible(false);
|
||||
this->menu->ClearItems();
|
||||
mainApp->LoadLayout(mainApp->usbinstPage);
|
||||
usbInstPage::ourNsps = usbInstStuff::OnSelected();
|
||||
if (!usbInstPage::ourNsps.size()) {
|
||||
this->ourNsps = usbInstStuff::OnSelected();
|
||||
if (!this->ourNsps.size()) {
|
||||
mainApp->LoadLayout(mainApp->mainPage);
|
||||
return;
|
||||
} else {
|
||||
this->pageInfoText->SetText("Select what files you want to install from the usb, then press the Plus button!");
|
||||
this->pageInfoText->SetText("Select what files you want to install from usb, then press the Plus button!");
|
||||
this->butText->SetText("\ue0e0 Select File \ue0e3 Select All \ue0ef Install File(s) \ue0e1 Cancel ");
|
||||
usbInstPage::drawMenuItems(true);
|
||||
this->drawMenuItems(true);
|
||||
}
|
||||
this->menu->SetVisible(true);
|
||||
return;
|
||||
|
@ -87,41 +86,40 @@ namespace inst::ui {
|
|||
|
||||
void usbInstPage::startInstall() {
|
||||
int dialogResult = -1;
|
||||
if (usbInstPage::selectedNsps.size() == 1) dialogResult = mainApp->CreateShowDialog("Where should " + selectedNsps[0] + " be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
else dialogResult = mainApp->CreateShowDialog("Where should the selected " + std::to_string(usbInstPage::selectedNsps.size()) + " files be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
if (this->selectedNsps.size() == 1) dialogResult = mainApp->CreateShowDialog("Where should " + selectedNsps[0] + " be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
else dialogResult = mainApp->CreateShowDialog("Where should the selected " + std::to_string(this->selectedNsps.size()) + " files be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
if (dialogResult == -1) return;
|
||||
usbInstStuff::installNspUsb(usbInstPage::selectedNsps, dialogResult);
|
||||
usbInstStuff::installNspUsb(this->selectedNsps, dialogResult);
|
||||
return;
|
||||
}
|
||||
|
||||
void usbInstPage::onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos) {
|
||||
if (Down & KEY_B) {
|
||||
usbCommsExit();
|
||||
mainApp->LoadLayout(mainApp->mainPage);
|
||||
}
|
||||
if ((Down & KEY_A) || (Up & KEY_TOUCH)) {
|
||||
usbInstPage::selectNsp(this->menu->GetSelectedIndex());
|
||||
if (this->menu->GetItems().size() == 1 && usbInstPage::selectedNsps.size() == 1) {
|
||||
usbInstPage::startInstall();
|
||||
this->selectNsp(this->menu->GetSelectedIndex());
|
||||
if (this->menu->GetItems().size() == 1 && this->selectedNsps.size() == 1) {
|
||||
this->startInstall();
|
||||
}
|
||||
}
|
||||
if ((Down & KEY_Y)) {
|
||||
if (usbInstPage::selectedNsps.size() == this->menu->GetItems().size()) usbInstPage::drawMenuItems(true);
|
||||
if (this->selectedNsps.size() == this->menu->GetItems().size()) this->drawMenuItems(true);
|
||||
else {
|
||||
for (long unsigned int i = 0; i < this->menu->GetItems().size(); i++) {
|
||||
if (this->menu->GetItems()[i]->GetIcon() == "romfs:/check-box-outline.png") continue;
|
||||
else usbInstPage::selectNsp(i);
|
||||
else this->selectNsp(i);
|
||||
}
|
||||
usbInstPage::drawMenuItems(false);
|
||||
this->drawMenuItems(false);
|
||||
}
|
||||
}
|
||||
if (Down & KEY_PLUS) {
|
||||
if (usbInstPage::selectedNsps.size() == 0) {
|
||||
usbInstPage::selectNsp(this->menu->GetSelectedIndex());
|
||||
usbInstPage::startInstall();
|
||||
if (this->selectedNsps.size() == 0) {
|
||||
this->selectNsp(this->menu->GetSelectedIndex());
|
||||
this->startInstall();
|
||||
return;
|
||||
}
|
||||
usbInstPage::startInstall();
|
||||
this->startInstall();
|
||||
}
|
||||
}
|
||||
}
|
84
source/usbInstall.cpp
Normal file → Executable file
84
source/usbInstall.cpp
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
|||
#include <string>
|
||||
#include "usbInstall.hpp"
|
||||
#include "install/usb_nsp.hpp"
|
||||
#include "install/install_nsp_remote.hpp"
|
||||
|
@ -11,6 +12,11 @@
|
|||
|
||||
namespace inst::ui {
|
||||
extern MainApplication *mainApp;
|
||||
|
||||
void setUsbInfoText(std::string ourText){
|
||||
mainApp->usbinstPage->pageInfoText->SetText(ourText);
|
||||
mainApp->CallForRender();
|
||||
}
|
||||
}
|
||||
|
||||
namespace usbInstStuff {
|
||||
|
@ -23,7 +29,13 @@ namespace usbInstStuff {
|
|||
|
||||
std::vector<std::string> OnSelected() {
|
||||
Result rc = 0;
|
||||
inst::ui::setInstInfoText("waiting for usb...\n");
|
||||
|
||||
u32 usbState = 0;
|
||||
usbDsGetState(&usbState);
|
||||
if (usbState != 5) {
|
||||
inst::ui::mainApp->CreateShowDialog("Plug in usb ya faggot!", "", {"OK"}, false);
|
||||
return {};
|
||||
}
|
||||
|
||||
while(true) {
|
||||
hidScanInput();
|
||||
|
@ -51,45 +63,79 @@ namespace usbInstStuff {
|
|||
// Split the string up into individual nsp names
|
||||
std::stringstream nspNameStream(nspListBuf.get());
|
||||
std::string segment;
|
||||
std::string nspExt = ".nsp";
|
||||
std::string nszExt = ".nsz";
|
||||
|
||||
while (std::getline(nspNameStream, segment, '\n')) {
|
||||
if (segment.compare(segment.size() - nspExt.size(), nspExt.size(), nspExt) == 0 || segment.compare(segment.size() - nszExt.size(), nszExt.size(), nszExt) == 0)
|
||||
nspNames.push_back(segment);
|
||||
nspNames.push_back(segment);
|
||||
}
|
||||
|
||||
return nspNames;
|
||||
}
|
||||
|
||||
void installNspUsb(std::vector<std::string> ourNspList, int ourStorage) {
|
||||
void installNspUsb(std::vector<std::string> ourNspList, int ourStorage)
|
||||
{
|
||||
inst::util::initInstallServices();
|
||||
|
||||
inst::ui::loadInstallScreen();
|
||||
bool nspInstalled = true;
|
||||
NcmStorageId m_destStorageId = NcmStorageId_SdCard;
|
||||
|
||||
if (ourStorage) m_destStorageId = NcmStorageId_BuiltInUser;
|
||||
unsigned int fileItr;
|
||||
|
||||
for (std::string nspName: ourNspList) {
|
||||
try {
|
||||
tin::install::nsp::USBNSP usbNSP(nspName);
|
||||
inst::ui::setInstInfoText("installing" + nspName);
|
||||
std::vector<std::string> fileNames;
|
||||
for (long unsigned int i = 0; i < ourNspList.size(); i++) {
|
||||
fileNames.push_back(inst::util::shortenString(ourNspList[i], 42, true));
|
||||
}
|
||||
/*
|
||||
std::vector<int> previousClockValues;
|
||||
if (inst::config::overClock) {
|
||||
previousClockValues.push_back(inst::util::setClockSpeed(0, 1785000000)[0]);
|
||||
previousClockValues.push_back(inst::util::setClockSpeed(1, 76800000)[0]);
|
||||
previousClockValues.push_back(inst::util::setClockSpeed(2, 1600000000)[0]);
|
||||
}
|
||||
*/
|
||||
try {
|
||||
for (fileItr = 0; fileItr < ourNspList.size(); fileItr++) {
|
||||
inst::ui::setTopInstInfoText("Installing " + fileNames[fileItr]);
|
||||
|
||||
tin::install::nsp::USBNSP usbNSP(ourNspList[fileItr]);
|
||||
tin::install::nsp::RemoteNSPInstall install(m_destStorageId, inst::config::ignoreReqVers, &usbNSP);
|
||||
|
||||
printf("%s\n", "Preparing installation");
|
||||
inst::ui::setInstInfoText("Preparing installation...");
|
||||
inst::ui::setInstBarPerc(0);
|
||||
install.Prepare();
|
||||
|
||||
install.Begin();
|
||||
} catch(...) {
|
||||
int rc = inst::ui::mainApp->CreateShowDialog("install failed", nspName + " failed\ndo you want to continue?", {"yes", "cancel"}, true);
|
||||
if (rc == 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
printf("Failed to install");
|
||||
printf("%s", e.what());
|
||||
fprintf(stdout, "%s", e.what());
|
||||
inst::ui::setInstInfoText("Failed to install " + fileNames[fileItr]);
|
||||
inst::ui::setInstBarPerc(0);
|
||||
inst::ui::mainApp->CreateShowDialog("Failed to install " + fileNames[fileItr] + "!", "Partially installed contents can be removed from the System Settings applet.\n\n" + (std::string)e.what(), {"OK"}, true);
|
||||
nspInstalled = false;
|
||||
}
|
||||
|
||||
tin::util::USBCmdManager::SendExitCmd();
|
||||
/*
|
||||
if (previousClockValues.size() > 0) {
|
||||
inst::util::setClockSpeed(0, previousClockValues[0]);
|
||||
inst::util::setClockSpeed(1, previousClockValues[1]);
|
||||
inst::util::setClockSpeed(2, previousClockValues[2]);
|
||||
}
|
||||
*/
|
||||
|
||||
inst::ui::setInstInfoText("finished installation");
|
||||
inst::ui::mainApp->CreateShowDialog("Done", "Back to menu?", {"ok"}, true);
|
||||
if(nspInstalled) {
|
||||
inst::ui::setInstInfoText("Install complete");
|
||||
inst::ui::setInstBarPerc(100);
|
||||
if (ourNspList.size() > 1) inst::ui::mainApp->CreateShowDialog(std::to_string(ourNspList.size()) + " files installed successfully!", nspInstStuff::finishedMessage(), {"OK"}, true);
|
||||
else inst::ui::mainApp->CreateShowDialog(fileNames[0] + " installed!", nspInstStuff::finishedMessage(), {"OK"}, true);
|
||||
}
|
||||
|
||||
printf("Done");
|
||||
inst::ui::loadMainMenu();
|
||||
inst::util::deinitInstallServices();
|
||||
inst::util::deinitInstallServices();
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -25,10 +25,12 @@ namespace inst::util {
|
|||
#ifdef __DEBUG__
|
||||
nxlinkStdio();
|
||||
#endif
|
||||
usbCommsInitialize();
|
||||
}
|
||||
|
||||
void deinitApp () {
|
||||
socketExit();
|
||||
usbCommsExit();
|
||||
}
|
||||
|
||||
void initInstallServices() {
|
||||
|
|
Loading…
Reference in a new issue