update changelog
This commit is contained in:
1 parent
56495e9b64
commit
52424a86e3
8 files changed
+244
-7
No files matched your search
@@ -17,12 +17,14 @@
|
||||
#include "update_gui.h"
|
||||
#include "ult_ext.h"
|
||||
#include "base_menu_gui.h"
|
||||
#include "update_confirm_gui.h"
|
||||
#include "../format.h"
|
||||
#include "../style.h"
|
||||
|
||||
#include <tesla.hpp>
|
||||
#include <ultra.hpp>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -131,6 +133,29 @@ void UpdateGui::startJob(int packageIndex, bool extractOnly) {
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateGui::startChangelogFetch(int packageIndex) {
|
||||
if (isBusy()) return;
|
||||
|
||||
m_activePackage = packageIndex;
|
||||
m_resultMessage.clear();
|
||||
m_changelogTag.clear();
|
||||
m_changelogLines.clear();
|
||||
|
||||
ult::abortDownload.store(false, std::memory_order_release);
|
||||
|
||||
m_stage.store(UpdateStage::FetchingChangelog, std::memory_order_release);
|
||||
|
||||
if (R_SUCCEEDED(threadCreate(&m_thread, fetchChangelogEntry, this,
|
||||
nullptr, 0x8000, 0x20, -2))) {
|
||||
m_threadActive = true;
|
||||
threadStart(&m_thread);
|
||||
} else {
|
||||
m_resultMessage = "Failed to create thread";
|
||||
m_stage.store(UpdateStage::Failed, std::memory_order_release);
|
||||
m_threadActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateGui::requestCancel() {
|
||||
ult::abortDownload.store(true, std::memory_order_release);
|
||||
ult::abortUnzip.store(true, std::memory_order_release);
|
||||
@@ -186,6 +211,55 @@ void UpdateGui::jobBody() {
|
||||
m_stage.store(UpdateStage::Done, std::memory_order_release);
|
||||
}
|
||||
|
||||
/* static */ void UpdateGui::fetchChangelogEntry(void *arg) {
|
||||
static_cast<UpdateGui *>(arg)->fetchChangelogBody();
|
||||
}
|
||||
|
||||
void UpdateGui::fetchChangelogBody() {
|
||||
ult::createDirectory("sdmc:/config/horizon-oc/");
|
||||
|
||||
bool ok = ult::downloadFile(kReleaseApiUrl, kReleaseInfoPath, false, false);
|
||||
if (!ok || ult::abortDownload.load(std::memory_order_acquire)) {
|
||||
m_resultMessage = ult::abortDownload.load(std::memory_order_acquire)
|
||||
? "Changelog fetch cancelled"
|
||||
: "Could not fetch changelog -- check network";
|
||||
m_stage.store(
|
||||
ult::abortDownload.load() ? UpdateStage::Cancelled : UpdateStage::Failed,
|
||||
std::memory_order_release);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<ult::json_t, ult::JsonDeleter> root(ult::readJsonFromFile(kReleaseInfoPath));
|
||||
std::remove(kReleaseInfoPath);
|
||||
|
||||
if (!root) {
|
||||
m_resultMessage = "Could not parse changelog";
|
||||
m_stage.store(UpdateStage::Failed, std::memory_order_release);
|
||||
return;
|
||||
}
|
||||
|
||||
m_changelogTag = ult::getStringFromJson(root.get(), "tag_name");
|
||||
const std::string body = ult::getStringFromJson(root.get(), "body");
|
||||
|
||||
m_changelogLines.clear();
|
||||
size_t pos = 0;
|
||||
while (pos <= body.size()) {
|
||||
size_t nl = body.find('\n', pos);
|
||||
std::string line = (nl == std::string::npos) ? body.substr(pos) : body.substr(pos, nl - pos);
|
||||
if (!line.empty() && line.back() == '\r')
|
||||
line.pop_back();
|
||||
if (!line.empty())
|
||||
m_changelogLines.push_back(line);
|
||||
if (nl == std::string::npos)
|
||||
break;
|
||||
pos = nl + 1;
|
||||
}
|
||||
if (m_changelogLines.empty())
|
||||
m_changelogLines.push_back("No changelog available for this release.");
|
||||
|
||||
m_stage.store(UpdateStage::ChangelogReady, std::memory_order_release);
|
||||
}
|
||||
|
||||
|
||||
void UpdateGui::listUI() {
|
||||
BaseMenuGui::refresh();
|
||||
@@ -201,7 +275,12 @@ void UpdateGui::listUI() {
|
||||
item->setClickListener([this, idx](u64 keys) -> bool {
|
||||
if (isBusy()) return false;
|
||||
if (keys & HidNpadButton_A) {
|
||||
startJob(idx, false);
|
||||
if (ult::limitedMemory) {
|
||||
m_status->setState(4, 100, kPackages[idx].displayName,
|
||||
"Updates cannot be performed on a 4MB overlay heap");
|
||||
return true;
|
||||
}
|
||||
startChangelogFetch(idx);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -242,6 +321,24 @@ void UpdateGui::pollJob() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stage == UpdateStage::FetchingChangelog) {
|
||||
m_status->setState(6, 0, pkgName, "Fetching changelog...");
|
||||
if (m_items[m_activePackage])
|
||||
m_items[m_activePackage]->setValue("...");
|
||||
return;
|
||||
}
|
||||
|
||||
if (stage == UpdateStage::ChangelogReady) {
|
||||
reapThread();
|
||||
m_stage.store(UpdateStage::Idle, std::memory_order_release);
|
||||
m_status->setState(0, 0, "", "");
|
||||
if (m_items[m_activePackage])
|
||||
m_items[m_activePackage]->setValue("");
|
||||
|
||||
m_pendingChangelogConfirm = true;
|
||||
return;
|
||||
}
|
||||
|
||||
int panelStage = (stage == UpdateStage::Done) ? 3
|
||||
: (stage == UpdateStage::Failed) ? 4 : 5;
|
||||
|
||||
@@ -263,6 +360,13 @@ bool UpdateGui::handleInput(u64 keysDown, u64 keysHeld,
|
||||
const HidTouchState &touchPos,
|
||||
HidAnalogStickState leftJoy,
|
||||
HidAnalogStickState rightJoy) {
|
||||
if (m_pendingChangelogConfirm) {
|
||||
m_pendingChangelogConfirm = false;
|
||||
tsl::changeTo<UpdateConfirmGui>(this, m_activePackage, kPackages[m_activePackage].displayName,
|
||||
m_changelogTag, m_changelogLines);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((keysDown & HidNpadButton_R) && isBusy()) {
|
||||
requestCancel();
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user