Detect network status before allowing network related functions

This commit is contained in:
Huntereb 2019-11-28 10:54:32 -05:00
parent 9be193b39d
commit 3f42a148ec
6 changed files with 22 additions and 20 deletions

View file

@ -16,4 +16,5 @@ namespace inst::util {
std::string softwareKeyboard(std::string guideText, std::string initialText, int LenMax); std::string softwareKeyboard(std::string guideText, std::string initialText, int LenMax);
std::string getDriveFileName(std::string fileId); std::string getDriveFileName(std::string fileId);
std::vector<uint32_t> setClockSpeed(int deviceToClock, uint32_t clockSpeed); std::vector<uint32_t> setClockSpeed(int deviceToClock, uint32_t clockSpeed);
std::string getIPAddress();
} }

View file

@ -22,10 +22,8 @@ SOFTWARE.
#include <cstring> #include <cstring>
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/errno.h> #include <sys/errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include <sstream> #include <sstream>
#include <curl/curl.h> #include <curl/curl.h>
@ -215,16 +213,9 @@ namespace netInstStuff{
} }
} }
struct in_addr addr = {(in_addr_t) gethostid()}; std::string ourIPAddress = inst::util::getIPAddress();
std::string ourIPAddr(inet_ntoa(addr)); inst::ui::setNetInfoText("Waiting for a connection... Your Switch's IP Address is: " + ourIPAddress);
// If our IP is 127.0.0.1, cancel because we aren't connected to a network printf("%s %s\n", "Switch IP is ", ourIPAddress.c_str());
if (ourIPAddr == "1.0.0.127") {
inst::ui::mainApp->CreateShowDialog("Network connection not available", "Check that airplane mode is disabled and you're connected to a local network.", {"OK"}, true);
return {};
}
inst::ui::setNetInfoText("Waiting for a connection... Your Switch's IP Address is: " + ourIPAddr);
printf("%s %s\n", "Switch IP is ", inet_ntoa(addr));
printf("%s\n", "Waiting for network"); printf("%s\n", "Waiting for network");
printf("%s\n", "B to cancel"); printf("%s\n", "B to cancel");
@ -287,11 +278,7 @@ namespace netInstStuff{
std::string nspExt = ".nsp"; std::string nspExt = ".nsp";
std::string nszExt = ".nsz"; std::string nszExt = ".nsz";
while (std::getline(urlStream, segment, '\n')) while (std::getline(urlStream, segment, '\n')) urls.push_back(segment);
{
if (segment.compare(segment.size() - nspExt.size(), nspExt.size(), nspExt) == 0) urls.push_back(segment);
else if (segment.compare(segment.size() - nszExt.size(), nszExt.size(), nszExt) == 0) urls.push_back(segment);
}
break; break;
} }

View file

@ -22,15 +22,19 @@ namespace sig {
} }
int ourResult = inst::ui::mainApp->CreateShowDialog("Install signature patches?", "Signature patches are required for installing and playing official software." + versionText, {installButtonText, "Uninstall", "Cancel"}, true); int ourResult = inst::ui::mainApp->CreateShowDialog("Install signature patches?", "Signature patches are required for installing and playing official software." + versionText, {installButtonText, "Uninstall", "Cancel"}, true);
if (ourResult == 0) { if (ourResult == 0) {
if (inst::util::getIPAddress() == "1.0.0.127") {
inst::ui::mainApp->CreateShowDialog("Network connection not available", "Check that airplane mode is disabled and you're connected to a local network.", {"OK"}, true);
return;
}
if (!inst::util::copyFile("sdmc:/bootloader/patches.ini", inst::config::appDir + "/patches.ini.old")) { if (!inst::util::copyFile("sdmc:/bootloader/patches.ini", inst::config::appDir + "/patches.ini.old")) {
if (inst::ui::mainApp->CreateShowDialog("Could not back up old Hekate patches.ini! Install anyway?", "Installing patches requires the use of the Hekate bootloader.", {"Yes", "No"}, false)) return; if (inst::ui::mainApp->CreateShowDialog("Could not back up old Hekate patches.ini! Install anyway?", "Installing patches requires use of the Hekate bootloader.", {"Yes", "No"}, false)) return;
} }
std::string ourPath = inst::config::appDir + "/patches.zip"; std::string ourPath = inst::config::appDir + "/patches.zip";
bool didDownload = inst::curl::downloadFile(inst::config::sigPatchesUrl, ourPath.c_str()); bool didDownload = inst::curl::downloadFile(inst::config::sigPatchesUrl, ourPath.c_str());
bool didExtract = false; bool didExtract = false;
if (didDownload) didExtract = inst::zip::extractFile(ourPath, "sdmc:/"); if (didDownload) didExtract = inst::zip::extractFile(ourPath, "sdmc:/");
else { else {
inst::ui::mainApp->CreateShowDialog("Network connection not available", "Check that airplane mode is disabled and you're connected to a local network.", {"OK"}, true); inst::ui::mainApp->CreateShowDialog("Could not download signature patches", "You may have supplied an invalid source in Awoo Installer's settings,\nor the host may just be down right now.", {"OK"}, true);
return; return;
} }
std::filesystem::remove(ourPath); std::filesystem::remove(ourPath);

View file

@ -66,6 +66,10 @@ namespace inst::ui {
} }
void MainPage::netInstallMenuItem_Click() { void MainPage::netInstallMenuItem_Click() {
if (inst::util::getIPAddress() == "1.0.0.127") {
inst::ui::mainApp->CreateShowDialog("Network connection not available", "Check that airplane mode is disabled and you're connected to a local network.", {"OK"}, true);
return;
}
mainApp->netinstPage->startNetwork(); mainApp->netinstPage->startNetwork();
} }

View file

@ -76,7 +76,6 @@ namespace inst::ui {
} }
void netInstPage::startNetwork() { void netInstPage::startNetwork() {
this->pageInfoText->SetText("Waiting for a connection...");
this->butText->SetText("\ue0e3 Install Over Internet \ue0e2 Help \ue0e1 Cancel "); this->butText->SetText("\ue0e3 Install Over Internet \ue0e2 Help \ue0e1 Cancel ");
this->menu->SetVisible(false); this->menu->SetVisible(false);
this->menu->ClearItems(); this->menu->ClearItems();

View file

@ -5,6 +5,8 @@
#include <unistd.h> #include <unistd.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <regex> #include <regex>
#include <arpa/inet.h>
#include <unistd.h>
#include "switch.h" #include "switch.h"
#include "util/util.hpp" #include "util/util.hpp"
#include "nx/ipc/tin_ipc.h" #include "nx/ipc/tin_ipc.h"
@ -248,4 +250,9 @@ namespace inst::util {
return {previousHz, hz}; return {previousHz, hz};
} }
} }
std::string getIPAddress() {
struct in_addr addr = {(in_addr_t) gethostid()};
return inet_ntoa(addr);
}
} }