Play your Steam library's Windows games on a jailbroken PS5.
C++
Add Update runtime to Maintenance
Leonardo Lobato8bf1a49aa40c
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex 02ee03b..b702efb 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -834,15 +834,27 @@ void Controller::TickRuntime() {WithApp(id, [this, path = root->second](std::uint32_t app) { runtime_->ScanPrograms(app, path); });for (const auto& [id, kind] : model_.TakeMaintenanceRequests())WithApp(id, [this, id = id, kind = kind](std::uint32_t app) {+ if (kind == MaintenanceKind::UpdateRuntime) {+ if (runtime_updates_.count(id) || recreate_.count(id)) return;+ runtime_updates_[id] = {runtime_->Shared()->prepares_handled, false, std::chrono::steady_clock::now()};+ runtime_update_results_.erase(id);+ recreate_results_.erase(id);+ ++play_notes_revision_;+ // As Play does for such a title: a drop-folder game's files are opened first.+ if (!HoldForDropFolder(id, DropFolderNext::kPrepare)) RequestPrepare(id);+ return;+ }if (kind == MaintenanceKind::RecreateBottle) {if (recreate_.count(id)) return;recreate_[id] = {runtime_->Shared()->removals_handled, false, false, {}, {}};recreate_results_.erase(id);+ runtime_update_results_.erase(id);runtime_->Remove(app, false);++play_notes_revision_;return;}recreate_results_.erase(id); // the sheet shows the newest request+ runtime_update_results_.erase(id);++play_notes_revision_;runtime_->Maintain(app, kind == MaintenanceKind::ClearShaderCache ? RuntimeMaintenance::kClearShaderCache: kind == MaintenanceKind::Repair ? RuntimeMaintenance::kRepair@@ -1011,6 +1023,24 @@ void Controller::TickRuntime() {finish(false, refusal_of(id).empty() ? "The game could not be prepared again; press Prepare on the game page.": refusal_of(id));}+ // Update runtime: done when its preparation ends, with the title on the kit's runtime or with the refusal.+ for (auto it = runtime_updates_.begin(); it != runtime_updates_.end();) {+ const auto id = it->first;+ auto& pending = it->second;+ if (drop_folder_opens_.count(id)) { ++it; continue; } // its files are still being opened+ if (IsNumber(prepared, prepared.preparing_app, id)) { pending.seen_preparing = true; ++it; continue; }+ const bool queued = PrepareQueued(prepared, NumberIn(prepared, id)) || prepare_after_details_.count(id);+ const bool handled = !queued && prepared.prepares_handled > pending.prepares_handled;+ const bool unseen_too_long = !pending.seen_preparing && !queued && !prepared.preparing_app &&+ std::chrono::steady_clock::now() - pending.submitted_at > std::chrono::seconds(15);+ if (!pending.seen_preparing && !handled && !unseen_too_long) { ++it; continue; }+ const auto* record = record_of(id);+ const auto refusal = refusal_of(id);+ runtime_update_results_[id] = ready(record) ? std::pair<bool, std::string>{true, "Runtime updated."}+ : std::pair<bool, std::string>{false, refusal.empty() ? "The runtime could not be updated." : refusal};+ ++play_notes_revision_;+ it = runtime_updates_.erase(it);+ }for (auto it = play_after_prepare_.begin(); it != play_after_prepare_.end();) {const auto id = it->first;auto& pending = it->second;@@ -1317,6 +1347,17 @@ void Controller::TickRuntime() {game.maintenance_ok = result->second.first;game.maintenance_message = result->second.second;}+ if (runtime_updates_.count(id)) {+ game.maintenance = MaintenanceKind::UpdateRuntime;+ game.maintenance_running = true;+ game.maintenance_message.clear();+ } else if (const auto result = runtime_update_results_.find(id); result != runtime_update_results_.end() &&+ (!game.maintenance || !game.maintenance_running)) {+ game.maintenance = MaintenanceKind::UpdateRuntime;+ game.maintenance_running = false;+ game.maintenance_ok = result->second.first;+ game.maintenance_message = result->second.second;+ }games.push_back(std::move(game));}model_.SetGeneratedRecipes(snapshot.generated_recipes);@@ -1373,6 +1414,7 @@ void Controller::BeginUninstall(GameId id, bool delete_saves) {prepare_after_import_.erase(id);prepare_after_details_.erase(id);play_after_prepare_.erase(id);+ runtime_updates_.erase(id);if (prepare_next_pending_ == id) prepare_next_pending_.reset();// With automatic sync off, nothing moves to or from Steam Cloud unless the player syncs from Saves.if (uninstalls_.Begin(id, delete_saves, CloudCapable(id) && game_roots_.count(id) && !saves_root_.empty() &&@@ -1620,6 +1662,10 @@ void Controller::ReleaseDropFolderOpens(std::vector<GameId>& plays, std::vector<recreate_.erase(id);++play_notes_revision_;}+ if (open.prepare && runtime_updates_.erase(id)) {+ runtime_update_results_[id] = {false, message};+ ++play_notes_revision_;+ }} else if (open.play) {plays.push_back(id); // Play prepares a game that needs it on its ownif (open.recreate) submits.emplace_back(id, true);diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hppindex 69a9eb0..bac4cc5 100644--- a/src/homebrew/controller.hpp+++ b/src/homebrew/controller.hpp@@ -247,6 +247,15 @@ class Controller {};std::map<GameId, Recreate> recreate_;std::map<GameId, std::pair<bool, std::string>> recreate_results_;+ // Maintenance › Update runtime: the preparation Play runs first for a title on an older kit's runtime (RunPrepare's+ // update, with its settings republish), without starting the game. Results stay for the maintenance sheet.+ struct RuntimeUpdate {+ std::uint64_t prepares_handled = 0; // the worker's count when it was asked for+ bool seen_preparing = false;+ std::chrono::steady_clock::time_point submitted_at{};+ };+ std::map<GameId, RuntimeUpdate> runtime_updates_;+ std::map<GameId, std::pair<bool, std::string>> runtime_update_results_;// The verified kit's capabilities, which gate Game settings rows.std::optional<std::vector<std::string>> kit_capabilities_;// Titles waiting for the PS5 when Playden started are checked once (query only).diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex bbc9081..a7dee30 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -3964,6 +3964,7 @@ void Simulation::rebuild_view() {: action_key == "maintenance-shader" ? MaintenanceKind::ClearShaderCache: action_key == "maintenance-backup" ? MaintenanceKind::BackupSaves: action_key == "maintenance-recreate" ? MaintenanceKind::RecreateBottle+ : action_key == "maintenance-update" ? MaintenanceKind::UpdateRuntime: MaintenanceKind::ApplySettings;std::string closed_reason;const bool closed = game_closed(settings_game, &closed_reason);@@ -3976,6 +3977,19 @@ void Simulation::rebuild_view() {item.subtitle = settings_record != state_.game_settings.end() && !settings_record->second.overrides.empty()? "Nothing else to reset. The program you chose stays; change it in the Program row.": "Nothing to reset: the settings follow the preset.";+ } else if (kind == MaintenanceKind::UpdateRuntime) {+ // What Play does first for a title on an older kit's runtime ("Kit update available"), alone.+ const bool stale = runtime && (runtime->status == "Kit update available" || runtime->status == "Update available");+ item.title = "Update runtime";+ item.subtitle = "Moves the game to the installed kit's runtime without starting it.";+ item.badge = "Game must be closed";+ item.enabled = stale && runtime->can_prepare && closed && !busy;+ // While it runs the title is being prepared, no longer "Kit update available".+ const bool updating = busy && runtime->maintenance == MaintenanceKind::UpdateRuntime;+ if (!stale && !updating)+ item.subtitle = runtime && runtime->status == "No kit" ? "Needs a usable compatibility kit." : "Already up to date.";+ else if (!updating && !closed) item.subtitle = closed_reason;+ else if (!updating && !runtime->can_prepare && !busy) item.subtitle = "Wait for the game's setup to finish.";} else {item.title = kind == MaintenanceKind::Repair ? "Repair": kind == MaintenanceKind::ClearShaderCache ? "Clear shader cache"@@ -6863,6 +6877,7 @@ void Simulation::activate() {: chosen == "maintenance-shader" ? MaintenanceKind::ClearShaderCache: chosen == "maintenance-backup" ? MaintenanceKind::BackupSaves: chosen == "maintenance-recreate" ? MaintenanceKind::RecreateBottle+ : chosen == "maintenance-update" ? MaintenanceKind::UpdateRuntime: MaintenanceKind::ApplySettings;if (chosen == "maintenance-reset") {auto& record = state_.game_settings[state_.navigation.selected_game_id];@@ -7008,6 +7023,10 @@ void Simulation::activate() {if (action_name == "maintenance-reset") {heading = "Reset settings?";body = "Your changes to " + title + "'s settings are removed. The chosen preset and program stay; saves are not touched.";+ } else if (action_name == "maintenance-update") {+ heading = "Update the runtime?";+ body = title + " moves to the runtime of the installed compatibility kit, and settings that need it apply. "+ "The game doesn't start; saves are not touched.";} else if (action_name == "maintenance-repair") {heading = "Repair the game?";body = "Playden checks the files " + title + " needs to start, fixes their permissions and writes its settings again. Saves are not touched.";@@ -8202,7 +8221,8 @@ std::vector<std::string> Simulation::details_context_actions() const {}std::vector<std::string> Simulation::maintenance_actions() const {- return {"maintenance-reset", "maintenance-repair", "maintenance-shader", "maintenance-backup", "maintenance-recreate", "cancel"};+ return {"maintenance-reset", "maintenance-update", "maintenance-repair", "maintenance-shader", "maintenance-backup",+ "maintenance-recreate", "cancel"};}bool Simulation::game_prepared(GameId id) const {@@ -8239,7 +8259,8 @@ void Simulation::request_maintenance(GameId id, MaintenanceKind kind) {const char* words = kind == MaintenanceKind::ClearShaderCache ? "Shader cache cleared": kind == MaintenanceKind::Repair ? "Repaired": kind == MaintenanceKind::BackupSaves ? "Saves backed up"- : kind == MaintenanceKind::RecreateBottle ? "Bottle recreated" : "Settings applied";+ : kind == MaintenanceKind::RecreateBottle ? "Bottle recreated"+ : kind == MaintenanceKind::UpdateRuntime ? "Runtime updated" : "Settings applied";push_notice({"maintenance-" + ToKey(id), words, "", false, kLiveNoticeSeconds, false, "Simulated"});return;}diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex d5a551c..25fdc6e 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -49,7 +49,7 @@ struct InstallRequest {bool delete_saves = false; // Uninstall only: also delete the game's kept saves and settings};// Game maintenance the details page offers (simulated in fixture mode).-enum class MaintenanceKind { ApplySettings, ClearShaderCache, Repair, BackupSaves, RecreateBottle };+enum class MaintenanceKind { ApplySettings, ClearShaderCache, Repair, BackupSaves, RecreateBottle, UpdateRuntime };// Whether a game's PS5 title runs now, as the console last answered.enum class TitleActivity { Unknown, Stopped, Running };// Live install state projected from the real install service.diff --git a/tests/homebrew_installed_locations_test.cpp b/tests/homebrew_installed_locations_test.cppindex f1b898f..5b9a424 100644--- a/tests/homebrew_installed_locations_test.cpp+++ b/tests/homebrew_installed_locations_test.cpp@@ -490,7 +490,8 @@ void ImportedGamePlaysInPlace() {config.package_operations.validate_bottle = [](const fs::path& bottle) {return fs::is_regular_file(bottle / "system.reg") && fs::is_regular_file(bottle / "user.reg");};- const auto kit = SyntheticKit(fixture.root / "kit");+ // Replaced by a newer kit for Update runtime, at the end.+ auto kit = SyntheticKit(fixture.root / "kit");config.admit_kit = [&kit](std::string*) { return std::optional<RuntimeKit>(kit); };unsigned uuids = 0;config.uuid = [&uuids]() -> std::optional<std::string> {@@ -599,7 +600,7 @@ void ImportedGamePlaysInPlace() {};tick_until([&] {return host.Snapshot().status == RuntimeHostStatus::kReady && model.state().runtime == hb::RuntimeState::Ready &&- !model.state().import_scanning && model.state().import_candidates.size() == 2;+ !model.state().import_scanning && model.state().import_candidates.size() >= 2; // Sky joins later});body(model, controller, host, *local_library, tick_until);controller.Shutdown();@@ -881,6 +882,90 @@ void ImportedGamePlaysInPlace() {for (int i = 0; i < 50; ++i) { controller.Tick(); std::this_thread::sleep_for(std::chrono::milliseconds(2)); }CHECK(launched.size() == plays_before);});++ // A newer kit with 120 Hz output: Sky's title keeps the older runtime until it is updated. 120 Hz output and Frame+ // limit 120 chosen now wait for that; Maintenance › Update runtime moves the title to the kit's runtime without+ // starting the game, and publishes them.+ kit = SyntheticKit(fixture.root / "kit-display", "native-2", "kit-1", 'c');+ kit.capabilities.push_back("display-120hz");+ std::sort(kit.capabilities.begin(), kit.capabilities.end());+ run(false, [&](hb::Simulation& model, hb::Controller& controller, RuntimeHost& host, local::LocalLibrarySource& source,+ const std::function<void(const std::function<bool()>&)>& tick_until) {+ std::string sky_id;+ for (const auto& imported : source.Snapshot()->games)+ if (imported.volume == "internal") sky_id = imported.id;+ CHECK(!sky_id.empty());+ const auto game = GameId::Local(sky_id);+ const auto runtime_of = [&]() -> const hb::LiveRuntimeGame* {+ const auto found = model.state().runtime_games.find(game);+ return found == model.state().runtime_games.end() ? nullptr : &found->second;+ };+ tick_until([&] {+ const auto* runtime = runtime_of();+ const auto snapshot = host.Snapshot();+ return game_of(model, game) && runtime && runtime->status == "Kit update available" && !runtime->runtime_current &&+ (!snapshot.launch || (snapshot.launch->state != LaunchState::kLaunching &&+ snapshot.launch->state != LaunchState::kRunning));+ });+ fs::path profile;+ for (const auto& entry : fs::recursive_directory_iterator(fixture.root / "data/playden/games"))+ if (entry.path().extension() == ".profile" && entry.path().string().find(sky_id) != std::string::npos) profile = entry.path();+ CHECK(!profile.empty());+ const auto plays_before = launched.size();+ open_details(model, game);+ CHECK(model.action("focus:details-more") && model.action("cross"));+ CHECK(model.action("focus:game-settings") && model.action("cross"));+ CHECK(model.action("focus:section-more") && model.action("cross"));+ // Sky's recipe leaves Graphics automatic; 120 Hz output is for DXVK and OpenGL.+ tick_until([&] { const auto* row = row_of(model, "setting-graphics"); return row && row->enabled; });+ CHECK(model.action("focus:setting-graphics") && model.action("cross"));+ CHECK(model.action("focus:choice-2") && model.action("cross"));+ tick_until([&] { const auto* row = row_of(model, "setting-refresh"); return row && row->enabled; });+ CHECK(row_of(model, "setting-refresh")->subtitle.rfind(kAppliesAfterKitUpdate, 0) == 0);+ CHECK(model.action("focus:setting-refresh") && model.action("cross"));+ CHECK(model.action("focus:choice-1") && model.action("cross"));+ CHECK(model.action("focus:setting-frame_limit") && model.action("cross"));+ CHECK(model.action("focus:choice-1") && model.action("cross"));+ CHECK(model.state().game_settings.at(game).overrides.at("refresh") == "120" &&+ model.state().game_settings.at(game).overrides.at("frame_limit") == "120");+ CHECK(model.action("circle")); // closing the sheet applies the settings+ tick_until([&] {+ const auto* runtime = runtime_of();+ return runtime && runtime->maintenance == hb::MaintenanceKind::ApplySettings && !runtime->maintenance_running &&+ runtime->settings_revision == model.state().game_settings.at(game).revision;+ });+ CHECK(Read(profile).find("frame_rate") == std::string::npos && Read(profile).find("refresh = 120") == std::string::npos);++ // Not while the game runs.+ fixture.activity->store(static_cast<int>(NativeActivity::kActive));+ CHECK(model.action("focus:game-maintenance") && model.action("cross"));+ tick_until([&] {+ const auto* row = row_of(model, "maintenance-update");+ return row && !row->enabled && row->subtitle == "Quit Sky to change this.";+ });+ CHECK(model.action("circle"));+ fixture.activity->store(static_cast<int>(NativeActivity::kStopped));+ CHECK(model.action("focus:game-maintenance") && model.action("cross"));+ tick_until([&] { const auto* row = row_of(model, "maintenance-update"); return row && row->enabled; });+ CHECK(model.action("focus:maintenance-update") && model.action("cross"));+ CHECK(model.action("focus:confirm-destructive") && model.action("cross"));+ tick_until([&] {+ const auto* runtime = runtime_of();+ return runtime && runtime->maintenance == hb::MaintenanceKind::UpdateRuntime && !runtime->maintenance_running;+ });+ {+ const auto& updated = *runtime_of();+ if (!updated.maintenance_ok) std::fprintf(stderr, "Update runtime: %s\n", updated.maintenance_message.c_str());+ CHECK(updated.maintenance_ok && updated.maintenance_message == "Runtime updated.");+ CHECK(updated.runtime_current && updated.status != "Kit update available");+ }+ CHECK(Read(profile).find("\nrefresh = 120\nframe_rate = 120\n") != std::string::npos);+ const auto* update = row_of(model, "maintenance-update");+ CHECK(update && !update->enabled && update->subtitle == "Runtime updated.");+ // The game does not start.+ for (int i = 0; i < 50; ++i) { controller.Tick(); std::this_thread::sleep_for(std::chrono::milliseconds(2)); }+ CHECK(launched.size() == plays_before);+ });}int main(int argc, char** argv) {diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cppindex 54b3f83..bc59a07 100644--- a/tests/homebrew_live_model_test.cpp+++ b/tests/homebrew_live_model_test.cpp@@ -310,6 +310,94 @@ void live_120hz_waits_for_the_title_update(const std::filesystem::path& base) {"after Reset the rows show the preset's values");}+// Maintenance › Update runtime runs the update Play does first for a title on an older kit's runtime, without+// starting the game: only while the title waits for it and the game is closed.+void live_update_runtime_from_maintenance(const std::filesystem::path& base) {+ using playden::homebrew::MaintenanceKind;+ using playden::homebrew::TitleActivity;+ using Requests = std::vector<std::pair<playden::homebrew::GameId, MaintenanceKind>>;+ std::filesystem::create_directories(base);+ auto model = make_live(base);+ model.SetGameSettingsFile(base / "update-settings.json");+ model.SetSettingsData({{"playden-default", "Playden default", "Most games", "", {}}}, {});+ model.SetKitCapabilities(playden::runtime::KitCapabilitiesFromManifest({"dxvk", "display-120hz"}, true));+ model.UpdateAccount({AuthState::SignedIn, "account", "Owner", {}, {}, false});+ playden::GameSummary game;+ game.id = SteamId(220);+ game.title = "Half-Life 2";+ check(model.UpdateLibrary({{game}, false, {}, false, true, 100}), "update game library delivered");+ model.UpdateInstalls({}, {{SteamId(220), 1024, "internal", true}});+ playden::homebrew::LiveRuntimeGame runtime;+ runtime.game_id = SteamId(220);+ runtime.status = "Kit update available";+ runtime.prepared = runtime.has_title = runtime.can_prepare = true;+ runtime.runtime_current = false;+ runtime.launch_entry_id = "game";+ runtime.activity = TitleActivity::Stopped;+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});+ check(model.action("details:220"), "open the stale game's details");+ activate(model, "details-more");+ activate(model, "game-maintenance");+ check(!find_row(model, "maintenance-update")->enabled, "Update runtime waits for the console's answer");+ model.TakeActivityRequests();+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});+ const auto* update = find_row(model, "maintenance-update");+ check(update && update->enabled && update->title == "Update runtime" &&+ update->subtitle == "Moves the game to the installed kit's runtime without starting it." &&+ update->badge == "Game must be closed",+ "Update runtime is offered for a closed game whose title waits for its kit update");++ // Not while the game runs.+ runtime.activity = TitleActivity::Running;+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});+ update = find_row(model, "maintenance-update");+ check(update && !update->enabled && update->subtitle == "Quit Half-Life 2 to change this.", "Update runtime waits while the game runs");+ (void)model.action("focus:maintenance-update");+ (void)model.action("cross");+ check(model.TakeMaintenanceRequests().empty(), "a running game's title is not updated");+ // Nor while its setup is queued or running.+ runtime.activity = TitleActivity::Stopped;+ runtime.can_prepare = false;+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});+ update = find_row(model, "maintenance-update");+ check(update && !update->enabled && update->subtitle == "Wait for the game's setup to finish.", "Update runtime waits for setup");+ runtime.can_prepare = true;+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});++ activate(model, "maintenance-update");+ check(model.state().navigation.modals.back().title == "Update the runtime?", "Update runtime asks first");+ activate(model, "confirm-destructive");+ check(model.TakeMaintenanceRequests() == Requests{{SteamId(220), MaintenanceKind::UpdateRuntime}},+ "a confirmed Update runtime goes to the runtime");+ check(model.TakeRuntimePlayRequests().empty(), "Update runtime does not start the game");+ check(find_row(model, "maintenance-update")->value == "Working…" && !find_row(model, "maintenance-repair")->enabled,+ "the update shows its progress and holds the other actions");+ runtime.maintenance = MaintenanceKind::UpdateRuntime;+ runtime.maintenance_running = true;+ runtime.status = "Preparing";+ runtime.can_prepare = false;+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});+ update = find_row(model, "maintenance-update");+ check(update && !update->enabled && update->value == "Working…" &&+ update->subtitle == "Moves the game to the installed kit's runtime without starting it.",+ "the running update keeps saying what it does");+ runtime.can_prepare = true;+ runtime.maintenance_running = false;+ runtime.maintenance_ok = true;+ runtime.maintenance_message = "Runtime updated.";+ runtime.status = "Ready";+ runtime.ready = true;+ runtime.runtime_current = true;+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});+ check(has_notice(model, "maintenance-220"), "the finished update reports its outcome");+ update = find_row(model, "maintenance-update");+ check(update && !update->enabled && update->subtitle == "Runtime updated.", "the row shows the outcome");+ runtime.maintenance.reset();+ model.UpdateRuntime(playden::homebrew::RuntimeState::Ready, {runtime});+ update = find_row(model, "maintenance-update");+ check(update && !update->enabled && update->subtitle == "Already up to date.", "a current title has nothing to update");+}+// A prepared game's settings and maintenance: rows that need the game closed wait for the// console's answer, a closed sheet asks for the settings to be applied, and maintenance// requests go to the runtime after a confirmation.@@ -969,6 +1057,7 @@ int main() {settings_survive_account_restore_and_cache_action_is_honest(base);live_settings_follow_the_prepared_title(base);live_120hz_waits_for_the_title_update(base / "display");+ live_update_runtime_from_maintenance(base / "update-runtime");live_program_change_applies_like_other_settings(base);live_imported_game_steam_app_id(base);live_imported_program_seeds_once(base);