Play your Steam library's Windows games on a jailbroken PS5.
C++
Prepare imported games once they're in the library
Leonardo Lobato0b7f17ae49d8
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex 41e822d..ef30d77 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -808,7 +808,6 @@ void Controller::TickRuntime() {pending->second.submitted_at = std::chrono::steady_clock::now();SubmitPrepare(id, announce);}- // A game Playden still holds back moves to the front once it is asked for.// The latest choice wins: a game Playden still holds back moves first once it is asked for.for (const auto id : model_.TakePrepareNextRequests()) {bool busy = false;@@ -922,7 +921,7 @@ void Controller::TickRuntime() {}if (cloud_busy_.count(*it)) { ++it; continue; } // a move waits for saves in transitplay_after_prepare_.erase(*it);- RequestPrepare(*it);+ if (!HoldForDropFolder(*it, DropFolderNext::kPrepare)) RequestPrepare(*it); // a drop-folder game's files open firstit = auto_prepare_.erase(it);}// A title still waiting for the PS5 when Playden started is checked once: the@@ -1359,6 +1358,7 @@ void Controller::BeginUninstall(GameId id, bool delete_saves) {if (const auto app = RuntimeApp(*runtime_, id, &busy)) runtime_->WithdrawPrepare(*app);}std::erase(auto_prepare_, id);+ prepare_after_import_.erase(id);prepare_after_details_.erase(id);play_after_prepare_.erase(id);if (prepare_next_pending_ == id) prepare_next_pending_.reset();@@ -1484,7 +1484,10 @@ void Controller::TickImports() {for (const auto& id : std::exchange(held_import_removals_, {})) {// A game with a folder to play from goes like an uninstall: its PS5 title first.if (LocationOf(id)) BeginUninstall(id, false);- else track(local_->Remove(id.value), {ImportRequestKind::Remove, id});+ else {+ prepare_after_import_.erase(id);+ track(local_->Remove(id.value), {ImportRequestKind::Remove, id});+ }}// A drive plugged in or out: its games become (un)available and its folders are looked at.const auto now = std::chrono::steady_clock::now();@@ -1498,12 +1501,27 @@ void Controller::TickImports() {const auto outcome = std::find_if(snapshot->outcomes.begin(), snapshot->outcomes.end(),[&](const stores::local::ImportOutcome& o) { return o.request == it->first; });if (outcome == snapshot->outcomes.end()) { ++it; continue; }- if (!outcome->ok) model_.NotifyImportFailed(it->second, outcome->message);- // A game just added: the program chosen with it goes into its Game settings.- else if (it->second.kind == ImportRequestKind::Add && !outcome->id.empty())+ if (!outcome->ok) {+ model_.NotifyImportFailed(it->second, outcome->message);+ } else if (it->second.kind == ImportRequestKind::Add && !outcome->id.empty()) {+ // A game just added: the program chosen with it goes into its Game settings.model_.SeedGameProgram(GameId::Local(outcome->id), it->second.program);+ if (it->second.prepare) prepare_after_import_[GameId::Local(outcome->id)] = false;+ } else if (it->second.kind == ImportRequestKind::MoveIntoPlayden) {+ prepare_after_import_[it->second.game_id] = true;+ }it = import_requests_.erase(it);}+ // Their folder listed, they join the preparation queue as a finished download does (which skips a+ // game already prepared there). One listed that can't play (its drive gone, a name the PS5 can't+ // open) is left for the player.+ for (auto it = prepare_after_import_.begin(); it != prepare_after_import_.end();) {+ const auto* location = LocationOf(it->first);+ if (!location || location->managed() != it->second) { ++it; continue; }+ if (game_roots_.count(it->first) && std::find(auto_prepare_.begin(), auto_prepare_.end(), it->first) == auto_prepare_.end())+ auto_prepare_.push_back(it->first);+ it = prepare_after_import_.erase(it);+ }// Once imports.json is read: copies that finished or stopped while Playden was closed are settled.// A move a restart interrupted is finished then too, once the runtime has started (its PS5 title// follows the folder).diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hppindex 80bcb11..e165712 100644--- a/src/homebrew/controller.hpp+++ b/src/homebrew/controller.hpp@@ -144,6 +144,9 @@ class Controller {// Copies and moves into Playden whose game's first runtime number waits for the runtime worker// (starting up, or in a batch): asked again on the next tick, in order.std::vector<ImportRequest> held_import_transfers_;+ // Games added to play in place, or moved into Playden, that join the preparation queue once their+ // folder is listed: true for a move, which waits for Playden's own folder.+ std::map<GameId, bool> prepare_after_import_;// Runtime calls whose game's first number waited for the runtime worker: made again on the next// tick, in order. The main thread never waits for that worker.std::vector<std::function<void()>> deferred_runtime_;@@ -209,7 +212,7 @@ class Controller {// prepared yet. Play then starts it once it is Ready; the refusal seen when Prepare// was queued tells a new refusal from an old one.std::set<GameId> downloading_;- std::vector<GameId> auto_prepare_; // in the order their downloads finished+ std::vector<GameId> auto_prepare_; // in the order their downloads (copies, imports) finishedstd::optional<GameId> prepare_next_pending_; // Prepare next on a game not in the runtime's queue yetstruct PlayAfterPrepare {bool queued = false;diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex 7b0fcf7..3c2d73b 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -1097,7 +1097,10 @@ void Simulation::choose_import_volume(const std::string& volume_id) {void Simulation::add_import_candidate(const std::string& key, std::optional<ImportRequestKind> then, const std::string& volume_id) {const auto* candidate = import_candidate(key);if (!candidate) return;- RequestImport({ImportRequestKind::Add, {}, candidate->volume_id, candidate->folder, candidate->programs[import_program_index_].path});+ // Played in place, it is prepared once added; a copy or move chosen with it prepares it once it is+ // in Playden instead.+ RequestImport({ImportRequestKind::Add, {}, candidate->volume_id, candidate->folder, candidate->programs[import_program_index_].path,+ !then});pending_imports_[key] = {then, volume_id, state_.navigation.route};import_failures_.erase(key);if (!live()) {diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex 8070e9e..eab3b16 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -226,6 +226,7 @@ struct LiveImportCandidate {bool operator==(const LiveImportCandidate&) const = default;};// Requests for the Local store: look for games, add a candidate (in place), remove an imported game.+// A game moved into Playden is prepared once it is there, as a finished copy is.// CopyIntoPlayden: copy an imported game playing in place into Playden's own storage (volume_id:// an install volume, empty for the default one). MoveIntoPlayden: rename a drop-folder game into// Playden's games folder on the console storage (instant; its PS5 title, if any, follows).@@ -236,6 +237,7 @@ struct ImportRequest {std::string volume_id; // Add, CopyIntoPlaydenstd::string folder; // Add: relative to the volume's mountstd::string program; // Add: relative to the folder+ bool prepare = false; // Add: prepare the game once it is in the library (it plays in place)};// Live Steam Cloud save state for one game, projected from the cloud service.// Waiting: transfers that need no choice wait for the player (an uninstalled game's saves, ordiff --git a/tests/homebrew_installed_locations_test.cpp b/tests/homebrew_installed_locations_test.cppindex ca56e14..4f28e02 100644--- a/tests/homebrew_installed_locations_test.cpp+++ b/tests/homebrew_installed_locations_test.cpp@@ -770,7 +770,10 @@ void ImportedGamePlaysInPlace() {Write(sky / "Game.exe", pe + std::string(4096, 'x'), 0755);Write(sky / "Data/sky.ini", "[sky]", 0644);CHECK(chmod((sky / "Data").c_str(), 0755) == 0 && chmod(sky.c_str(), 0755) == 0);- model.RequestImport({hb::ImportRequestKind::Add, {}, "internal", "Sky", "Game.exe"});+ // Added to play in place: it is prepared without Play, its files opened first.+ const auto opens_at_add = drop_opens.load();+ const auto launches_at_add = launched.size();+ model.RequestImport({hb::ImportRequestKind::Add, {}, "internal", "Sky", "Game.exe", true});std::string sky_id;tick_until([&] {for (const auto& game : source.Snapshot()->games)@@ -780,6 +783,12 @@ void ImportedGamePlaysInPlace() {game_of(model, GameId::Local(sky_id));});const auto game = GameId::Local(sky_id);+ tick_until([&] {+ const auto found = model.state().runtime_games.find(game);+ return !host.Snapshot().preparing_app && found != model.state().runtime_games.end() &&+ (found->second.prepared || found->second.awaiting_registration);+ });+ CHECK(drop_opens.load() == opens_at_add + 2 && launched.size() == launches_at_add); // at the add, then before preparingCHECK(source.Snapshot()->games.size() == 2);CHECK(Mode(sky) == 0777 && Mode(sky / "Data") == 0777 && Mode(sky / "Data/sky.ini") == 0666 &&Mode(sky / "Game.exe") == 0777 && drop_raises > 0);diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cppindex 611e697..751c156 100644--- a/tests/homebrew_library_model_test.cpp+++ b/tests/homebrew_library_model_test.cpp@@ -2569,8 +2569,9 @@ void live_import_sheet_sends_requests() {activate(model, "import-play-in-place");requests = model.TakeImportRequests();check(requests.size() == 1 && requests.front().kind == ImportRequestKind::Add && requests.front().volume_id == "internal" &&- requests.front().folder == "playden-import/Delores" && requests.front().program == "Delores.exe",- "choosing the program adds the folder");+ requests.front().folder == "playden-import/Delores" && requests.front().program == "Delores.exe" &&+ requests.front().prepare,+ "choosing the program adds the folder, to be prepared there");check(model.view().surface == "import-games" &&model.state().navigation.focus_key == "import-candidate-internal:playden-import/Delores","back on the sheet at the folder");@@ -2651,8 +2652,8 @@ void live_import_choice_and_details() {activate(model, "volume-usb1");requests = model.TakeImportRequests();check(requests.size() == 1 && requests[0].kind == ImportRequestKind::Add && requests[0].volume_id == "usb0" &&- requests[0].program == "Rally.exe",- "Import here adds the folder first");+ requests[0].program == "Rally.exe" && !requests[0].prepare,+ "Import here adds the folder first, prepared once copied");check(model.view().surface == "import-games" && find_row(model, "import-candidate-usb0:playden/import/Rally")->value == "Adding…","the sheet says the folder is being added");const auto id = playden::GameId::Local("6d1f3a52-0c55-4f3e-9b2a-5d1c7e0a9f11");