Check for updates within app options

This commit is contained in:
Huntereb 2019-12-17 22:25:21 -05:00
parent a8df385ff3
commit 3608a661c8
7 changed files with 22962 additions and 19 deletions

View File

@ -20,5 +20,6 @@ namespace inst::ui {
pu::ui::elm::Menu::Ref menu;
void setMenuText();
std::string getMenuOptionIcon(bool ourBool);
void checkForUpdate();
};
}

View File

@ -2,6 +2,6 @@
#include <string>
namespace inst::curl {
bool downloadFile(const std::string ourUrl, const char *pagefilename);
std::string downloadToBuffer (const std::string ourUrl, int firstRange = -1, int secondRange = -1);
bool downloadFile(const std::string ourUrl, const char *pagefilename, long timeout = 5000, bool writeProgress = false);
std::string downloadToBuffer (const std::string ourUrl, int firstRange = -1, int secondRange = -1, long timeout = 5000);
}

22875
include/util/json.hpp Executable file

File diff suppressed because it is too large Load Diff

View File

@ -19,4 +19,5 @@ namespace inst::util {
std::string getIPAddress();
int getUsbState();
void playAudio(std::string audioPath);
std::vector<std::string> checkForAppUpdate();
}

View File

@ -6,14 +6,14 @@
#include "ui/optionsPage.hpp"
#include "util/util.hpp"
#include "util/config.hpp"
#include "util/curl.hpp"
#include "sdInstall.hpp"
#define COLOR(hex) pu::ui::Color::FromHex(hex)
namespace inst::ui {
extern MainApplication *mainApp;
std::vector<std::string> ourMenuEntries = {"Ignore minimum firmware version required by titles", "Verify NCA signatures before installation", "Enable \"boost mode\" during installations", "Ask to delete original files after installation", "Remove anime", "Signature patches source URL: "};
optionsPage::optionsPage() : Layout::Layout() {
this->SetBackgroundColor(COLOR("#670000FF"));
if (std::filesystem::exists(inst::config::appDir + "/background.png")) this->SetBackgroundImage(inst::config::appDir + "/background.png");
@ -42,6 +42,40 @@ namespace inst::ui {
this->Add(this->menu);
}
void optionsPage::checkForUpdate() {
std::vector<std::string> downloadUrl = inst::util::checkForAppUpdate();
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 (!downloadUrl.size()) {
mainApp->CreateShowDialog("No updates found", "You are on the latest version of Awoo Installer!", {"OK"}, false);
return;
}
else {
if (!mainApp->CreateShowDialog("Update available", "Awoo Installer " + downloadUrl[0] + " is available now! Ready to update?", {"Update", "Cancel"}, false)) {
inst::ui::loadInstallScreen();
inst::ui::setTopInstInfoText("Updating to Awoo Installer " + downloadUrl[0]);
inst::ui::setInstBarPerc(0);
inst::ui::setInstInfoText("Downloading Awoo Installer " + downloadUrl[0]);
try {
romfsExit();
std::string curName = inst::config::appDir + "/Awoo-Installer.nro";
std::string downloadName = inst::config::appDir + "/temp_download";
inst::curl::downloadFile(downloadUrl[1], downloadName.c_str(), 0, true);
if (std::filesystem::exists(curName)) std::filesystem::remove(curName);
std::filesystem::rename(downloadName, curName);
mainApp->CreateShowDialog("Update complete!", "The software will now be closed.", {"OK"}, false);
} catch (...) {
mainApp->CreateShowDialog("Update failed!", "The software will now be closed.", {"OK"}, false);
}
mainApp->FadeOut();
mainApp->Close();
}
}
return;
}
std::string optionsPage::getMenuOptionIcon(bool ourBool) {
if(ourBool) return "romfs:/images/icons/check-box-outline.png";
else return "romfs:/images/icons/checkbox-blank-outline.png";
@ -49,29 +83,32 @@ namespace inst::ui {
void optionsPage::setMenuText() {
this->menu->ClearItems();
auto ignoreFirmOption = pu::ui::elm::MenuItem::New(ourMenuEntries[0]);
auto ignoreFirmOption = pu::ui::elm::MenuItem::New("Ignore minimum firmware version required by titles");
ignoreFirmOption->SetColor(COLOR("#FFFFFFFF"));
ignoreFirmOption->SetIcon(this->getMenuOptionIcon(inst::config::ignoreReqVers));
this->menu->AddItem(ignoreFirmOption);
auto validateOption = pu::ui::elm::MenuItem::New(ourMenuEntries[1]);
auto validateOption = pu::ui::elm::MenuItem::New("Verify NCA signatures before installation");
validateOption->SetColor(COLOR("#FFFFFFFF"));
validateOption->SetIcon(this->getMenuOptionIcon(inst::config::validateNCAs));
this->menu->AddItem(validateOption);
auto overclockOption = pu::ui::elm::MenuItem::New(ourMenuEntries[2]);
auto overclockOption = pu::ui::elm::MenuItem::New("Enable \"boost mode\" during installations");
overclockOption->SetColor(COLOR("#FFFFFFFF"));
overclockOption->SetIcon(this->getMenuOptionIcon(inst::config::overClock));
this->menu->AddItem(overclockOption);
auto deletePromptOption = pu::ui::elm::MenuItem::New(ourMenuEntries[3]);
auto deletePromptOption = pu::ui::elm::MenuItem::New("Ask to delete original files after installation");
deletePromptOption->SetColor(COLOR("#FFFFFFFF"));
deletePromptOption->SetIcon(this->getMenuOptionIcon(inst::config::deletePrompt));
this->menu->AddItem(deletePromptOption);
auto gayModeOption = pu::ui::elm::MenuItem::New(ourMenuEntries[4]);
auto gayModeOption = pu::ui::elm::MenuItem::New("Remove anime");
gayModeOption->SetColor(COLOR("#FFFFFFFF"));
gayModeOption->SetIcon(this->getMenuOptionIcon(inst::config::gayMode));
this->menu->AddItem(gayModeOption);
auto sigPatchesUrlOption = pu::ui::elm::MenuItem::New(ourMenuEntries[5] + inst::util::shortenString(inst::config::sigPatchesUrl, 42, false));
auto sigPatchesUrlOption = pu::ui::elm::MenuItem::New("Signature patches source URL: " + inst::util::shortenString(inst::config::sigPatchesUrl, 42, false));
sigPatchesUrlOption->SetColor(COLOR("#FFFFFFFF"));
this->menu->AddItem(sigPatchesUrlOption);
auto updateOption = pu::ui::elm::MenuItem::New("Check for updates");
updateOption->SetColor(COLOR("#FFFFFFFF"));
this->menu->AddItem(updateOption);
auto creditsOption = pu::ui::elm::MenuItem::New("Credits");
creditsOption->SetColor(COLOR("#FFFFFFFF"));
this->menu->AddItem(creditsOption);
@ -129,6 +166,9 @@ namespace inst::ui {
}
break;
case 6:
this->checkForUpdate();
break;
case 7:
inst::ui::mainApp->CreateShowDialog("Thanks to the following people!", "- HookedBehemoth for A LOT of contributions\n- Adubbz and other contributors for Tinfoil\n- XorTroll for Plutonium and Goldleaf\n- blawar (wife beater) and nicoboss for NSZ support\n- The kind folks at the AtlasNX Discuck (or at least some of them)\n- The also kind folks at the RetroNX Discuck (of no direct involvement)\n- namako8982 for the Momiji art\n- TheXzoron for being a baka", {"Close"}, true);
break;
default:

View File

@ -1,10 +1,11 @@
#include "util/curl.hpp"
#include "util/config.hpp"
#include "util/error.hpp"
#include <curl/curl.h>
#include <string>
#include <sstream>
#include <iostream>
#include "util/curl.hpp"
#include "util/config.hpp"
#include "util/error.hpp"
#include "sdInstall.hpp"
static size_t writeDataFile(void *ptr, size_t size, size_t nmemb, void *stream) {
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
@ -18,8 +19,19 @@ size_t writeDataBuffer(char *ptr, size_t size, size_t nmemb, void *userdata) {
return count;
}
int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
if (ultotal) {
int uploadProgress = (int)(((double)ulnow / (double)ultotal) * 100.0);
inst::ui::setInstBarPerc(uploadProgress);
} else if (dltotal) {
int downloadProgress = (int)(((double)dlnow / (double)dltotal) * 100.0);
inst::ui::setInstBarPerc(downloadProgress);
}
return 0;
}
namespace inst::curl {
bool downloadFile (const std::string ourUrl, const char *pagefilename) {
bool downloadFile (const std::string ourUrl, const char *pagefilename, long timeout, bool writeProgress) {
CURL *curl_handle;
CURLcode result;
FILE *pagefile;
@ -30,11 +42,13 @@ namespace inst::curl {
curl_easy_setopt(curl_handle, CURLOPT_URL, ourUrl.c_str());
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Awoo-Installer");
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, 5000L);
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, 5000L);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, timeout);
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, timeout);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeDataFile);
if (writeProgress) curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
pagefile = fopen(pagefilename, "wb");
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
@ -51,7 +65,7 @@ namespace inst::curl {
}
}
std::string downloadToBuffer (const std::string ourUrl, int firstRange, int secondRange) {
std::string downloadToBuffer (const std::string ourUrl, int firstRange, int secondRange, long timeout) {
CURL *curl_handle;
CURLcode result;
std::ostringstream stream;
@ -62,10 +76,11 @@ namespace inst::curl {
curl_easy_setopt(curl_handle, CURLOPT_URL, ourUrl.c_str());
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Awoo-Installer");
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, 5000L);
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, 5000L);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, timeout);
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, timeout);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeDataBuffer);
if (firstRange && secondRange) {
const char * ourRange = (std::to_string(firstRange) + "-" + std::to_string(secondRange)).c_str();

View File

@ -15,6 +15,7 @@
#include "util/curl.hpp"
#include "ui/MainApplication.hpp"
#include "util/usb_comms_awoo.h"
#include "util/json.hpp"
namespace inst::util {
void initApp () {
@ -295,4 +296,14 @@ namespace inst::util {
return;
}
std::vector<std::string> checkForAppUpdate () {
try {
std::string jsonData = inst::curl::downloadToBuffer("https://api.github.com/repos/Huntereb/Awoo-Installer/releases/latest", 0, 0, 1000L);
if (jsonData.size() == 0) return {};
nlohmann::json ourJson = nlohmann::json::parse(jsonData);
if (ourJson["tag_name"].get<std::string>() != inst::config::appVersion) return {ourJson["tag_name"].get<std::string>(), ourJson["assets"][0]["browser_download_url"].get<std::string>()};
} catch (...) {}
return {};
}
}