Xbox Cloud Gaming app for PS5 Homebrew
C
feat(log): rotate xcloud.log to xcloud.prev.log on boot and show build ID in UI
Rafael Abud Ferreira6002539dc2d6
diff --git a/src/app/app_core.cpp b/src/app/app_core.cppindex 933f701..1c32d0f 100644--- a/src/app/app_core.cpp+++ b/src/app/app_core.cpp@@ -63,7 +63,13 @@ std::string crashMarkerPath() { return platform::dataDir() + "/crash.marker"; }// of the session that went down instead of this one.void openReport(const std::string& what, bool previousSession, const std::string& heading, const std::string& crash = {}) {std::string logText;- platform::readFile(platform::dataDir() + "/xcloud.log", logText);+ bool loadedPrev = false;+ if (previousSession) {+ loadedPrev = platform::readFile(platform::dataDir() + "/xcloud.prev.log", logText);+ }+ if (logText.empty()) {+ platform::readFile(platform::dataDir() + "/xcloud.log", logText);+ }if (logText.empty()) {logText = log::recentLogs();}@@ -83,7 +89,7 @@ void openReport(const std::string& what, bool previousSession, const std::stringinfo.firmware = platform::firmwareVersion();info.platform = platform::platformName();std::string platHeader = "[Platform: " + info.platform + "]\n";- info.log = platHeader + report::sanitize(report::logExcerpt(logText, previousSession), privateWords);+ info.log = platHeader + report::sanitize(report::logExcerpt(logText, previousSession && !loadedPrev), privateWords);info.crash = report::sanitize(crash, privateWords);std::string url = report::issueUrl(info);std::string detail = info.crash;@@ -249,11 +255,19 @@ ui::UiCaps uiCaps() {bool coreStartup() {platform::init();platform::setThreadAffinity(platform::ThreadRole::Main, "xcloud_main");- bool logOk = log::setFile((platform::dataDir() + "/xcloud.log").c_str());+ const std::string dataDir = platform::dataDir();+ const std::string logPath = dataDir + "/xcloud.log";+ const std::string prevLogPath = dataDir + "/xcloud.prev.log";+ struct stat logSt{};+ if (::stat(logPath.c_str(), &logSt) == 0 && logSt.st_size > 0) {+ std::remove(prevLogPath.c_str());+ std::rename(logPath.c_str(), prevLogPath.c_str());+ }+ bool logOk = log::setFile(logPath.c_str());if (!platform::dataDirNote().empty())- XC_LOGI("data folder %s: %s", platform::dataDir().c_str(), platform::dataDirNote().c_str());+ XC_LOGI("data folder %s: %s", dataDir.c_str(), platform::dataDirNote().c_str());if (!logOk)- XC_LOGW("could not open xcloud.log in %s: log kept in memory", platform::dataDir().c_str());+ XC_LOGW("could not open xcloud.log in %s: log kept in memory", dataDir.c_str());XC_LOGI("=== PSBox Cloud Gaming starting ===");XC_LOGI("firmware %s, PSBox %s (build %s, %s)", platform::firmwareVersion().c_str(), XC_APP_VERSION, XC_BUILD_ID,platform::platformName().c_str());@@ -650,7 +664,8 @@ bool coreStartup() {g_ui->setWebUrl(webServerUrl());{g_ui->setAllow1440(allow1440Locked());- g_ui->setUpdateState(XC_APP_VERSION, {}, false); // Settings shows this version before any check+ std::string displayVer = std::string(XC_APP_VERSION) + " (" + XC_BUILD_ID + ")";+ g_ui->setUpdateState(displayVer, {}, false); // Settings shows this version before any checkg_ui->setSettings(ui::choiceFromSettings(g_settings));g_ui->setPerGameSettings(g_settings.perGame);g_ui->setGyroDefaults(g_settings.gyroMode, g_settings.gyroLevel);diff --git a/src/app/updater.cpp b/src/app/updater.cppindex 3a1172d..b8f896b 100644--- a/src/app/updater.cpp+++ b/src/app/updater.cpp@@ -187,7 +187,7 @@ bool updatablePath(const std::string& path) {start = slash + 1;}static const std::set<std::string> kUsers = {"account.json", "settings.json", "library.json",- "library_cache.json", "prices.json", "xcloud.log", "autoplay.txt",+ "library_cache.json", "prices.json", "xcloud.log", "xcloud.prev.log", "autoplay.txt","update.journal", "store_import.done", "settings.json.bad"};std::string top = path.substr(0, path.find('/'));return !kUsers.count(path) && top != "imgcache" && top.rfind("update.", 0) != 0 && path.find(".ppm") == std::string::npos;diff --git a/src/app/web_server.cpp b/src/app/web_server.cppindex 18c6b0e..a4008f4 100644--- a/src/app/web_server.cpp+++ b/src/app/web_server.cpp@@ -454,11 +454,16 @@ WebServer::HttpResponse WebServer::handleRequest(const std::string& method, cons}return {200, "application/json", "", root.dump()};}- if (path == "/api/log") {+ if (path == "/api/log" || path == "/api/log/prev") {+ bool prev = (path == "/api/log/prev");+ std::string filename = prev ? "xcloud.prev.log" : "xcloud.log";std::string rawLog;- platform::readFile(platform::dataDir() + "/xcloud.log", rawLog);+ platform::readFile(platform::dataDir() + "/" + filename, rawLog);+ if (rawLog.empty() && prev) {+ platform::readFile(platform::dataDir() + "/xcloud.log", rawLog);+ }std::string clean = report::sanitize(rawLog, {});- return {200, "text/plain; charset=utf-8", "Content-Disposition: attachment; filename=\"xcloud.log\"\r\n", clean};+ return {200, "text/plain; charset=utf-8", "Content-Disposition: attachment; filename=\"" + filename + "\"\r\n", clean};}if (path == "/api/report-issue" || path.rfind("/api/report-issue?", 0) == 0) {std::string rawLog;diff --git a/src/app/web_server_html.cpp b/src/app/web_server_html.cppindex ba217c5..3744f2e 100644--- a/src/app/web_server_html.cpp+++ b/src/app/web_server_html.cpp@@ -1139,7 +1139,8 @@ input:checked + .slider-sw:before { transform: translateX(20px); }<h2>📋 Download de Logs Cru</h2><p>Baixe o arquivo <code>xcloud.log</code> sanitizado (sem tokens ou dados privados) para inspeção local ou envio manual.</p><div class="btn-row" style="margin-top: 0; margin-bottom: 14px; gap: 8px; display: flex; flex-wrap: wrap;">- <a href="/api/log" download="xcloud.log" class="btn btn-primary">⬇️ Baixar xcloud.log</a>+ <a href="/api/log" download="xcloud.log" class="btn btn-primary">⬇️ Baixar xcloud.log (Atual)</a>+ <a href="/api/log/prev" download="xcloud.prev.log" class="btn btn-secondary">⬇️ Baixar xcloud.prev.log (Anterior)</a><button type="button" class="btn" onclick="loadLogPreview()">Visualizar Últimas Linhas</button></div><pre id="logPreview">Clique em "Visualizar Últimas Linhas" ou "Pré-visualizar" para inspecionar os dados...</pre>diff --git a/src/app/worker_diagnostics.cpp b/src/app/worker_diagnostics.cppindex 1714088..74d8f34 100644--- a/src/app/worker_diagnostics.cpp+++ b/src/app/worker_diagnostics.cpp@@ -10,6 +10,7 @@#include "ui/strings.h"#include "util/log.h"#include "xcloud/regions.h"+#include "build_id.h"#include <algorithm>#include <cerrno>@@ -36,7 +37,8 @@ Release g_release;// Asks for the latest release; a newer one with a signed package is offered// (the pop-up, unless the user said "Not now" to it) and shown in Settings.void checkForUpdate() {- g_ui->setUpdateState(XC_APP_VERSION, {}, true);+ std::string displayVer = std::string(XC_APP_VERSION) + " (" + XC_BUILD_ID + ")";+ g_ui->setUpdateState(displayVer, {}, true);Release r;std::string err;bool found = findLatestRelease(r, err, g_autoplay.updateFeed);@@ -55,7 +57,7 @@ void checkForUpdate() {std::lock_guard<std::mutex> lock(g_releaseMutex);g_release = offer ? r : Release{};}- g_ui->setUpdateState(XC_APP_VERSION, offer || (newer && !selfUpdate) ? r.tag : std::string(), false, r.notes);+ g_ui->setUpdateState(displayVer, offer || (newer && !selfUpdate) ? r.tag : std::string(), false, r.notes);bool skipped;{std::lock_guard<std::mutex> lock(g_settingsMutex);