Skip to content

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

C++

Keep game files when a PS5 title removal fails

Leonardo Lobatoc186e75b5254
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index 4d5ba22..9ca5859 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -1388,7 +1388,10 @@ void Controller::TickUninstalls() {
for (const auto id : ids) {
if (IsNumber(snapshot, snapshot.preparing_app, id)) continue; // its title is removed once the preparation ends
UninstallFacts facts;
- facts.has_title = std::any_of(snapshot.installs.begin(), snapshot.installs.end(),
+ // Unknown records count as a title: the removal reads them again, and the game's files stay
+ // while they can't be read.
+ facts.has_title = !snapshot.installs_known ||
+ std::any_of(snapshot.installs.begin(), snapshot.installs.end(),
[id](const RuntimeInstallView& view) { return view.game == id; });
facts.removing = IsNumber(snapshot, snapshot.removing_app, id);
facts.removal_started = std::any_of(snapshot.installs.begin(), snapshot.installs.end(), [id](const RuntimeInstallView& view) {
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index bd57faf..adc6122 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -1240,7 +1240,11 @@ void RuntimeHost::PublishInstalls(const Composition& composition, const std::str
}
installs.push_back(std::move(view));
}
- Publish([&](RuntimeSnapshot& s) { s.installs = std::move(installs); });
+ const bool known = composition.repository.Loaded();
+ Publish([&](RuntimeSnapshot& s) {
+ s.installs = std::move(installs);
+ s.installs_known = known;
+ });
PublishPrepared(&composition);
}
@@ -3196,6 +3200,17 @@ void RuntimeHost::PublishKeptBottles(Composition& c) {
// scan root, unregister the title through the one-shot remover, keep or delete the
// bottle, then drop the record once the console no longer lists the title.
std::string RuntimeHost::RunRemove(Composition& c, std::uint32_t app, bool delete_saves, bool moving) {
+ // After a failed write the records are unknown until read again, and an empty list would read
+ // as "no PS5 title": the game's files would then be deleted under a title that still exists.
+ if (!c.repository.Loaded()) {
+ const auto loaded = c.repository.Load();
+ PublishInstalls(c);
+ if (!loaded.ok()) {
+ Log("remove records unavailable: " + loaded.message());
+ return "Playden's records of PS5 titles cannot be read: " + loaded.message() + ".";
+ }
+ Log("remove records read again installs=" + std::to_string(c.repository.Snapshot().size()));
+ }
std::optional<rt::RuntimeInstall> found;
for (const auto& record : c.repository.Snapshot())
if (record.runtime_number == app) found = record;
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index 1854d82..cce05e1 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -268,6 +268,9 @@ struct RuntimeSnapshot {
std::string kit_reason; // why preparation is unavailable
std::optional<RuntimeKit> kit; // the admitted kit, for display
std::vector<RuntimeInstallView> installs;
+ // False while the PS5 title records could not be read (after a failed write): `installs` is then
+ // empty, which does not mean that no game has a PS5 title.
+ bool installs_known = true;
// Below, games are named by runtime number (RuntimeHost::RuntimeNumberFor): a Steam game's app ID.
// The games of the other numbers, for the fields that carry no GameId.
std::map<std::uint32_t, GameId> runtime_games;
diff --git a/src/homebrew/uninstall_flow.cpp b/src/homebrew/uninstall_flow.cpp
index db05eb1..9f50ff7 100644
--- a/src/homebrew/uninstall_flow.cpp
+++ b/src/homebrew/uninstall_flow.cpp
@@ -89,7 +89,9 @@ UninstallAction UninstallFlow::Advance(GameId id, const UninstallFacts& facts) {
} else {
if (facts.removing || facts.removals_handled <= entry.removals_before) return {};
// A refusal before the removal began changed nothing: there is no removal for Retry to continue.
- if (facts.has_title)
+ // A failure stops the uninstall even when the runtime lists no title: its install list can be
+ // empty because it could not be read, while the PS5 title still points at the game's files.
+ if (facts.has_title || !facts.removal_failure.empty())
return Stop(id, "The PS5 title could not be removed: " +
(facts.removal_failure.empty() ? std::string("unknown reason.") : facts.removal_failure) +
(facts.removal_started ? " The game stays installed; Retry on its PS5 title continues."
diff --git a/src/runtime/game_install.h b/src/runtime/game_install.h
index 429f350..b379a99 100644
--- a/src/runtime/game_install.h
+++ b/src/runtime/game_install.h
@@ -213,6 +213,8 @@ class RuntimeInstallRepository {
RepositoryResult<void> Load();
RepositoryResult<void> Save();
+ // False before Load, and after a write whose outcome is unknown until the registry is read again.
+ bool Loaded() const { return loaded_; }
std::vector<RuntimeInstall> Snapshot() const;
std::optional<RuntimeInstall> Find(const std::string& install_id) const;
RepositoryResult<RuntimeInstall> Reserve(const ReserveRequest& request);
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index 6e1a184..de53213 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -2563,6 +2563,27 @@ void RemovesTitleKeepingSaves() {
host.DeleteKeptBottle(220);
WaitFor(host, [](const RuntimeSnapshot& s) { return s.kept_bottles.empty(); });
CHECK(!fs::exists(kept));
+
+ // A removal whose record cannot be written (a full drive) changes nothing, and the next
+ // one reads the records again instead of taking the empty list for "no PS5 title".
+ prepare(host);
+ CHECK(fixture.registered);
+ const auto records = config.state_root / "installs.json";
+ fs::rename(records, config.state_root / "installs.aside");
+ fs::create_directory(records); // the record can be neither replaced nor read
+ removed = remove(host, false);
+ CHECK(removed.removal_failures.at(220).find("could not be recorded") != std::string::npos);
+ CHECK(fixture.registered && fs::is_directory(bottle));
+ // The empty list is published as unknown, so an uninstall still asks for the removal.
+ CHECK(removed.installs.empty() && !removed.installs_known);
+ removed = remove(host, false);
+ CHECK(removed.removal_failures.at(220).find("cannot be read") != std::string::npos);
+ CHECK(fixture.registered && fs::is_directory(bottle));
+ fs::remove(records);
+ fs::rename(config.state_root / "installs.aside", records);
+ removed = remove(host, false);
+ CHECK(!removed.removal_failures.count(220) && removed.installs.empty() && removed.installs_known);
+ CHECK(!fixture.registered && !fs::exists(bottle) && fs::is_directory(kept));
host.Shutdown();
}
}
diff --git a/tests/homebrew_uninstall_flow_test.cpp b/tests/homebrew_uninstall_flow_test.cpp
index 0498160..56bd8eb 100644
--- a/tests/homebrew_uninstall_flow_test.cpp
+++ b/tests/homebrew_uninstall_flow_test.cpp
@@ -71,6 +71,19 @@ int main() {
action = flow.Advance(SteamId(47), titled);
CHECK(action.kind == Kind::kStop && action.reason.find("Retry on its PS5 title continues") != std::string::npos);
+ // A failed removal keeps the download even when the runtime lists no title: its install list
+ // is empty when its registry could not be written, while the PS5 title is still there.
+ CHECK(flow.Begin(SteamId(49), false, false));
+ titled = {};
+ titled.has_title = true;
+ CHECK(flow.Advance(SteamId(49), titled).kind == Kind::kRemoveTitle);
+ UninstallFacts unlisted;
+ unlisted.removals_handled = 1;
+ unlisted.removal_failure = "The removal could not be recorded: runtime install registry could not be written";
+ action = flow.Advance(SteamId(49), unlisted);
+ CHECK(action.kind == Kind::kStop && action.reason.find("could not be recorded") != std::string::npos);
+ CHECK(!flow.Step(SteamId(49)));
+
// A game without a PS5 title goes straight to the download.
CHECK(flow.Begin(SteamId(44), false, false));
CHECK(flow.Advance(SteamId(44), UninstallFacts{}).kind == Kind::kRemoveDownload);