mirror of
https://github.com/Huntereb/Awoo-Installer
synced 2024-11-26 05:30:19 +00:00
Detect network status before allowing network related functions
This commit is contained in:
parent
9be193b39d
commit
3f42a148ec
6 changed files with 22 additions and 20 deletions
|
@ -16,4 +16,5 @@ namespace inst::util {
|
|||
std::string softwareKeyboard(std::string guideText, std::string initialText, int LenMax);
|
||||
std::string getDriveFileName(std::string fileId);
|
||||
std::vector<uint32_t> setClockSpeed(int deviceToClock, uint32_t clockSpeed);
|
||||
std::string getIPAddress();
|
||||
}
|
|
@ -22,10 +22,8 @@ SOFTWARE.
|
|||
|
||||
#include <cstring>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sstream>
|
||||
#include <curl/curl.h>
|
||||
|
||||
|
@ -215,16 +213,9 @@ namespace netInstStuff{
|
|||
}
|
||||
}
|
||||
|
||||
struct in_addr addr = {(in_addr_t) gethostid()};
|
||||
std::string ourIPAddr(inet_ntoa(addr));
|
||||
// If our IP is 127.0.0.1, cancel because we aren't connected to a network
|
||||
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));
|
||||
std::string ourIPAddress = inst::util::getIPAddress();
|
||||
inst::ui::setNetInfoText("Waiting for a connection... Your Switch's IP Address is: " + ourIPAddress);
|
||||
printf("%s %s\n", "Switch IP is ", ourIPAddress.c_str());
|
||||
printf("%s\n", "Waiting for network");
|
||||
printf("%s\n", "B to cancel");
|
||||
|
||||
|
@ -287,11 +278,7 @@ namespace netInstStuff{
|
|||
std::string nspExt = ".nsp";
|
||||
std::string nszExt = ".nsz";
|
||||
|
||||
while (std::getline(urlStream, segment, '\n'))
|
||||
{
|
||||
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);
|
||||
}
|
||||
while (std::getline(urlStream, segment, '\n')) urls.push_back(segment);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
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::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";
|
||||
bool didDownload = inst::curl::downloadFile(inst::config::sigPatchesUrl, ourPath.c_str());
|
||||
bool didExtract = false;
|
||||
if (didDownload) didExtract = inst::zip::extractFile(ourPath, "sdmc:/");
|
||||
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;
|
||||
}
|
||||
std::filesystem::remove(ourPath);
|
||||
|
|
|
@ -66,6 +66,10 @@ namespace inst::ui {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ namespace inst::ui {
|
|||
}
|
||||
|
||||
void netInstPage::startNetwork() {
|
||||
this->pageInfoText->SetText("Waiting for a connection...");
|
||||
this->butText->SetText("\ue0e3 Install Over Internet \ue0e2 Help \ue0e1 Cancel ");
|
||||
this->menu->SetVisible(false);
|
||||
this->menu->ClearItems();
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <unistd.h>
|
||||
#include <curl/curl.h>
|
||||
#include <regex>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include "switch.h"
|
||||
#include "util/util.hpp"
|
||||
#include "nx/ipc/tin_ipc.h"
|
||||
|
@ -248,4 +250,9 @@ namespace inst::util {
|
|||
return {previousHz, hz};
|
||||
}
|
||||
}
|
||||
|
||||
std::string getIPAddress() {
|
||||
struct in_addr addr = {(in_addr_t) gethostid()};
|
||||
return inet_ntoa(addr);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue