Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Move Playden to PPSA97031 through its self-update

Leonardo Lobato5c8c45b100fc
diff --git a/cmake/HomebrewPS5.cmake b/cmake/HomebrewPS5.cmake
index af64c56..8bcaf6d 100644
--- a/cmake/HomebrewPS5.cmake
+++ b/cmake/HomebrewPS5.cmake
@@ -3,8 +3,8 @@ function(playden_add_homebrew_ps5_title)
if(NOT DEFINED ENV{PS5_PAYLOAD_SDK})
message(FATAL_ERROR "PS5_PAYLOAD_SDK is unset; use scripts/build-homebrew-ps5.sh")
endif()
- if(NOT PLAYDEN_PS5_TITLE_ID MATCHES "^FAKE[0-9][0-9][0-9][0-9][0-9]$")
- message(FATAL_ERROR "PLAYDEN_PS5_TITLE_ID is required and must match FAKE12345")
+ if(NOT PLAYDEN_PS5_TITLE_ID MATCHES "^(FAKE|PPSA)[0-9][0-9][0-9][0-9][0-9]$")
+ message(FATAL_ERROR "PLAYDEN_PS5_TITLE_ID is required and must match FAKE12345 or PPSA12345")
endif()
set(sdk "$ENV{PS5_PAYLOAD_SDK}")
diff --git a/cmake/WriteNativePackageIdentity.cmake b/cmake/WriteNativePackageIdentity.cmake
index 5296c3e..9c2f919 100644
--- a/cmake/WriteNativePackageIdentity.cmake
+++ b/cmake/WriteNativePackageIdentity.cmake
@@ -1,4 +1,4 @@
-if(NOT DEFINED APP_DIR OR NOT TITLE_ID MATCHES "^FAKE[0-9][0-9][0-9][0-9][0-9]$")
+if(NOT DEFINED APP_DIR OR NOT TITLE_ID MATCHES "^(FAKE|PPSA)[0-9][0-9][0-9][0-9][0-9]$")
message(FATAL_ERROR "APP_DIR and a canonical native TITLE_ID are required")
endif()
if(NOT EXISTS "${APP_DIR}/eboot.bin" OR IS_DIRECTORY "${APP_DIR}/eboot.bin" OR IS_SYMLINK "${APP_DIR}/eboot.bin")
diff --git a/dependencies.lock.json b/dependencies.lock.json
index 1b2531e..1b4cf7b 100644
--- a/dependencies.lock.json
+++ b/dependencies.lock.json
@@ -10,7 +10,8 @@
"foundation_revision": "9c0b994a048521af6fb84c73ded364504fe250e9",
"protocol_sha256": "bb02c4aa814eaba7a7a423a31b29ff41f786212c2953678cf29434e85fa0f869",
"variants": {
- "FAKE77031": "910f12157ea9ddcb3fd1c84864b02a0eee95d33133bafdf9058426f66d3dd316"
+ "FAKE77031": "910f12157ea9ddcb3fd1c84864b02a0eee95d33133bafdf9058426f66d3dd316",
+ "PPSA97031": "2ec5761c36349c53e98b10b78037e7f70916fee9750292e793cbc86ac2b41c31"
},
"payload_sdk": {
"version": "v0.42",
@@ -34,7 +35,7 @@
"purpose": "Reads release zips for Playden's self-update; writing APIs left out"
},
"self_update_relaunch": {
- "sha256": "e32c635cca2d67b0a94b388e17711748c9f4955238a02914135b432d529396e2",
+ "sha256": "31a4ffb53de58b0bd5e9266a79a8a2f44df33586dffd4fe0fdb0df1510b14265",
"payload_sdk": "ps5_payload_sdk",
"source": "tools/self-update-relaunch/main.c; build with scripts/build-self-update-relaunch.sh (reproducible; sent by Playden to the payload loader on 127.0.0.1:9021 when it quits to finish an update)"
},
diff --git a/scripts/build-homebrew-ps5.sh b/scripts/build-homebrew-ps5.sh
index 835613a..051455f 100755
--- a/scripts/build-homebrew-ps5.sh
+++ b/scripts/build-homebrew-ps5.sh
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
# Package the selected direct Hui consumer locally, without console discovery, upload or launch.
+# PLAYDEN_PS5_TITLE_ID picks the title (default FAKE77031); its Lapy helper must be pinned in dependencies.lock.json.
set -euo pipefail
+title=${PLAYDEN_PS5_TITLE_ID:-FAKE77031}
root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
environment=${PLAYDEN_PS5_ENV:-"$root/scripts/with-env.sh"}
deps=${PLAYDEN_PS5_DEPS_DIR:-"$root/deps"}
@@ -8,7 +10,7 @@ hui=${PLAYDEN_HUI_SOURCE_DIR:-"$root/third_party/ps5-homebrew-ui"}
simulation=${PLAYDEN_UI_SIMULATION:-OFF}
native_access=${PLAYDEN_NATIVE_RUNTIME_ACCESS:-ON}
prospero_source=${PLAYDEN_PROSPERO_SOURCE_DIR:-"$root/third_party/prospero-win"}
-helper_build="$root/third_party/PS5-Lapy-JB-Daemon/build/owned_root_helper-FAKE77031"
+helper_build="$root/third_party/PS5-Lapy-JB-Daemon/build/owned_root_helper-$title"
lapy_helper=${PLAYDEN_LAPY_HELPER_ELF:-"$helper_build/lapy.elf"}
lapy_manifest=${PLAYDEN_LAPY_HELPER_MANIFEST:-"$helper_build/lapy-manifest.json"}
title_remover=${PLAYDEN_TITLE_REMOVER_ELF:-"$root/build/title-remover/title-remover.elf"}
@@ -38,11 +40,11 @@ if [[ ! -f "$root/scripts/network-deps/.deps/ps5/lib/libcurl.a" ]]; then
fi
bash "$environment" bash -c 'exec "$PS5_PAYLOAD_SDK/bin/prospero-cmake" "$@"' bash \
-G Ninja -S "$root" -B "$root/build/homebrew-ps5" -DCMAKE_BUILD_TYPE=Release \
- -DPLAYDEN_PLATFORM_PS5=ON -DPLAYDEN_PS5_TITLE_ID=FAKE77031 \
+ -DPLAYDEN_PLATFORM_PS5=ON -DPLAYDEN_PS5_TITLE_ID="$title" \
-DPLAYDEN_UI_SIMULATION="$simulation" \
-DPLAYDEN_NATIVE_RUNTIME_ACCESS="$native_access" -DPLAYDEN_PROSPERO_SOURCE_DIR="$prospero_source" \
-DPLAYDEN_LAPY_HELPER_ELF="$lapy_helper" -DPLAYDEN_LAPY_HELPER_MANIFEST="$lapy_manifest" \
-DPLAYDEN_TITLE_REMOVER_ELF="$title_remover" -DPLAYDEN_RELAUNCH_ELF="$relaunch" \
-DPLAYDEN_PS5_DEPS_DIR="$deps" -DPLAYDEN_HUI_SOURCE_DIR="$hui"
bash "$environment" cmake --build "$root/build/homebrew-ps5" --target playden-homebrew-ps5-package
-echo "Selected Hui package (not deployed): $root/build/homebrew-ps5/dist/FAKE77031"
+echo "Selected Hui package (not deployed): $root/build/homebrew-ps5/dist/$title"
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index 71fb655..64580c0 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -2136,6 +2136,7 @@ void Controller::TickSelfUpdate() {
else if (request == "cancel") self_update_->Cancel();
else if (request == "restart") self_update_->RequestRestart();
else if (request == "rollback") self_update_->RequestRollback();
+ else if (request == "open-successor") self_update_->RequestOpenSuccessor();
else if (request == "acknowledge") self_update_->AcknowledgeFinished();
else if (request == "kit-check") self_update_->CheckKit();
else if (request == "kit-install") self_update_->InstallKit();
@@ -2199,6 +2200,7 @@ void Controller::TickSelfUpdate() {
}
live.download_bytes = snapshot.download_bytes;
live.kit_needed = snapshot.kit_needed;
+ live.moves = snapshot.moves;
live.user_check = snapshot.user_check;
live.error = snapshot.error;
live.previous = snapshot.previous;
@@ -2207,6 +2209,7 @@ void Controller::TickSelfUpdate() {
live.current_notes_url = snapshot.current_notes_url;
live.whats_new = snapshot.whats_new;
live.quiet = snapshot.quiet;
+ live.moved_to = snapshot.moved_to;
live.finished_message = snapshot.finished_message;
live.finished_failed = snapshot.finished_failed;
live.kit_phase = update::KitInstallPhaseName(snapshot.kit.phase);
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index 48e3c87..599a0c2 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -395,6 +395,17 @@ int main() {
update_config.kit_manifest_sha256 = playden::runtime::kExpectedKitManifestSha256;
for (const auto& renamed : playden::runtime::kKitIdRenames)
if (std::string(renamed.to) == playden::runtime::kDevelopmentKitId) update_config.renamed_kit_ids.push_back(renamed.from);
+ // Playden moves from FAKE77031 to PPSA97031, the ID ProsperoStore can install: a release whose update
+ // information names PPSA97031 installs as that title, and ShadowMountPlus registers it.
+ if (std::string(PLAYDEN_PS5_TITLE_ID) == "FAKE77031") {
+ update_config.successor_title_id = "PPSA97031";
+ update_config.successor_root = "/data/homebrew/PPSA97031";
+ update_config.register_title = [](const std::string& folder) {
+ const auto added = playden::ps5::ShadowMountPost("/api/v1/manual/add", "{\"path\":\"" + folder + "\"}");
+ playden::ps5::ShadowMountPost("/api/v1/scan", "{}"); // deferred until no title runs
+ return added && added->find("\"status\":0") != std::string::npos;
+ };
+ }
update_config.appmeta_root = std::string("/user/appmeta/") + PLAYDEN_PS5_TITLE_ID;
update_config.registered_app_root = std::string("/user/app/") + PLAYDEN_PS5_TITLE_ID;
update_config.layout_journal = "/data/playden/runtime-state/layout-0.6.json";
@@ -925,7 +936,8 @@ int main() {
playden::app::AppendLogLine(log_root, "launch.log", "shutdown self-update start");
self_update.Shutdown();
playden::app::AppendLogLine(log_root, "launch.log", "shutdown done");
- if (self_update.Snapshot().restart_requested || self_update.Snapshot().rollback_requested) {
+ if (self_update.Snapshot().restart_requested || self_update.Snapshot().rollback_requested ||
+ self_update.Snapshot().open_successor_requested) {
// The relaunch payload starts first: it waits until Playden has gone, then opens it again.
std::string elf, error;
if (FILE* file = std::fopen((paths.title_root + "/self-update-relaunch.elf").c_str(), "rb")) {
@@ -936,12 +948,20 @@ int main() {
}
const std::string request = "/data/playden/self-update/relaunch-title";
FILE* title = std::fopen(request.c_str(), "w");
- const bool requested = title && std::fputs(PLAYDEN_PS5_TITLE_ID "\n", title) >= 0;
+ // The title to open, then this one (they differ when the update moves Playden to a new title).
+ const std::string titles = self_update.RelaunchTitle() + "\n" PLAYDEN_PS5_TITLE_ID "\n";
+ const bool requested = title && std::fputs(titles.c_str(), title) >= 0;
if (title) std::fclose(title);
const bool sent = !elf.empty() && requested && playden::ps5::SendToPayloadLoader(elf, &error);
playden::app::AppendLogLine(log_root, "update.log", std::string("self-update: relaunch payload ") +
(sent ? "sent" : "not sent: " + (elf.empty() ? std::string("missing") : error)));
const bool swapped = self_update.ApplyAtQuit();
+ // A move that did not happen reopens this title: the payload reads the request again once Playden is gone.
+ if (!swapped && self_update.RelaunchTitle() != PLAYDEN_PS5_TITLE_ID)
+ if (FILE* again = std::fopen(request.c_str(), "w")) {
+ std::fputs(PLAYDEN_PS5_TITLE_ID "\n" PLAYDEN_PS5_TITLE_ID "\n", again);
+ std::fclose(again);
+ }
playden::app::AppendLogLine(log_root, "update.log", std::string("self-update: quit ") +
(swapped ? "with the new files in place" : "without changing the app"));
}
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index 1d9cf5f..162f61f 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -498,7 +498,7 @@ std::string action_label(const std::string& key) {
{"about-version", "Version"}, {"self-update-install", "Download and install"},
{"self-update-restart", "Restart Playden"}, {"self-update-cancel", "Cancel update"},
{"kit-install", "Download"}, {"kit-cancel", "Cancel download"},
- {"self-update-back-confirm", "Go back"}, {"release-notes-ok", "OK"},
+ {"self-update-back-confirm", "Go back"}, {"release-notes-ok", "OK"}, {"successor-open", "Open the new Playden"},
{"about-build", "Build"}, {"about-framework", "Framework"}, {"about-platform", "Platform"},
{"about-kit", "Runtime kit"}, {"about-kit-source", "Built from"},
{"about-back", "Back"}, {"inject-library-refresh", "Refresh library fixture"},
@@ -1660,7 +1660,7 @@ void Simulation::UpdateSelfUpdate(const LiveSelfUpdate& update) {
before.part != update.part || before.current != update.current ||
before.bytes_per_second != update.bytes_per_second || before.previous != update.previous ||
before.quiet != update.quiet || before.current_notes_url != update.current_notes_url ||
- before.whats_new != update.whats_new ||
+ before.whats_new != update.whats_new || before.moved_to != update.moved_to ||
before.kit_phase != update.kit_phase || before.kit_done != update.kit_done ||
before.kit_total != update.kit_total || before.kit_error != update.kit_error ||
!update.finished_message.empty();
@@ -1680,7 +1680,9 @@ void Simulation::UpdateSelfUpdate(const LiveSelfUpdate& update) {
state_.self_update.finished_message.clear();
self_update_requests_.push_back("acknowledge");
}
- if (update.phase == "available" && update.quiet) {
+ if (!update.moved_to.empty() && before.moved_to.empty()) {
+ pending_update_prompt_ = "moved";
+ } else if (update.phase == "available" && update.quiet) {
self_update_prompted_ = "available " + update.available; // Settings still lists it
} else if (update.phase == "available" && self_update_prompted_ != "available " + update.available) {
self_update_prompted_ = "available " + update.available;
@@ -1746,9 +1748,18 @@ void Simulation::show_update_prompt() {
size + "You can sign in and keep using Playden while it downloads.";
open_modal(std::move(prompt));
} else if (pending_update_prompt_ == "available" && update.phase == "available") {
- ModalEntry prompt{"confirmation", "Playden " + update.available + (update.available.find("-beta.") != std::string::npos ? " (Beta)" : "") + " is available", state_.navigation.focus_key,
- {"self-update-install", "ready-later"}, 0, false};
- prompt.body = (update.notes.empty() ? std::string() : update.notes + "\n\n") + "The download is " +
+ const std::string beta = update.available.find("-beta.") != std::string::npos ? " (Beta)" : "";
+ // The same version as a new app: the step that follows an update from 0.7.1-beta.2 or older.
+ const bool same = update.moves && update.available == update.current;
+ ModalEntry prompt{"confirmation",
+ same ? std::string("Move Playden to its new app")
+ : "Playden " + update.available + beta + " is available",
+ state_.navigation.focus_key, {"self-update-install", "ready-later"}, 0, false};
+ const std::string move = "Playden " + update.available + " installs as a new app next to this one, so "
+ "ProsperoStore can install and update it. Your sign-in, games and settings stay, and "
+ "this app is removed once the new one has started.\n\n";
+ prompt.body = (same ? std::string() : update.notes.empty() ? std::string() : update.notes + "\n\n") +
+ (update.moves ? move : std::string()) + "The download is " +
format_bytes(update.download_bytes) +
(update.kit_needed ? ", with a new runtime kit." : ".") +
" You can keep using Playden while it downloads.";
@@ -1760,6 +1771,15 @@ void Simulation::show_update_prompt() {
prompt.body = "Restart Playden to finish the update. It closes and opens again by itself; if it doesn't, "
"open it from the Home screen.";
open_modal(std::move(prompt));
+ } else if (pending_update_prompt_ == "moved" && !update.moved_to.empty()) {
+ // This title updated to the new one, which hasn't started yet: its tile may be missing.
+ ModalEntry prompt{"confirmation", "Playden " + update.moved_to + " is a new app", state_.navigation.focus_key,
+ {"successor-open", "ready-later"}, 0, false};
+ prompt.body = "Playden " + update.moved_to + " was installed as a new app, and this one no longer updates. "
+ "Open the new Playden from Home.\n\nIf it isn't on Home, choose Open the new Playden: this "
+ "Playden closes, asks the PS5 to add the new one, and opens it. If this Playden opens again "
+ "instead, restart the PS5 and look on Home.";
+ open_modal(std::move(prompt));
} else if (pending_update_prompt_ == "whats-new" || pending_update_prompt_ == "release-notes") {
open_release_notes(pending_update_prompt_ == "whats-new");
}
@@ -1826,7 +1846,7 @@ void Simulation::close_game_modals() {
modals.erase(std::remove_if(modals.begin(), modals.end(), [](const ModalEntry& modal) {
return std::none_of(modal.action_keys.begin(), modal.action_keys.end(), [](const std::string& key) {
return key == "self-update-install" || key == "self-update-restart" || key == "release-notes-ok" ||
- key == "kit-install";
+ key == "kit-install" || key == "successor-open";
});
}), modals.end());
}
@@ -1850,6 +1870,11 @@ void Simulation::request_self_update_restart(const std::string& request) {
const auto& game = entry.second;
return game.status == "Preparing" || !game.uninstall_status.empty() || game.maintenance_running;
});
+ if (busy && request == "open-successor") {
+ show_alert("Open the new Playden later", "A game is being prepared or removed. When it is done, close Playden "
+ "and open the new one from Home, or restart the PS5 if it isn't there.");
+ return;
+ }
if (busy) {
show_alert("Restart Playden later", "A game is being prepared or removed. Restart Playden from Settings when it is done.");
return;
@@ -5238,8 +5263,10 @@ void Simulation::rebuild_view() {
item.value = "Checking…";
item.subtitle = "Looking for a newer Playden on GitHub";
} else if (update.phase == "available") {
- item.value = update.available + " available";
- item.subtitle = "Download " + format_bytes(update.download_bytes);
+ item.value = update.moves && update.available == update.current ? "New app available"
+ : update.available + " available";
+ item.subtitle = (update.moves ? "Installs as a new app · download " : "Download ") +
+ format_bytes(update.download_bytes);
} else if (update.phase == "downloading" || update.phase == "unpacking") {
item.value = update.total ? std::to_string(update.done * 100 / update.total) + "%" : "Working…";
item.subtitle = update.phase == "downloading" ? "Downloading Playden " + update.available
@@ -7560,6 +7587,7 @@ void Simulation::activate() {
else if (live() && action_name == "kit-cancel") { close_modal(); self_update_requests_.push_back("kit-cancel"); }
else if (live() && action_name == "self-update-cancel") { close_modal(); self_update_requests_.push_back("cancel"); }
else if (live() && action_name == "self-update-restart") { close_modal(); request_self_update_restart(); }
+ else if (live() && action_name == "successor-open") { close_modal(); request_self_update_restart("open-successor"); }
else if (live() && action_name == "self-update-notes") open_release_notes(false);
else if (action_name == "release-notes-ok") close_modal();
else if (live() && action_name == "self-update-back") {
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index 23c8001..213ab64 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -110,6 +110,7 @@ struct LiveSelfUpdate {
std::optional<int> eta_seconds;
std::uint64_t download_bytes = 0;
bool kit_needed = false;
+ bool moves = false; // the update installs Playden as a new app (its new title)
bool user_check = false; // the last check was asked for in Settings
std::string error;
std::string previous; // the version "go back" restores; empty when none is kept
@@ -118,6 +119,7 @@ struct LiveSelfUpdate {
std::string current_notes_url;
bool whats_new = false; // the previous run updated Playden: show its release notes once
bool quiet = false; // the available version is one the player went back from: no dialog
+ std::string moved_to; // Playden moved to its new title, which hasn't started yet: its version
std::string finished_message; // the previous run's update result, shown once
bool finished_failed = false;
// The kit-only install (first run, or a kit that isn't this version's): idle, checking, not-needed,
diff --git a/src/platform/ps5/title_remover.h b/src/platform/ps5/title_remover.h
index 4b32456..5a9a67f 100644
--- a/src/platform/ps5/title_remover.h
+++ b/src/platform/ps5/title_remover.h
@@ -21,7 +21,7 @@ struct TitleRemoverConfig {
// Exchange directory the payload reads (0755, owned by Playden; see
// tools/title-remover/main.c) and the payload itself, shipped in Playden's title.
std::filesystem::path request_directory = "/data/playden/title-remover";
- std::filesystem::path payload = "/data/homebrew/FAKE77031/title-remover.elf";
+ std::filesystem::path payload; // <title root>/title-remover.elf
// Sends the payload's bytes to the payload loader; false with a reason on failure.
std::function<bool(const std::string& elf, std::string* error)> send;
int result_polls = 60;
diff --git a/src/update/release.cpp b/src/update/release.cpp
index d298260..653b82d 100644
--- a/src/update/release.cpp
+++ b/src/update/release.cpp
@@ -103,6 +103,11 @@ const ReleaseAsset* Release::Find(std::string_view name) const {
return nullptr;
}
+const ReleaseAsset* Release::Manifest() const {
+ const auto* v2 = Find(kUpdateManifestAssetV2);
+ return v2 ? v2 : Find(kUpdateManifestAsset);
+}
+
namespace {
std::optional<Release> ReleaseFrom(const Json* doc, std::string* error) {
diff --git a/src/update/release.h b/src/update/release.h
index ccc7c49..32bc2e1 100644
--- a/src/update/release.h
+++ b/src/update/release.h
@@ -13,6 +13,9 @@
namespace playden::update {
inline constexpr const char* kUpdateManifestAsset = "playden-update.json";
+// From 0.8.0 a release has two: playden-update.json names a FAKE77031 build, the only one Playden 0.7.1-beta.2
+// and older can read; playden-update-v2.json names the PPSA97031 app, and newer builds read it first.
+inline constexpr const char* kUpdateManifestAssetV2 = "playden-update-v2.json";
struct ReleaseAsset {
std::string name;
@@ -29,6 +32,8 @@ struct Release {
bool prerelease = false;
std::vector<ReleaseAsset> assets;
const ReleaseAsset* Find(std::string_view name) const;
+ // The update information this build reads: playden-update-v2.json when the release has one.
+ const ReleaseAsset* Manifest() const;
};
// The JSON of GET /repos/<owner>/<repo>/releases/latest. The tag must be a version ("v0.3.0").
diff --git a/src/update/update_service.cpp b/src/update/update_service.cpp
index 2ff4a6a..b9af1af 100644
--- a/src/update/update_service.cpp
+++ b/src/update/update_service.cpp
@@ -180,7 +180,8 @@ void UpdateService::Fail(const std::string& message, const std::string& detail)
std::string UpdateService::StatePath() const { return config_.work_root + "/state.json"; }
bool UpdateService::SaveState(const std::string& phase, const std::string& extra) {
- const std::string text = "{\"phase\":" + Quote(phase) + extra + "}\n";
+ // The owner: after a move both titles share the work folder, and each leaves the other's state alone.
+ const std::string text = "{\"phase\":" + Quote(phase) + ",\"owner\":" + Quote(config_.title_id) + extra + "}\n";
const bool ok = WriteFileAtomically(StatePath(), text);
if (!ok) Log("cannot save " + StatePath());
return ok;
@@ -189,7 +190,8 @@ bool UpdateService::SaveState(const std::string& phase, const std::string& extra
std::string UpdateService::StagedFields() const {
const auto snapshot = Snapshot();
return ",\"version\":" + Quote(staged_version_.ToString()) + ",\"from\":" + Quote(config_.current.ToString()) +
- ",\"stage\":" + Quote(staged_folder_) + ",\"kit\":" + Quote(staged_kit_) + ",\"kit_id\":" +
+ ",\"stage\":" + Quote(staged_folder_) + ",\"title\":" + Quote(staged_title_) + ",\"kit\":" +
+ Quote(staged_kit_) + ",\"kit_id\":" +
Quote(staged_kit_id_) + ",\"notes\":" + Quote(snapshot.notes) + ",\"notes_url\":" + Quote(snapshot.notes_url);
}
@@ -380,6 +382,22 @@ void UpdateService::RequestRestart() {
});
}
+bool UpdateService::Moving() const {
+ return !staged_title_.empty() && staged_title_ != config_.title_id && staged_title_ == config_.successor_title_id &&
+ !config_.successor_root.empty();
+}
+
+void UpdateService::RequestOpenSuccessor() {
+ if (!superseded_) return;
+ Set([](UpdateSnapshot& s) { s.open_successor_requested = true; });
+}
+
+std::string UpdateService::RelaunchTitle() const {
+ const auto snapshot = Snapshot();
+ if (superseded_) return snapshot.open_successor_requested ? config_.successor_title_id : config_.title_id;
+ return snapshot.restart_requested && !snapshot.rollback_requested && Moving() ? staged_title_ : config_.title_id;
+}
+
DownloadOptions UpdateService::Downloads(const std::string& part) {
DownloadOptions options;
options.fetch = config_.fetch;
@@ -411,6 +429,37 @@ std::string UpdateService::ReadyKit(const KitPart& kit) const {
}
void UpdateService::Start() {
+ // The successor title is installed (this title moved to it, or it came from ProsperoStore): updates,
+ // kits and the shared update state are its business now, and this title points the player to it.
+ if (!config_.successor_root.empty() && Exists(config_.successor_root + "/eboot.bin")) {
+ superseded_ = true;
+ LoadCurrentNotes();
+ std::string text;
+ const auto state = ReadSmallFile(StatePath(), &text) ? steam::json::Parse(text) : std::nullopt;
+ const auto text_field = [&](const char* name) -> std::string {
+ const auto* value = state && state->is_object() ? state->Find(name) : nullptr;
+ return value && value->is_string() ? value->text() : std::string();
+ };
+ // The move this title made and the new title has not confirmed yet: ShadowMountPlus is asked again,
+ // in case the new title has no tile yet.
+ const bool unconfirmed = text_field("phase") == "applied" && text_field("moved_to") == config_.successor_title_id &&
+ (text_field("owner").empty() || text_field("owner") == config_.title_id);
+ Log(config_.successor_title_id + " is installed: updates are left to it" +
+ (unconfirmed ? "; the move to " + text_field("version") + " is not confirmed yet" : std::string()));
+ Set([&](UpdateSnapshot& s) {
+ // Not started yet: a dialog says where Playden went, in case its tile is missing. Else a short notice.
+ if (unconfirmed) {
+ s.moved_to = text_field("version");
+ } else {
+ s.finished_message = "Open the new Playden from Home.";
+ s.finished_failed = false;
+ }
+ });
+ if (unconfirmed && config_.register_title)
+ Run([this] { Log(config_.register_title(config_.successor_root) ? "new title registration requested"
+ : "new title registration not answered"); });
+ return;
+ }
FindPrevious();
LoadCurrentNotes();
RemoveReplacedKits();
@@ -431,6 +480,12 @@ void UpdateService::Start() {
return value && value->is_string() ? value->text() : std::string();
};
const std::string phase = field("phase");
+ // Another title's state (the two share the work folder after a move) is left alone, except the move to this one.
+ const std::string owner = field("owner");
+ if (!owner.empty() && owner != config_.title_id && !(phase == "applied" && field("moved_to") == config_.title_id)) {
+ Log("update state of " + owner + " left alone");
+ return;
+ }
if (phase == "applied") {
ConfirmApplied(text);
return;
@@ -439,9 +494,14 @@ void UpdateService::Start() {
const auto version = ParseVersion(field("version"));
const std::string stage = field("stage");
const std::string kit = field("kit");
+ // States from before the move to a successor title have no title: they are this one.
+ const std::string title = field("title").empty() ? config_.title_id : field("title");
+ const bool title_known = title == config_.title_id || (title == config_.successor_title_id && !config_.successor_root.empty());
const bool kit_present = kit.empty() || (config_.verify_kit && config_.verify_kit(kit));
- if (version && config_.current < *version && !stage.empty() && Exists(stage + "/eboot.bin") && kit_present) {
+ if (version && config_.current < *version && !stage.empty() && Exists(stage + "/eboot.bin") && kit_present &&
+ title_known) {
staged_folder_ = stage;
+ staged_title_ = title;
staged_version_ = *version;
staged_kit_ = kit;
staged_kit_id_ = field("kit_id");
@@ -542,6 +602,7 @@ void UpdateService::ConfirmApplied(const std::string& text) {
bool UpdateService::SetIncludeBetas(bool enabled) { return include_betas_.exchange(enabled) != enabled; }
void UpdateService::Check(bool user_asked) {
+ if (superseded_) return;
{
std::lock_guard<std::mutex> lock(shared_->mutex);
const auto phase = shared_->snapshot.phase;
@@ -552,6 +613,7 @@ void UpdateService::Check(bool user_asked) {
}
void UpdateService::Install() {
+ if (superseded_) return;
Run([this] {
// A track change can arrive while a download is being cancelled or a check is queued.
if (release_ && (release_->prerelease || release_->version.beta) && !include_betas_.load()) {
@@ -597,7 +659,7 @@ void UpdateService::DoCheck(bool user_asked) {
if (!release) return Fail("The latest release on GitHub could not be read.", error);
if (release->draft || release->prerelease || release->version.beta) release.reset();
}
- if (!release || !(config_.current < release->version)) {
+ const auto up_to_date = [&] {
Log("up to date: running " + config_.current.ToString());
release_.reset();
manifest_.reset();
@@ -606,16 +668,24 @@ void UpdateService::DoCheck(bool user_asked) {
s.phase = UpdatePhase::kUpToDate;
s.available = release ? release->version : config_.current;
});
- return;
- }
- const auto* asset = release->Find(kUpdateManifestAsset);
+ };
+ const bool can_move = !config_.successor_title_id.empty() && !config_.successor_root.empty();
+ // This version's own release can still move Playden: the FAKE77031 build that 0.7.1-beta.2 and older update
+ // to first (they read only playden-update.json) finds the same version under the successor title.
+ const bool newer = release && config_.current < release->version;
+ const bool same = release && release->version == config_.current;
+ if (!newer && !(same && can_move && release->Find(kUpdateManifestAssetV2))) return up_to_date();
+ const auto* asset = release->Manifest();
if (!asset) return Fail("Release " + release->tag + " has no update information. Install it by hand.", "no asset");
- const auto manifest_text = local ? read_local(kUpdateManifestAsset)
+ const auto manifest_text = local ? read_local(asset->name)
: FetchSmall(asset->url, 256 << 10, options, "application/octet-stream", &error);
if (!manifest_text) return Fail("Playden could not read the update information.", error);
const auto manifest = ParseUpdateManifest(*manifest_text, &error);
if (!manifest) return Fail("The update information of " + release->tag + " is not valid.", error);
- if (manifest->app_version != release->version || manifest->title_id != config_.title_id)
+ // A release under the successor title is a move: it installs next to this one.
+ const bool moves = can_move && manifest->title_id == config_.successor_title_id;
+ if (!newer && !moves) return up_to_date();
+ if (manifest->app_version != release->version || (manifest->title_id != config_.title_id && !moves))
return Fail("The update information does not match release " + release->tag + ".", "version or title");
if (config_.current < manifest->min_from)
return Fail("Playden " + release->version.ToString() + " cannot update from this version. Install it by hand.",
@@ -646,7 +716,8 @@ void UpdateService::DoCheck(bool user_asked) {
manifest_ = *manifest;
if (kit_needed) kit_zip_ = *kit;
else kit_zip_.reset();
- Log("update " + release->tag + " available: app " + std::to_string(app->size) + " bytes, kit " +
+ Log("update " + release->tag + " available" + (moves ? " as " + manifest->title_id : std::string()) + ": app " +
+ std::to_string(app->size) + " bytes, kit " +
(kit_needed ? std::to_string(kit->size) + " bytes" : "already installed"));
std::string declined;
ReadSmallFile(config_.work_root + "/declined-version", &declined, 64);
@@ -659,6 +730,7 @@ void UpdateService::DoCheck(bool user_asked) {
s.notes_url = release->page.empty() ? PageFor(release->tag) : release->page;
s.kit_needed = kit_needed;
s.download_bytes = app->size + (kit_needed ? kit->size : 0);
+ s.moves = moves;
});
}
@@ -685,6 +757,7 @@ void UpdateService::DoInstall() {
kit_folder = ReadyKit(manifest.kit);
}
if (!StageApp(release, manifest)) return;
+ staged_title_ = manifest.title_id;
staged_version_ = release.version;
// The installed kit already matches: nothing to swap for it.
staged_kit_ = kit_folder == config_.kits_root + "/" + manifest.kit.kit_id ? std::string() : kit_folder;
@@ -829,11 +902,13 @@ std::optional<std::vector<Release>> UpdateService::FetchReleases(std::string* er
}
void UpdateService::CheckKit() {
+ if (superseded_) return;
if (config_.kit_id.empty() || config_.kit_manifest_sha256.empty()) return;
Run([this] { DoCheckKit(); });
}
void UpdateService::InstallKit() {
+ if (superseded_) return;
Run([this] {
if (!kit_asset_ || !kit_part_) DoCheckKit();
if (Snapshot().kit.phase != KitInstallPhase::kAvailable) return;
@@ -868,18 +943,19 @@ void UpdateService::DoCheckKit() {
for (const auto& release : *releases)
if (!release.draft && release.version == config_.current) own = &release;
if (!own) return unavailable("no release has version " + config_.current.ToString());
- const auto* manifest_asset = own->Find(kUpdateManifestAsset);
+ const auto* manifest_asset = own->Manifest();
if (!manifest_asset) return unavailable("release " + own->tag + " has no update information");
auto options = Downloads("");
options.max_attempts = 2;
- const bool local = !config_.local_release_dir.empty() && Exists(config_.local_release_dir + "/" + kUpdateManifestAsset);
+ const std::string local_manifest = config_.local_release_dir + "/" + manifest_asset->name;
+ const bool local = !config_.local_release_dir.empty() && Exists(local_manifest);
std::optional<std::string> manifest_text;
if (!local) {
manifest_text = FetchSmall(manifest_asset->url, 256 << 10, options, "application/octet-stream", &error);
- } else if (std::string text; ReadSmallFile(config_.local_release_dir + "/" + kUpdateManifestAsset, &text, 256 << 10)) {
+ } else if (std::string text; ReadSmallFile(local_manifest, &text, 256 << 10)) {
manifest_text = std::move(text);
} else {
- error = std::string("cannot read ") + kUpdateManifestAsset;
+ error = "cannot read " + manifest_asset->name;
}
if (!manifest_text) return FailKit("Playden could not read the kit information.", error);
const auto manifest = ParseUpdateManifest(*manifest_text, &error);
@@ -1030,7 +1106,7 @@ bool UpdateService::StageApp(const Release& release, const UpdateManifest& manif
const auto full_version = has_full ? ParseVersion(full_text)
: (Exists(stage + "/playden-version") ? std::nullopt : content_version);
const Version numeric{release.version.major, release.version.minor, release.version.patch};
- if (!title || !title->is_string() || title->text() != config_.title_id || !content_version ||
+ if (!title || !title->is_string() || title->text() != manifest.title_id || !content_version ||
*content_version != numeric || !full_version || *full_version != release.version ||
!Exists(stage + "/eboot.bin")) {
RemoveOwnedTree(stage);
@@ -1135,8 +1211,16 @@ bool UpdateService::RollBackAtQuit() {
}
bool UpdateService::ApplyAtQuit() {
+ if (superseded_) {
+ // Asked for from the old title: ShadowMountPlus adds the new title once this one has closed.
+ if (!Snapshot().open_successor_requested) return false;
+ const bool registered = config_.register_title && config_.register_title(config_.successor_root);
+ Log(std::string("opening ") + config_.successor_title_id + (registered ? ", registration requested" : ", registration not answered"));
+ return true;
+ }
if (Snapshot().rollback_requested) return RollBackAtQuit();
if (!Snapshot().restart_requested || staged_folder_.empty()) return false;
+ if (Moving()) return MoveAtQuit();
const std::string stamp = std::to_string(config_.now());
const std::string backup = config_.work_root + "/backup/" + config_.current.ToString() + "-" + stamp;
const std::string installed_kit = staged_kit_id_.empty() ? std::string() : config_.kits_root + "/" + staged_kit_id_;
@@ -1167,27 +1251,14 @@ bool UpdateService::ApplyAtQuit() {
if (name.compare(0, 10, ".previous-") == 0) RemoveTree(config_.kits_root + "/" + name);
// One transaction: the kit first, then the app; a failed app swap puts the kit back.
if (!staged_kit_.empty()) {
- if (!Exists(staged_kit_)) {
- swap.error = "staged kit is missing";
- return false;
- }
- if (Exists(installed_kit) && rename(installed_kit.c_str(), previous_kit.c_str()) != 0) {
- swap.error = "cannot move the installed kit aside";
- return false;
- }
- if (rename(staged_kit_.c_str(), installed_kit.c_str()) != 0) {
- rename(previous_kit.c_str(), installed_kit.c_str());
- swap.error = "cannot move the new kit in";
- return false;
- }
+ if (!SwapKitIn(installed_kit, previous_kit, &swap.error)) return false;
kit_swapped = true;
}
MakeFolders(config_.work_root + "/backup");
swap = SwapApp(config_.installed_root, staged_folder_, backup, log);
if (!swap.ok) {
if (kit_swapped) {
- rename(installed_kit.c_str(), staged_kit_.c_str());
- if (Exists(previous_kit)) rename(previous_kit.c_str(), installed_kit.c_str());
+ SwapKitBack(installed_kit, previous_kit);
kit_swapped = false;
}
return false;
@@ -1209,4 +1280,88 @@ bool UpdateService::ApplyAtQuit() {
return true;
}
+bool UpdateService::SwapKitIn(const std::string& installed_kit, const std::string& previous_kit, std::string* error) {
+ if (!Exists(staged_kit_)) {
+ *error = "staged kit is missing";
+ return false;
+ }
+ if (Exists(installed_kit) && rename(installed_kit.c_str(), previous_kit.c_str()) != 0) {
+ *error = "cannot move the installed kit aside";
+ return false;
+ }
+ if (rename(staged_kit_.c_str(), installed_kit.c_str()) != 0) {
+ rename(previous_kit.c_str(), installed_kit.c_str());
+ *error = "cannot move the new kit in";
+ return false;
+ }
+ return true;
+}
+
+void UpdateService::SwapKitBack(const std::string& installed_kit, const std::string& previous_kit) {
+ rename(installed_kit.c_str(), staged_kit_.c_str());
+ if (Exists(previous_kit)) rename(previous_kit.c_str(), installed_kit.c_str());
+}
+
+// A release under the successor title goes into its own folder: this app stays as it is (it runs until
+// the process exits, and is the way back if the new title does not open). ShadowMountPlus defers its
+// scan while a title runs and registers the new title once this one has closed.
+bool UpdateService::MoveAtQuit() {
+ const std::string stamp = std::to_string(config_.now());
+ const std::string installed_kit = staged_kit_id_.empty() ? std::string() : config_.kits_root + "/" + staged_kit_id_;
+ const std::string previous_kit = config_.kits_root + "/.previous-" + staged_kit_id_ + "-" + stamp;
+ // A folder already at the successor's place (an earlier try, or a copy installed by hand) is moved aside.
+ const std::string aside = config_.work_root + "/replaced/" + staged_title_ + "-" + stamp;
+ const auto applied = [&](bool kit_moved) {
+ return ",\"version\":" + Quote(staged_version_.ToString()) + ",\"from\":" + Quote(config_.current.ToString()) +
+ ",\"moved_to\":" + Quote(staged_title_) + ",\"notes\":" + Quote(Snapshot().notes) + ",\"notes_url\":" +
+ Quote(Snapshot().notes_url) + ",\"kit_id\":" + Quote(staged_kit_id_) + ",\"previous_kit\":" +
+ Quote(kit_moved ? previous_kit : std::string()) + ",\"next_kit\":" +
+ Quote(kit_moved ? staged_kit_ : std::string());
+ };
+ if (!SaveState("applied", applied(!staged_kit_.empty()))) {
+ Log("move failed: cannot save the state");
+ return false;
+ }
+ std::string error;
+ bool kit_swapped = false;
+ const bool moved = config_.as_root([&] {
+ // As for a swap: one previous version and kit are kept. The backups are of this title's app, which
+ // the new title must never restore into its own folder, so none is left.
+ for (const auto& name : ListFolder(config_.work_root + "/backup")) RemoveTree(config_.work_root + "/backup/" + name);
+ for (const auto& name : ListFolder(config_.kits_root))
+ if (name.compare(0, 10, ".previous-") == 0) RemoveTree(config_.kits_root + "/" + name);
+ if (!staged_kit_.empty()) {
+ if (!SwapKitIn(installed_kit, previous_kit, &error)) return false;
+ kit_swapped = true;
+ }
+ const bool occupied = Exists(config_.successor_root);
+ if (occupied && (!MakeFolders(config_.work_root + "/replaced") ||
+ rename(config_.successor_root.c_str(), aside.c_str()) != 0)) {
+ error = "cannot move " + config_.successor_root + " aside";
+ } else if (rename(staged_folder_.c_str(), config_.successor_root.c_str()) != 0) {
+ error = "cannot move the new app to " + config_.successor_root;
+ if (occupied) rename(aside.c_str(), config_.successor_root.c_str());
+ } else {
+ // Like an app folder deployed by hand: Playden writes in it as the app's user.
+ chmod(config_.successor_root.c_str(), 0777);
+ return true;
+ }
+ if (kit_swapped) {
+ SwapKitBack(installed_kit, previous_kit);
+ kit_swapped = false;
+ }
+ return false;
+ });
+ if (!moved) {
+ Log("move failed: " + error);
+ SaveState("staged", StagedFields()); // still staged: the next quit tries again
+ return false;
+ }
+ SaveState("applied", applied(kit_swapped && Exists(previous_kit)));
+ const bool registered = config_.register_title && config_.register_title(config_.successor_root);
+ Log("moved to " + staged_title_ + " " + staged_version_.ToString() + " at " + config_.successor_root +
+ (kit_swapped ? " with a new kit" : "") + (registered ? ", registration requested" : ", registration not answered"));
+ return true;
+}
+
} // namespace playden::update
diff --git a/src/update/update_service.h b/src/update/update_service.h
index fea2ab0..c064f24 100644
--- a/src/update/update_service.h
+++ b/src/update/update_service.h
@@ -32,6 +32,13 @@ struct UpdateConfig {
// Ids the kit had before (runtime::kKitIdRenames): a Playden that used one leaves its kit at
// <kits_root>/<that id> when it updates to this one, and Start retires it as a previous kit.
std::vector<std::string> renamed_kit_ids;
+ // The title Playden moves to when a release's update information names it instead of title_id
+ // (FAKE77031 -> PPSA97031, the ID ProsperoStore can install). The update goes into
+ // successor_root, the running app stays, and register_title asks ShadowMountPlus to add it.
+ // Empty: the update information must name title_id.
+ std::string successor_title_id;
+ std::string successor_root; // /data/homebrew/PPSA97031
+ std::function<bool(const std::string& folder)> register_title;
std::string appmeta_root; // /user/appmeta/FAKE77031
std::string registered_app_root; // /user/app/FAKE77031
// The 0.6 layout move's record (/data/playden/runtime-state/layout-0.6.json). While it exists,
@@ -109,12 +116,16 @@ struct UpdateSnapshot {
std::uint64_t total = 0;
std::uint64_t download_bytes = 0; // what Install will download
bool kit_needed = false;
+ bool moves = false; // the available release installs Playden as the successor title
std::string error; // for kFailed: one short sentence
bool user_check = false; // the last check was asked for in Settings
bool restart_requested = false;
// The version kept from the last update, which "go back" restores; empty when there is none.
std::string previous;
bool rollback_requested = false;
+ // This title moved to the successor, which has not started yet: the version it moved to.
+ std::string moved_to;
+ bool open_successor_requested = false;
// The available version is one the player went back from: Settings lists it, no dialog offers it.
bool quiet = false;
// One-shot result of the previous run's update ("Playden was updated to 0.3.0."), shown once.
@@ -148,6 +159,11 @@ class UpdateService {
void InstallKit();
// Marks a staged update to be applied when Playden quits.
void RequestRestart();
+ // The successor is installed: when Playden quits, it is registered again and opened instead.
+ void RequestOpenSuccessor();
+ // The title to open after quitting: the successor while a move to it is staged (or it was asked
+ // for), else title_id.
+ std::string RelaunchTitle() const;
// Marks the previous version (and its kit) to be put back when Playden quits.
void RequestRollback();
UpdateSnapshot Snapshot() const;
@@ -159,7 +175,8 @@ class UpdateService {
// Stops the worker (cancels a download; the bytes are kept for next time).
void Shutdown();
// Last step before the process exits, with every other service stopped: swaps the app folder
- // when a staged update was requested. Returns true when the new version is in place.
+ // when a staged update was requested. Returns true when the new version is in place (or, with
+ // the successor asked for, once its registration is requested).
bool ApplyAtQuit();
// The newest app backup (".../backup/<version>-<time>") and its version, when it is complete.
struct Backup {
@@ -175,6 +192,12 @@ class UpdateService {
void DoInstall();
void ConfirmApplied(const std::string& state);
bool RollBackAtQuit();
+ bool MoveAtQuit();
+ // Puts the staged kit in place, the installed one going to previous_kit; as root. SwapKitBack undoes it.
+ bool SwapKitIn(const std::string& installed_kit, const std::string& previous_kit, std::string* error);
+ void SwapKitBack(const std::string& installed_kit, const std::string& previous_kit);
+ // Whether a staged update moves Playden to the successor title.
+ bool Moving() const;
// Why going back to `to` is refused (it can't read the 0.6 data layout), or empty.
std::string LayoutRefusal(const Version& to) const;
void FindPrevious();
@@ -213,7 +236,10 @@ class UpdateService {
std::optional<ReleaseAsset> kit_zip_;
// The staged update (from this run or a previous one): app folder, version, and the staged kit
// folder with its kit id (empty when the installed kit is already the release's).
+ // The successor title is installed: this title no longer updates or installs kits.
+ bool superseded_ = false;
std::string staged_folder_;
+ std::string staged_title_;
Version staged_version_;
std::string staged_kit_;
std::string staged_kit_id_;
diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cpp
index 02b2340..8077748 100644
--- a/tests/homebrew_live_model_test.cpp
+++ b/tests/homebrew_live_model_test.cpp
@@ -1006,6 +1006,71 @@ void live_self_update(const std::filesystem::path& base) {
"update: Download and install still has the focus");
}
+ // The old title after the move to the new one, which hasn't started yet: a dialog says where Playden
+ // went, and its button quits to open the new title (registered again at quit). It shows once.
+ {
+ auto old_title = make_live(base);
+ old_title.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
+ check(old_title.UpdateLibrary({{}, false, {}, false, true, 100}), "moved: library delivered");
+ LiveSelfUpdate moved;
+ moved.current = "0.7.1";
+ moved.moved_to = "0.8.0";
+ old_title.UpdateSelfUpdate(moved);
+ check(!old_title.state().navigation.modals.empty() &&
+ old_title.state().navigation.modals.back().title == "Playden 0.8.0 is a new app" &&
+ old_title.state().navigation.modals.back().body.find("restart the PS5") != std::string::npos,
+ "moved: the old title says where Playden went");
+ playden::GameSummary game;
+ game.id = SteamId(220);
+ game.title = "Half-Life 2";
+ check(old_title.UpdateLibrary({{game}, false, {}, false, true, 100}) &&
+ !old_title.state().navigation.modals.empty(),
+ "moved: the games arriving leave the dialog open");
+ check(old_title.action("cross") && old_title.state().quit_requested &&
+ old_title.TakeSelfUpdateRequests() == std::vector<std::string>{"open-successor"},
+ "moved: Open the new Playden quits to open it");
+ auto later = make_live(base);
+ later.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
+ check(later.UpdateLibrary({{}, false, {}, false, true, 100}), "moved: library delivered again");
+ later.UpdateSelfUpdate(moved);
+ check(later.action("right") && later.action("cross") && later.state().navigation.modals.empty() &&
+ !later.state().quit_requested && later.TakeSelfUpdateRequests().empty(),
+ "moved: Later keeps this Playden open");
+ later.UpdateSelfUpdate(moved);
+ check(later.state().navigation.modals.empty(), "moved: the dialog shows once");
+ }
+
+ // The bridge (0.8.0 as the old title) offers the same version as a new app; a newer move says so too.
+ {
+ auto bridge = make_live(base);
+ bridge.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
+ check(bridge.UpdateLibrary({{}, false, {}, false, true, 100}), "bridge: library delivered");
+ LiveSelfUpdate move;
+ move.current = "0.8.0";
+ move.phase = "available";
+ move.available = "0.8.0";
+ move.moves = true;
+ move.notes = "Notes already seen.";
+ bridge.UpdateSelfUpdate(move);
+ check(!bridge.state().navigation.modals.empty() &&
+ bridge.state().navigation.modals.back().title == "Move Playden to its new app" &&
+ bridge.state().navigation.modals.back().body.find("new app next to this one") != std::string::npos &&
+ bridge.state().navigation.modals.back().body.find("Notes already seen.") == std::string::npos,
+ "bridge: the same version is offered as a move");
+ check(bridge.action("cross") && bridge.TakeSelfUpdateRequests() == std::vector<std::string>{"install"},
+ "bridge: the move downloads like an update");
+ auto newer = make_live(base);
+ newer.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
+ check(newer.UpdateLibrary({{}, false, {}, false, true, 100}), "bridge: library delivered again");
+ move.current = "0.7.1";
+ newer.UpdateSelfUpdate(move);
+ check(!newer.state().navigation.modals.empty() &&
+ newer.state().navigation.modals.back().title == "Playden 0.8.0 is available" &&
+ newer.state().navigation.modals.back().body.find("Notes already seen.") != std::string::npos &&
+ newer.state().navigation.modals.back().body.find("new app next to this one") != std::string::npos,
+ "bridge: a newer move keeps its notes and says it is a new app");
+ }
+
// A failed install says why; the previous run's result shows once.
auto failing = make_live(base);
failing.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});
diff --git a/tests/self_update_service_test.cpp b/tests/self_update_service_test.cpp
index 13fd569..ac9b8db 100644
--- a/tests/self_update_service_test.cpp
+++ b/tests/self_update_service_test.cpp
@@ -86,15 +86,16 @@ struct Server {
}
};
-std::string AppZip(const std::string& version_text, const std::string& content_version, const std::string& full_version = "") {
+std::string AppZip(const std::string& version_text, const std::string& content_version, const std::string& full_version = "",
+ const std::string& title = "FAKE77031") {
const std::string top = "playden-ps5-" + version_text + "/";
return zip_fixture::Build({{top + "tools/console_title_deploy.py", "py"},
- {top + "FAKE77031/eboot.bin", "eboot " + version_text},
- {top + "FAKE77031/playden-version", full_version.empty() ? version_text + "\n" : full_version},
- {top + "FAKE77031/sce_sys/param.json",
- R"({"titleId":"FAKE77031","contentVersion":")" + content_version + R"("})"},
- {top + "FAKE77031/assets/a.txt", "asset " + version_text},
- {top + "FAKE77031/logs/", "", 040755}});
+ {top + title + "/eboot.bin", "eboot " + version_text},
+ {top + title + "/playden-version", full_version.empty() ? version_text + "\n" : full_version},
+ {top + title + "/sce_sys/param.json",
+ R"({"titleId":")" + title + R"(","contentVersion":")" + content_version + R"("})"},
+ {top + title + "/assets/a.txt", "asset " + version_text},
+ {top + title + "/logs/", "", 040755}});
}
std::string KitZip() {
@@ -105,14 +106,15 @@ std::string KitZip() {
void Publish(Server& server, const std::string& tag, const std::string& min_from = "0.2.0",
const std::string& content_version = "00.003.000", bool with_kit = true, bool with_digests = true,
- const std::string& kit_revision = "r9", const std::string& full_version = "") {
+ const std::string& kit_revision = "r9", const std::string& full_version = "",
+ const std::string& title = "FAKE77031") {
const std::string version_text = tag.substr(1);
- const std::string app = AppZip(version_text, content_version, full_version);
+ const std::string app = AppZip(version_text, content_version, full_version, title);
const std::string kit = KitZip();
const std::string manifest =
- R"({"format":1,"app":{"version":")" + version_text + R"(","title_id":"FAKE77031","min_from":")" + min_from +
- R"(","asset":"playden-ps5-)" + version_text + R"(.zip","prefix":"playden-ps5-)" + version_text +
- R"(/FAKE77031/"},"kit":{"kit_id":"kitid","revision":")" + kit_revision + R"(","manifest_sha256":")" + kKitSha +
+ R"({"format":1,"app":{"version":")" + version_text + R"(","title_id":")" + title + R"(","min_from":")" + min_from +
+ R"(","asset":"playden-ps5-)" + version_text + R"(.zip","prefix":"playden-ps5-)" + version_text + "/" + title +
+ R"(/"},"kit":{"kit_id":"kitid","revision":")" + kit_revision + R"(","manifest_sha256":")" + kKitSha +
R"(","asset":"playden-kit-h-r9.zip","prefix":"playden-kit-h-r9/kitid/"},"notes":"New things."})";
server.files[kDownload + "playden-update.json"] = manifest;
server.files[kDownload + "playden-ps5-" + version_text + ".zip"] = app;
@@ -999,6 +1001,241 @@ int main() {
CHECK(offered.Snapshot().rollback_requested);
RemoveTree(fixture.root);
}
+ // A release under the successor title installs next to this one: the running app stays, the new
+ // title is registered, the old title points the player to it, and the new title confirms the update.
+ {
+ Fixture fixture;
+ fixture.root = zip_fixture::TempFolder("service-move");
+ Installed(fixture.root);
+ const std::string old_app = fixture.root + "/homebrew/FAKE77031";
+ const std::string new_app = fixture.root + "/homebrew/PPSA97031";
+ const std::string state = fixture.root + "/playden/self-update/state.json";
+ Put(fixture.root + "/playden/self-update/backup/0.7.0-900/eboot.bin", "eboot 0.7.0");
+ Publish(fixture.server, "v0.8.0", "0.7.0", "00.008.000", true, true, "r9", "", "PPSA97031");
+ std::vector<std::string> registered;
+ std::mutex registered_mutex;
+ const auto moving = [&](Version current) {
+ auto config = fixture.Config(current);
+ config.successor_title_id = "PPSA97031";
+ config.successor_root = new_app;
+ config.register_title = [&](const std::string& folder) {
+ std::lock_guard<std::mutex> lock(registered_mutex);
+ registered.push_back(folder);
+ return true;
+ };
+ return config;
+ };
+ // Without a successor (or for another title) the release is refused, as before.
+ {
+ UpdateService plain(fixture.Config({0, 7, 1}));
+ plain.Check(true); Wait(plain);
+ CHECK(plain.Snapshot().phase == UpdatePhase::kFailed);
+ auto other = moving({0, 7, 1});
+ other.successor_title_id = "PPSA12345";
+ UpdateService refused(other);
+ refused.Check(true); Wait(refused);
+ CHECK(refused.Snapshot().phase == UpdatePhase::kFailed);
+ }
+ {
+ UpdateService service(moving({0, 7, 1}));
+ service.Start();
+ service.Install(); Wait(service);
+ CHECK(service.Snapshot().phase == UpdatePhase::kStaged);
+ CHECK(Read(state).find("\"title\":\"PPSA97031\"") != std::string::npos);
+ CHECK(service.RelaunchTitle() == "FAKE77031"); // nothing asked yet
+ service.RequestRestart();
+ CHECK(service.RelaunchTitle() == "PPSA97031");
+ service.Shutdown();
+ // A start in between keeps the staged move.
+ UpdateService restarted(moving({0, 7, 1}));
+ restarted.Start();
+ CHECK(restarted.Snapshot().phase == UpdatePhase::kStaged);
+ restarted.RequestRestart();
+ CHECK(restarted.RelaunchTitle() == "PPSA97031");
+ restarted.Shutdown();
+ // A folder that appeared at the new title's place since the start is moved aside, not merged.
+ Put(new_app + "/eboot.bin", "eboot by hand");
+ CHECK(restarted.ApplyAtQuit());
+ }
+ CHECK(Read(new_app + "/eboot.bin") == "eboot 0.8.0" && Read(new_app + "/assets/a.txt") == "asset 0.8.0");
+ CHECK(Read(old_app + "/eboot.bin") == "eboot 0.2.0" && Read(old_app + "/playden-data/session") == "session");
+ CHECK(Read(fixture.root + "/playden/self-update/replaced/PPSA97031-1000/eboot.bin") == "eboot by hand");
+ CHECK(registered.size() == 1 && registered[0] == new_app);
+ CHECK(Read(fixture.root + "/playden/kits/kitid/manifest.json") == kKitSha);
+ // No backup is left: the new title must never put the old title's app into its own folder.
+ CHECK(ListFolder(fixture.root + "/playden/self-update/backup").empty());
+ CHECK(Read(state).find("\"moved_to\":\"PPSA97031\"") != std::string::npos);
+ // The old title is opened instead: it says where the update went, keeps the state and asks again.
+ {
+ UpdateService old(moving({0, 7, 1}));
+ old.Start();
+ Wait(old);
+ CHECK(old.Snapshot().moved_to == "0.8.0" && old.Snapshot().finished_message.empty());
+ CHECK(!old.Snapshot().finished_failed && Exists(state) && registered.size() == 2);
+ CHECK(Read(fixture.root + "/playden/kits/kitid/manifest.json") == kKitSha); // the new kit stays
+ // It no longer updates or installs kits: the moved release is not offered again.
+ const auto before = Read(state);
+ const int requests = fixture.server.requests;
+ old.Check(true);
+ old.Install();
+ old.CheckKit();
+ Wait(old);
+ CHECK(old.Snapshot().phase == UpdatePhase::kIdle && fixture.server.requests == requests && Read(state) == before);
+ CHECK(!old.ApplyAtQuit() && old.RelaunchTitle() == "FAKE77031");
+ // Asked from its dialog: the new title is registered again at quit and opened instead.
+ old.RequestOpenSuccessor();
+ CHECK(old.RelaunchTitle() == "PPSA97031");
+ old.Shutdown();
+ CHECK(old.ApplyAtQuit() && registered.size() == 3 && Read(state) == before);
+ }
+ // The new title ignores the old title's other states (only the move is addressed to it).
+ {
+ const auto move = Read(state);
+ Put(state, R"({"phase":"staged","owner":"FAKE77031","version":"0.9.0","stage":"/nowhere","title":"FAKE77031"})");
+ auto config = fixture.Config({0, 8, 0});
+ config.title_id = "PPSA97031";
+ config.installed_root = new_app;
+ UpdateService other(config);
+ other.Start();
+ CHECK(other.Snapshot().phase == UpdatePhase::kIdle && Exists(state));
+ Put(state, move);
+ }
+ // The new title starts: the update is confirmed there, with nothing to go back to.
+ {
+ auto config = fixture.Config({0, 8, 0});
+ config.title_id = "PPSA97031";
+ config.installed_root = new_app;
+ config.appmeta_root = fixture.root + "/user/appmeta/PPSA97031";
+ config.registered_app_root = fixture.root + "/user/app/PPSA97031";
+ UpdateService next(config);
+ next.Start();
+ CHECK(next.Snapshot().finished_message == "Playden was updated to 0.8.0." && next.Snapshot().whats_new);
+ CHECK(!Exists(state) && next.Snapshot().previous.empty());
+ Wait(next);
+ }
+ // Later the new title updates itself and its state is "applied" when the old title opens: the old
+ // title leaves it (and the new title's backup) alone, and only points to the new app.
+ {
+ const std::string applied = R"({"phase":"applied","owner":"PPSA97031","version":"0.8.1","from":"0.8.0","backup":")" +
+ fixture.root + R"(/playden/self-update/backup/0.8.0-2000","stage":")" + fixture.root +
+ R"(/playden/self-update/stage/0.8.1","kit_id":"kitid","previous_kit":"","next_kit":""})";
+ Put(state, applied);
+ Put(fixture.root + "/playden/self-update/backup/0.8.0-2000/eboot.bin", "eboot 0.8.0");
+ UpdateService old(moving({0, 7, 1}));
+ old.Start();
+ Wait(old);
+ CHECK(Read(state) == applied && Read(old_app + "/eboot.bin") == "eboot 0.2.0" && Read(new_app + "/eboot.bin") == "eboot 0.8.0");
+ CHECK(old.Snapshot().finished_message == "Open the new Playden from Home." && old.Snapshot().moved_to.empty());
+ CHECK(old.Snapshot().previous.empty() && registered.size() == 3);
+ }
+ RemoveTree(fixture.root);
+ }
+ // From 0.8.0 a release carries two manifests: playden-update.json names a FAKE77031 build (the one 0.7.1-beta.2 and
+ // older read), playden-update-v2.json the PPSA97031 app. Newer builds read v2: a FAKE77031 build moves to the
+ // successor from an older version or from that same version (the bridge), and the successor finds itself up to date.
+ {
+ Fixture fixture;
+ fixture.root = zip_fixture::TempFolder("service-bridge");
+ Installed(fixture.root);
+ const std::string new_app = fixture.root + "/homebrew/PPSA97031";
+ Publish(fixture.server, "v0.8.0", "0.7.0", "00.008.000", true, true, "r9", "", "PPSA97031");
+ const std::string successor_manifest = fixture.server.files[kDownload + "playden-update.json"];
+ const std::string bridge_app = AppZip("0.8.0", "00.008.000", "", "FAKE77031");
+ std::string bridge_manifest = successor_manifest;
+ for (std::size_t at; (at = bridge_manifest.find("PPSA97031")) != std::string::npos;)
+ bridge_manifest.replace(at, 9, "FAKE77031");
+ bridge_manifest.replace(bridge_manifest.find("playden-ps5-0.8.0.zip"), 21, "playden-ps5-0.8.0-FAKE77031.zip");
+ const auto asset = [&](const std::string& name, const std::string& body) {
+ return R"({"name":")" + name + R"(","size":)" + std::to_string(body.size()) + R"(,"digest":"sha256:)" +
+ FakeSha(body) + R"(","browser_download_url":")" + kDownload + name + R"("})";
+ };
+ const auto publish = [&](bool with_v2) {
+ fixture.server.files[kDownload + "playden-update.json"] = bridge_manifest;
+ fixture.server.files[kDownload + "playden-update-v2.json"] = successor_manifest;
+ fixture.server.files[kDownload + "playden-ps5-0.8.0-FAKE77031.zip"] = bridge_app;
+ const auto& files = fixture.server.files;
+ fixture.server.latest =
+ R"({"tag_name":"v0.8.0","draft":false,"prerelease":false,"assets":[)" +
+ asset("playden-update.json", bridge_manifest) + "," +
+ (with_v2 ? asset("playden-update-v2.json", successor_manifest) + "," : std::string()) +
+ asset("playden-ps5-0.8.0.zip", files.at(kDownload + "playden-ps5-0.8.0.zip")) + "," +
+ asset("playden-ps5-0.8.0-FAKE77031.zip", bridge_app) + "," +
+ asset("playden-kit-h-r9.zip", files.at(kDownload + "playden-kit-h-r9.zip")) + "]}";
+ };
+ const auto fake = [&](Version current) {
+ auto config = fixture.Config(current);
+ config.successor_title_id = "PPSA97031";
+ config.successor_root = new_app;
+ config.register_title = [](const std::string&) { return true; };
+ return config;
+ };
+ publish(true);
+ // 0.7.1 moves to 0.8.0 directly.
+ {
+ UpdateService service(fake({0, 7, 1}));
+ service.Check(true); Wait(service);
+ CHECK(service.Snapshot().phase == UpdatePhase::kAvailable && service.Snapshot().moves);
+ CHECK(service.Snapshot().available == (Version{0, 8, 0}));
+ }
+ // The bridge, 0.8.0 as FAKE77031: the same version as the successor is still a move, and it takes place.
+ {
+ UpdateService bridge(fake({0, 8, 0}));
+ bridge.Check(true); Wait(bridge);
+ CHECK(bridge.Snapshot().phase == UpdatePhase::kAvailable && bridge.Snapshot().moves);
+ bridge.Install(); Wait(bridge);
+ CHECK(bridge.Snapshot().phase == UpdatePhase::kStaged);
+ bridge.RequestRestart();
+ CHECK(bridge.RelaunchTitle() == "PPSA97031");
+ bridge.Shutdown();
+ CHECK(bridge.ApplyAtQuit());
+ CHECK(Read(new_app + "/eboot.bin") == "eboot 0.8.0");
+ CHECK(Read(fixture.root + "/homebrew/FAKE77031/eboot.bin") == "eboot 0.2.0");
+ }
+ // The successor reads v2 too: its own version, up to date.
+ {
+ auto config = fixture.Config({0, 8, 0});
+ config.title_id = "PPSA97031";
+ config.installed_root = new_app;
+ UpdateService successor(config);
+ successor.Check(true); Wait(successor);
+ CHECK(successor.Snapshot().phase == UpdatePhase::kUpToDate);
+ }
+ RemoveTree(new_app);
+ RemoveTree(fixture.root + "/playden/self-update");
+ // A release without v2 (0.7.x): a FAKE77031 build at that version is up to date, and an older one updates in place.
+ publish(false);
+ {
+ UpdateService current(fake({0, 8, 0}));
+ current.Check(true); Wait(current);
+ CHECK(current.Snapshot().phase == UpdatePhase::kUpToDate);
+ UpdateService older(fake({0, 7, 1}));
+ older.Check(true); Wait(older);
+ CHECK(older.Snapshot().phase == UpdatePhase::kAvailable && !older.Snapshot().moves);
+ }
+ RemoveTree(fixture.root);
+ }
+ // A staged move that this build can't make (no successor) is dropped.
+ {
+ Fixture fixture;
+ fixture.root = zip_fixture::TempFolder("service-move-unknown");
+ Installed(fixture.root);
+ Publish(fixture.server, "v0.8.0", "0.7.0", "00.008.000", true, true, "r9", "", "PPSA97031");
+ auto config = fixture.Config({0, 7, 1});
+ config.successor_title_id = "PPSA97031";
+ config.successor_root = fixture.root + "/homebrew/PPSA97031";
+ {
+ UpdateService service(config);
+ service.Install(); Wait(service);
+ CHECK(service.Snapshot().phase == UpdatePhase::kStaged);
+ service.Shutdown();
+ }
+ UpdateService plain(fixture.Config({0, 7, 1}));
+ plain.Start();
+ CHECK(plain.Snapshot().phase == UpdatePhase::kIdle);
+ CHECK(!Exists(fixture.root + "/playden/self-update/state.json"));
+ CHECK(!Exists(fixture.root + "/playden/self-update/stage/0.8.0"));
+ RemoveTree(fixture.root);
+ }
// GitHub out of reach.
{
Fixture fixture;
diff --git a/tools/console_title_deploy.py b/tools/console_title_deploy.py
index b069a0d..072b866 100644
--- a/tools/console_title_deploy.py
+++ b/tools/console_title_deploy.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-"""Deploy or restore the Playden FAKE77031 package files over FTP.
+"""Deploy or restore the Playden package files (FAKE77031 unless --title says otherwise) over FTP.
deploy: compares every packaged file with the console, backs up each differing
console file locally (bytes, mode, SHA-256), then replaces it through a staged
@@ -17,6 +17,7 @@ import hashlib
import io
import json
import os
+import re
from pathlib import Path, PurePosixPath
import sys
@@ -105,14 +106,22 @@ def main():
parser.add_argument("--host", default=os.environ.get("PLAYDEN_PS5_HOST"),
help="the PS5's IP address (or set PLAYDEN_PS5_HOST)")
parser.add_argument("--port", type=int, default=2120)
+ parser.add_argument("--title", default="FAKE77031", help="Playden's title ID (default FAKE77031)")
args = parser.parse_args()
if not args.host:
parser.error("give the PS5's address with --host or PLAYDEN_PS5_HOST")
+ if not re.fullmatch(r"(?:FAKE|PPSA)[0-9]{5}", args.title):
+ parser.error("--title must be FAKE or PPSA and five digits")
+ global TITLE
+ TITLE = "/data/homebrew/" + args.title
ftp = ftplib.FTP()
ftp.connect(args.host, args.port, timeout=60)
ftp.login()
if args.command == "restore":
record = json.loads((args.backup / "backup.json").read_text())
+ if record["title"] != TITLE:
+ print(f"refusing: the backup is of {record['title']}, not {TITLE}", file=sys.stderr)
+ return 1
for path, entry in record["files"].items():
remote = f"{TITLE}/{path}"
if entry["sha256"] is None:
diff --git a/tools/self-update-relaunch/main.c b/tools/self-update-relaunch/main.c
index 96e8f12..77ac69d 100644
--- a/tools/self-update-relaunch/main.c
+++ b/tools/self-update-relaunch/main.c
@@ -3,11 +3,18 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// A title cannot start itself after it exits. Just before Playden quits to finish an update it
-// sends this payload to the payload loader on 127.0.0.1:9021. The payload reads the title id
-// from REQUEST ("FAKE77031\n"), waits until that title's sandbox (/mnt/sandbox/<id>_*) is gone,
-// and starts it again with sceLncUtilLaunchApp, falling back to sceSystemServiceLaunchApp. It
-// gives up after 120 s. If the start fails, a notification asks the player to open Playden.
+// sends this payload to the payload loader on 127.0.0.1:9021. The payload reads the title to open
+// from REQUEST's first line ("FAKE77031\n"), and the quitting title from its second line (the same
+// title when there is none), waits until the quitting title's sandbox (/mnt/sandbox/<id>_*) is
+// gone, and starts the title with sceLncUtilLaunchApp, falling back to sceSystemServiceLaunchApp.
+// It gives up after 120 s. If the start fails, a notification asks the player to open Playden.
// Measured in results/20261015-self-update-probes: the sandbox goes about 5 s after the quit.
+//
+// When Playden moves to another title ("PPSA97031\nFAKE77031\n"), ShadowMountPlus registers the
+// new title only once the old one has closed (results/20261025-ppsa97031-probe: about 1 s later),
+// so the payload waits up to 60 s for its /user/app/<id>/mount.lnk. If the new title can't be
+// started, it opens the old one, which tells the player where the update went. Playden rewrites
+// REQUEST when the move fails at quit, so the first line is read again once the old title is gone.
#include <dirent.h>
#include <stdint.h>
#include <stdio.h>
@@ -78,42 +85,82 @@ static void notify(const char* text) {
fprintf(out, "notify rc=0x%08x\n", sceKernelSendNotificationRequest(0, &request, sizeof request, 0));
}
+// 1 once ShadowMountPlus has registered the title (its mount.lnk), 0 when it has not after 60 s.
+static int registered(const char* title) {
+ char link[64];
+ snprintf(link, sizeof link, "/user/app/%s/mount.lnk", title);
+ const double start = now();
+ while (access(link, F_OK) != 0) {
+ if (now() - start > 60) return 0;
+ usleep(250000);
+ }
+ usleep(1000000); // the Home screen entry follows the link by about a second
+ return 1;
+}
+
+static uint32_t launch(const char* title, uint32_t user) {
+ launch_params params = {sizeof params, user, 0, 0, 0, 0};
+ uint32_t rc = sceLncUtilLaunchApp(title, NULL, &params);
+ fprintf(out, "%s sceLncUtilLaunchApp rc=0x%08x\n", title, rc);
+ if (rc & 0x80000000u) {
+ launch_params fallback = {sizeof fallback, user, 0, 0, 0, 1};
+ rc = sceSystemServiceLaunchApp(title, NULL, &fallback);
+ fprintf(out, "%s sceSystemServiceLaunchApp rc=0x%08x\n", title, rc);
+ }
+ return rc;
+}
+
int main(void) {
out = fopen(LOG, "w");
if (!out) return 1;
setvbuf(out, NULL, _IONBF, 0);
- char title[32] = {0};
+ char title[32] = {0}, quitting[32] = {0};
FILE* request = fopen(REQUEST, "r");
if (!request || !fgets(title, sizeof title, request)) {
fprintf(out, "no request\n");
if (request) fclose(request);
return 1;
}
+ if (!fgets(quitting, sizeof quitting, request)) quitting[0] = 0;
fclose(request);
title[strcspn(title, "\r\n")] = 0;
- if (!valid_title(title)) {
+ quitting[strcspn(quitting, "\r\n")] = 0;
+ if (!quitting[0]) strcpy(quitting, title);
+ if (!valid_title(title) || !valid_title(quitting)) {
fprintf(out, "bad title id\n");
return 1;
}
const double start = now();
int state;
- while ((state = running(title)) == 1 && now() - start < 120) usleep(250000);
- fprintf(out, "title=%s wait state=%d s=%.2f\n", title, state, now() - start);
+ while ((state = running(quitting)) == 1 && now() - start < 120) usleep(250000);
+ fprintf(out, "title=%s quitting=%s wait state=%d s=%.2f\n", title, quitting, state, now() - start);
if (state != 0) {
notify("Playden was updated. Open it again from the Home screen.");
return 1;
}
+ char final_title[32] = {0};
+ if ((request = fopen(REQUEST, "r"))) {
+ if (fgets(final_title, sizeof final_title, request)) {
+ final_title[strcspn(final_title, "\r\n")] = 0;
+ if (valid_title(final_title) && strcmp(final_title, title) != 0) {
+ fprintf(out, "title changed to %s\n", final_title);
+ strcpy(title, final_title);
+ }
+ }
+ fclose(request);
+ }
sceUserServiceInitialize(NULL);
uint32_t user = 0;
sceUserServiceGetForegroundUser(&user);
sceLncUtilInitialize();
- launch_params params = {sizeof params, user, 0, 0, 0, 0};
- uint32_t rc = sceLncUtilLaunchApp(title, NULL, &params);
- fprintf(out, "sceLncUtilLaunchApp rc=0x%08x\n", rc);
- if (rc & 0x80000000u) {
- launch_params fallback = {sizeof fallback, user, 0, 0, 0, 1};
- rc = sceSystemServiceLaunchApp(title, NULL, &fallback);
- fprintf(out, "sceSystemServiceLaunchApp rc=0x%08x\n", rc);
+ uint32_t rc = 0x80000000u;
+ if (strcmp(title, quitting) == 0) {
+ rc = launch(title, user);
+ } else {
+ const int ready = registered(title);
+ fprintf(out, "%s registered=%d s=%.2f\n", title, ready, now() - start);
+ if (ready) rc = launch(title, user);
+ if (rc & 0x80000000u) rc = launch(quitting, user);
}
if (rc & 0x80000000u) notify("Playden was updated. Open it again from the Home screen.");
fclose(out);