Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Keep the sign-in when the app's folder can't be written

Rafael Abud Ferreira7f4fc937e279
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index 99248b2..1c14ec8 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -164,6 +164,8 @@ int main(int argc, char** argv) {
platform::init();
log::setFile((platform::dataDir() + "/xcloud.log").c_str());
+ if (platform::dataDir() != "/data/homebrew/PPSA99810")
+ XC_LOGW("data folder: %s (/data/homebrew/PPSA99810 wasn't writable)", platform::dataDir().c_str());
XC_LOGI("=== PSBox Cloud Gaming starting ===");
XC_LOGI("firmware %s, PSBox %s", platform::firmwareVersion().c_str(), XC_APP_VERSION);
// Did the last session go down? (A crash leaves a marker; being closed
diff --git a/src/app/worker.cpp b/src/app/worker.cpp
index d541ad7..e02abe8 100644
--- a/src/app/worker.cpp
+++ b/src/app/worker.cpp
@@ -517,6 +517,8 @@ void signInAndLoad(auth::AuthManager& am, xcloud::GssvClient& gssv) {
XC_LOGI("AUTOPLAY END: consoles listed");
return;
}
+ if (!am.saved()) // the next start would ask for a code again: said now, not then
+ platform::notify(ui::tr(ui::Str::SignInNotSaved), "the sign-in couldn't be saved (notification)");
g_ui->setProfile(am.profile().gamertag, am.profile().gamerpicUrl, am.profile().gamerscore);
{
std::lock_guard<std::mutex> lock(g_argMutex);
diff --git a/src/auth/auth_manager.cpp b/src/auth/auth_manager.cpp
index 74ec96e..e3f49d6 100644
--- a/src/auth/auth_manager.cpp
+++ b/src/auth/auth_manager.cpp
@@ -8,6 +8,7 @@
#include "util/log.h"
#include <algorithm>
+#include <cerrno>
#include <cstdio>
namespace xc::auth {
@@ -48,9 +49,11 @@ bool AuthManager::save() const {
v.set("gamertag", profile_.gamertag);
v.set("xuid", profile_.xuid);
if (!platform::writeFileAtomic(storePath_, v.dump())) {
- XC_LOGE("could not write token store %s", storePath_.c_str());
+ XC_LOGE("could not write token store %s (errno %d)", storePath_.c_str(), errno);
+ saved_ = false;
return false;
}
+ saved_ = true;
return true;
}
diff --git a/src/auth/auth_manager.h b/src/auth/auth_manager.h
index 4fe8a83..472b40f 100644
--- a/src/auth/auth_manager.h
+++ b/src/auth/auth_manager.h
@@ -33,6 +33,9 @@ public:
explicit AuthManager(std::string storePath, MsaConfig cfg = {});
bool hasStoredAccount() const { return !tokens_.refreshToken.empty(); }
+ // False when the last sign-in couldn't be written to the store file: the
+ // next start asks for a code again.
+ bool saved() const { return saved_; }
// Full sign-in. Uses the stored refresh token when possible; otherwise
// starts the device-code flow and calls `onCode`. Blocking; `cancel` may be
@@ -54,6 +57,7 @@ public:
private:
bool load();
bool save() const;
+ mutable bool saved_ = true;
bool deviceCodeSignIn(const DeviceCodeCallback& onCode, std::string& err, const std::atomic<bool>* cancel);
bool xboxChain(xcloud::GssvClient& gssv, std::string& err);
void fetchGamerpic(const XblToken& xsts);
diff --git a/src/platform/ps5/platform_ps5.cpp b/src/platform/ps5/platform_ps5.cpp
index 925cdb2..3a0bbc6 100644
--- a/src/platform/ps5/platform_ps5.cpp
+++ b/src/platform/ps5/platform_ps5.cpp
@@ -3,6 +3,7 @@
#include "platform/platform.h"
#include "util/log.h"
+#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -41,11 +42,37 @@ std::string g_dataDir = "/data/homebrew/PPSA99810";
std::atomic<int> g_netPool{-1};
}
-bool init() {
- // If running in /data/homebrew/PPSA99810 or /app0
+// True when files can be made in `dir` (made first if missing).
+bool writable(const std::string& dir) {
struct stat st{};
- if (::stat(g_dataDir.c_str(), &st) != 0) {
- ::mkdir(g_dataDir.c_str(), 0777);
+ if (::stat(dir.c_str(), &st) != 0 && ::mkdir(dir.c_str(), 0777) != 0) return false;
+ std::string probe = dir + "/.write-test";
+ if (!writeFileAtomic(probe, "ok")) return false;
+ ::unlink(probe.c_str());
+ return true;
+}
+
+bool init() {
+ // The sign-in, settings and caches live in /data/homebrew/PPSA99810 (the
+ // app's own folder when installed there, kept apart from it on a USB
+ // drive). A folder the app can't write in (as an installer may leave
+ // it) would lose the sign-in at every start: then /data/psbox.
+ if (!writable(g_dataDir)) {
+ int err = errno;
+ const std::string fallback = "/data/psbox";
+ bool ok = writable(fallback);
+ XC_LOGW("data folder %s not writable (errno %d); %s", g_dataDir.c_str(), err,
+ ok ? ("using " + fallback).c_str() : "nor /data/psbox: nothing will be kept");
+ if (ok) {
+ // What can still be read there comes along (a folder that only
+ // refuses writes keeps the last sign-in).
+ for (const char* name : {"account.json", "settings.json"}) {
+ std::string text, mine;
+ if (readFile(g_dataDir + "/" + name, text) && !readFile(fallback + "/" + name, mine))
+ writeFileAtomic(fallback + "/" + name, text);
+ }
+ g_dataDir = fallback;
+ }
}
// libSceNet's resolver: 32 KiB pool.
int rc = sceNetInit();
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index 1da216a..64af23e 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -259,6 +259,7 @@ constexpr Column kEnglish = {
"Secure connections were refused because the PS5's date and time look wrong (it says %s). Set them in Settings > System > Date and Time, then try again.", // ClockWrong
"A secure connection was refused: something on the network (a DNS server, proxy or filter) is answering for Microsoft's sites. Try without it, then try again.", // ConnectionIntercepted
"PS5 date and time look wrong (%s): some content can't load. Set them in Settings > System > Date and Time.", // ClockWrongNotice
+ "Your sign-in couldn't be saved on the console, so it will be asked again next time. Please report it (Settings > △).", // SignInNotSaved
};
constexpr Column kPortugueseBR = {
@@ -488,6 +489,7 @@ constexpr Column kPortugueseBR = {
"As conexões seguras foram recusadas porque a data e a hora do PS5 parecem erradas (ele diz %s). Acerte em Configurações > Sistema > Data e hora e tente de novo.",
"Uma conexão segura foi recusada: algo na rede (um servidor DNS, proxy ou filtro) está respondendo no lugar dos sites da Microsoft. Tente sem ele e tente de novo.",
"A data e a hora do PS5 parecem erradas (%s): parte do conteúdo não carrega. Acerte em Configurações > Sistema > Data e hora.",
+ "Não foi possível salvar o login no console, então ele será pedido de novo na próxima vez. Relate o problema (Configurações > △).",
};
constexpr Column kSpanish = {
@@ -717,6 +719,7 @@ constexpr Column kSpanish = {
"Se rechazaron las conexiones seguras porque la fecha y la hora de la PS5 parecen incorrectas (indica %s). Ajústalas en Ajustes > Sistema > Fecha y hora y vuelve a intentarlo.",
"Se rechazó una conexión segura: algo en la red (un servidor DNS, proxy o filtro) responde en lugar de los sitios de Microsoft. Prueba sin él y vuelve a intentarlo.",
"La fecha y la hora de la PS5 parecen incorrectas (%s): parte del contenido no carga. Ajústalas en Ajustes > Sistema > Fecha y hora.",
+ "No se pudo guardar el inicio de sesión en la consola, así que se pedirá de nuevo la próxima vez. Infórmalo (Ajustes > △).",
};
constexpr Column kFrench = {
@@ -946,6 +949,7 @@ constexpr Column kFrench = {
"Les connexions sécurisées ont été refusées car la date et l'heure de la PS5 semblent fausses (elle indique %s). Réglez-les dans Paramètres > Système > Date et heure, puis réessayez.",
"Une connexion sécurisée a été refusée : quelque chose sur le réseau (serveur DNS, proxy ou filtre) répond à la place des sites de Microsoft. Essayez sans, puis réessayez.",
"La date et l'heure de la PS5 semblent fausses (%s) : une partie du contenu ne se charge pas. Réglez-les dans Paramètres > Système > Date et heure.",
+ "Impossible d'enregistrer la connexion sur la console : elle sera redemandée la prochaine fois. Signalez-le (Paramètres > △).",
};
constexpr Column kGerman = {
@@ -1175,6 +1179,7 @@ constexpr Column kGerman = {
"Sichere Verbindungen wurden abgelehnt, weil Datum und Uhrzeit der PS5 falsch zu sein scheinen (sie zeigt %s). Stelle sie unter Einstellungen > System > Datum und Uhrzeit ein und versuche es erneut.",
"Eine sichere Verbindung wurde abgelehnt: Etwas im Netzwerk (DNS-Server, Proxy oder Filter) antwortet anstelle der Microsoft-Seiten. Versuche es ohne und dann erneut.",
"Datum und Uhrzeit der PS5 scheinen falsch zu sein (%s): Einige Inhalte laden nicht. Stelle sie unter Einstellungen > System > Datum und Uhrzeit ein.",
+ "Die Anmeldung konnte nicht auf der Konsole gespeichert werden und wird beim nächsten Mal erneut abgefragt. Bitte melde das (Einstellungen > △).",
};
constexpr Column kItalian = {
@@ -1404,6 +1409,7 @@ constexpr Column kItalian = {
"Le connessioni sicure sono state rifiutate perché la data e l'ora della PS5 sembrano errate (indica %s). Impostale in Impostazioni > Sistema > Data e ora, poi riprova.",
"Una connessione sicura è stata rifiutata: qualcosa nella rete (un server DNS, proxy o filtro) risponde al posto dei siti Microsoft. Prova senza e riprova.",
"La data e l'ora della PS5 sembrano errate (%s): alcuni contenuti non si caricano. Impostale in Impostazioni > Sistema > Data e ora.",
+ "Impossibile salvare l'accesso sulla console: verrà richiesto di nuovo la prossima volta. Segnalalo (Impostazioni > △).",
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index c40e390..1187eee 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -236,6 +236,7 @@ enum class Str {
ClockWrong, // a certificate refused for the console's date: "%s" = that date
ConnectionIntercepted, // a certificate refused as untrusted or for another name
ClockWrongNotice, // notification: signed in, but some content refused for the clock; "%s" = the date
+ SignInNotSaved, // notification: the sign-in couldn't be written (asked again next start)
Count
};