Add nightly auto-update

- Closes #121
This commit is contained in:
Pk11
2022-05-27 18:14:30 -05:00
committed by Dark98
parent 4474424695
commit af27709fc7
9 changed files with 90 additions and 39 deletions
+19 -6
View File
@@ -56,7 +56,8 @@ static const std::vector<Structs::ButtonPos> langButtons = {
static const std::vector<Structs::ButtonPos> toggleAbles = {
{ 288, 44, 24, 24 },
{ 288, 120, 24, 24 }
{ 288, 110, 24, 24 },
{ 288, 180, 24, 24 }
};
static const std::vector<Structs::ButtonPos> dirButtons = {
@@ -167,10 +168,15 @@ static void DrawAutoUpdate(int selection) {
GFX::DrawToggle(toggleAbles[0].x, toggleAbles[0].y, config->autoupdate());
Gui::DrawString(47, 75, 0.4f, UIThemes->TextColor(), Lang::get("AUTO_UPDATE_STORE_DESC"), 265, 0, font, C2D_WordWrap);
Gui::Draw_Rect(40, 120, 280, 24, (selection == 1 ? UIThemes->MarkSelected() : UIThemes->MarkUnselected()));
Gui::DrawString(47, 124, 0.5f, UIThemes->TextColor(), Lang::get("AUTO_UPDATE_DS"), 210, 0, font);
Gui::Draw_Rect(40, 110, 280, 24, (selection == 1 ? UIThemes->MarkSelected() : UIThemes->MarkUnselected()));
Gui::DrawString(47, 114, 0.5f, UIThemes->TextColor(), Lang::get("AUTO_UPDATE_DS"), 210, 0, font);
GFX::DrawToggle(toggleAbles[1].x, toggleAbles[1].y, config->updatecheck());
Gui::DrawString(47, 151, 0.4f, UIThemes->TextColor(), Lang::get("AUTO_UPDATE_DS_DESC"), 265, 0, font, C2D_WordWrap);
Gui::DrawString(47, 141, 0.4f, UIThemes->TextColor(), Lang::get("AUTO_UPDATE_DS_DESC"), 265, 0, font, C2D_WordWrap);
Gui::Draw_Rect(40, 180, 280, 24, (selection == 2 ? UIThemes->MarkSelected() : UIThemes->MarkUnselected()));
Gui::DrawString(47, 184, 0.5f, UIThemes->TextColor(), Lang::get("AUTO_UPDATE_NIGHTLY"), 210, 0, font);
GFX::DrawToggle(toggleAbles[2].x, toggleAbles[2].y, config->updatenightly());
Gui::DrawString(47, 211, 0.4f, UIThemes->TextColor(), Lang::get("AUTO_UPDATE_NIGHTLY_DESC"), 265, 0, font, C2D_WordWrap);
}
/*
@@ -442,7 +448,7 @@ static void AutoUpdateLogic(int &page, int &selection) {
}
if (hRepeat & KEY_DOWN) {
if (selection < 1) selection++;
if (selection < 2) selection++;
}
if (hRepeat & KEY_UP) {
@@ -459,6 +465,9 @@ static void AutoUpdateLogic(int &page, int &selection) {
} else if (touching(touch, toggleAbles[1])) {
config->updatecheck(!config->updatecheck());
} else if (touching(touch, toggleAbles[2])) {
config->updatenightly(!config->updatenightly());
}
}
@@ -471,6 +480,10 @@ static void AutoUpdateLogic(int &page, int &selection) {
case 1:
config->updatecheck(!config->updatecheck());
break;
case 2:
config->updatenightly(!config->updatenightly());
break;
}
}
}
@@ -717,4 +730,4 @@ void StoreUtils::SettingsHandle(int &page, bool &dspSettings, int &storeMode, in
LanguageLogic(page, selection, sPos);
break;
}
}
}
+5 -5
View File
@@ -75,8 +75,8 @@ MainScreen::MainScreen() {
if (access("sdmc:/3ds/DarkStore/stores/darkstore-homebrew.unistore", F_OK) != 0) {
if (checkWifiStatus()) {
std::string tmp = ""; // Just a temp.
DownloadStore("https://darkstore.ml/app/darkstore-homebrew.unistore", -1, tmp, true, true);
DownloadSpriteSheet("https://darkstore.ml/app/darkstore-homebrew.t3x", "darkstore-homebrew.t3x");
DownloadStore("https://ds.dark98.co.uk/app/darkstore-homebrew.unistore", -1, tmp, true, true);
DownloadSpriteSheet("https://ds.dark98.co.uk/app/darkstore-homebrew.t3x", "darkstore-homebrew.t3x");
} else {
notConnectedMsg();
@@ -88,8 +88,8 @@ MainScreen::MainScreen() {
if (info.Version != 3 && info.Version != _STORE_VERSION) {
if (checkWifiStatus()) {
std::string tmp = ""; // Just a temp.
DownloadStore("https://darkstore.ml/app/darkstore-homebrew.unistore", -1, tmp, true, true);
DownloadSpriteSheet("https://darkstore.ml/app/darkstore-homebrew.t3x", "darkstore-homebrew.t3x");
DownloadStore("https://ds.dark98.co.uk/app/darkstore-homebrew.unistore", -1, tmp, true, true);
DownloadSpriteSheet("https://ds.dark98.co.uk/app/darkstore-homebrew.t3x", "darkstore-homebrew.t3x");
} else {
notConnectedMsg();
@@ -291,4 +291,4 @@ void MainScreen::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
break;
}
}
}
}
+2
View File
@@ -134,6 +134,7 @@ Config::Config() {
if (this->json.contains("Firm_Path")) this->firmPath(this->getString("Firm_Path"));
if (this->json.contains("MetaData")) this->metadata(this->getBool("MetaData"));
if (this->json.contains("UpdateCheck")) this->updatecheck(this->getBool("UpdateCheck"));
if (this->json.contains("UpdateNightly")) this->updatenightly(this->getBool("UpdateNightly"));
if (this->json.contains("UseBG")) this->usebg(this->getBool("UseBG"));
if (this->json.contains("CustomFont")) this->customfont(this->getBool("CustomFont"));
if (this->json.contains("Shortcut_Path")) this->shortcut(this->getString("Shortcut_Path"));
@@ -173,6 +174,7 @@ void Config::save() {
this->setString("Firm_Path", this->firmPath());
this->setBool("MetaData", this->metadata());
this->setBool("UpdateCheck", this->updatecheck());
this->setBool("UpdateNightly", this->updatenightly());
this->setBool("UseBG", this->usebg());
this->setBool("CustomFont", this->customfont());
this->setString("Shortcut_Path", this->shortcut());
+47 -19
View File
@@ -33,6 +33,7 @@
#include "screenshot.hpp"
#include "scriptUtils.hpp"
#include "stringutils.hpp"
#include "version.hpp"
#include <3ds.h>
#include <curl/curl.h>
@@ -43,7 +44,7 @@
#include <unistd.h>
#include <vector>
#define USER_AGENT APP_TITLE "-" VERSION_STRING
#define USER_AGENT APP_TITLE "-" VER_NUMBER
static char *result_buf = nullptr;
static size_t result_sz = 0;
@@ -795,7 +796,11 @@ DSUpdate IsDSUpdateAvailable() {
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, "https://api.github.com/repos/DarkStore-3DS/DarkStore/releases/latest");
const char *url;
if (config->updatenightly()) url = "https://api.github.com/repos/DarkStore-3DS/DarkStore/commits";
else url = "https://api.github.com/repos/DarkStore-3DS/DarkStore/releases/latest";
ret = setupContext(hnd, url);
if (ret != 0) {
socExit();
free(result_buf);
@@ -826,21 +831,39 @@ DSUpdate IsDSUpdateAvailable() {
if (nlohmann::json::accept(result_buf)) {
nlohmann::json parsedAPI = nlohmann::json::parse(result_buf);
if (parsedAPI.contains("tag_name") && parsedAPI["tag_name"].is_string()) {
DSUpdate update = { false, "", "" };
update.Version = parsedAPI["tag_name"];
if (config->updatenightly()) {
if (parsedAPI.is_array() && parsedAPI.size() > 0 && parsedAPI[0].contains("sha") && parsedAPI[0]["sha"].is_string()) {
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
DSUpdate update = { false, "", "" };
update.Version = parsedAPI[0]["sha"].get_ref<const std::string &>().substr(0, 7);
if (parsedAPI[0].contains("commit") && parsedAPI[0]["commit"].is_object() && parsedAPI[0]["commit"].contains("message") && parsedAPI[0]["commit"]["message"].is_string())
update.Notes = parsedAPI[0]["commit"]["message"];
update.Notes.erase(remove(update.Notes.begin(), update.Notes.end(), '\r'), update.Notes.end()); // Remove the CRLF \r's.
update.Available = strcasecmp(update.Version.c_str(), GIT_SHA) != 0;
return update;
}
} else {
if (parsedAPI.contains("tag_name") && parsedAPI["tag_name"].is_string()) {
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
if (parsedAPI["body"].is_string()) update.Notes = parsedAPI["body"];
update.Notes.erase(remove(update.Notes.begin(), update.Notes.end(), '\r'), update.Notes.end()); // Remove the CRLF \r's.
update.Available = strcasecmp(StringUtils::lower_case(update.Version).c_str(), StringUtils::lower_case(C_V).c_str()) > 0;
return update;
DSUpdate update = { false, "", "" };
update.Version = parsedAPI["tag_name"];
if (parsedAPI["body"].is_string()) update.Notes = parsedAPI["body"];
update.Notes.erase(remove(update.Notes.begin(), update.Notes.end(), '\r'), update.Notes.end()); // Remove the CRLF \r's.
update.Available = strcasecmp(update.Version.c_str(), C_V) > 0;
return update;
}
}
}
@@ -904,10 +927,15 @@ void UpdateAction() {
if ((down & KEY_A) || (down & KEY_B) || (down & KEY_START) || (down & KEY_TOUCH)) confirmed = true;
}
if (ScriptUtils::downloadRelease("DarkStore-3DS/DarkStore", (is3DSX ? "DarkStore.3dsx" : "DarkStore.cia"),
(is3DSX ? _3dsxPath : "sdmc:/DarkStore.cia"),
false, Lang::get("DONLOADING_DARKSTORE"), true) == 0) {
Result dlRes;
if (config->updatenightly())
dlRes = ScriptUtils::downloadFile("https://raw.githubusercontent.com/DarkStore-3DS/extras/master/builds/DarkStore/DarkStore." + std::string(is3DSX ? "3dsx" : "cia"),
(is3DSX ? _3dsxPath : "sdmc:/DarkStore.cia"), Lang::get("DONLOADING_DARKSTORE"), true);
else
dlRes = ScriptUtils::downloadRelease("DarkStore-3DS/DarkStore", (is3DSX ? "DarkStore.3dsx" : "DarkStore.cia"),
(is3DSX ? _3dsxPath : "sdmc:/DarkStore.cia"), false, Lang::get("DONLOADING_DARKSTORE"), true);
if (dlRes == ScriptState::NONE) {
if (is3DSX) {
Msg::waitMsg(Lang::get("UPDATE_DONE"));
exiting = true;
@@ -953,7 +981,7 @@ std::vector<StoreList> FetchStores() {
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, "https://darkstore.ml/app/Stores.json");
ret = setupContext(hnd, "https://ds.dark98.co.uk/app/Stores.json");
if (ret != 0) {
socExit();
free(result_buf);