Play your Steam library's Windows games on a jailbroken PS5.
C++
Hold an imported game's copy and removal during setup
Leonardo Lobatod8642ff5cca6
diff --git a/README.md b/README.mdindex 6f27e87..c265a4a 100644--- a/README.md+++ b/README.md@@ -269,7 +269,8 @@ The drive must be exFAT. The PS5 can't read NTFS, and FAT32 can't hold files ovecopy, and once the copy is checked the game's files leave the drop folder, so it isn't stored twice. Until thenit plays from the drop folder.-You can import a game that plays from its folder later, with **Import into Playden** on its page. The PS5 adds the+You can import a game that plays from its folder later, with **Copy to storage** on its page (**Move to storage** for+one in the drop folder). The PS5 adds thegame's title to Home when Playden quits. Importing a game later keeps its saves.**Limits:**diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex 9a4a0e4..d7e97b5 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -357,6 +357,15 @@ void reconcile_library_selection(State& state) {std::string game_key(GameId id) { return "game-" + ToKey(id); }+// A game's setup is under way: it's being set up or waiting for that, its bottle is being changed, or Play is installing+// something first. Its files stay where they are until that ends.+bool setup_under_way(const State& state, GameId id) {+ const auto found = state.runtime_games.find(id);+ if (found == state.runtime_games.end()) return false;+ const auto& game = found->second;+ return game.status == "Preparing" || game.queued || game.maintenance_running || !game.play_work.empty();+}+std::vector<std::string> context_actions(bool live) {if (live) return {"favorite", "collection", "note", "hide", "uninstall", "cancel"};return {"favorite", "collection", "note", "hide", "verify", "uninstall", "logs", "cancel"};@@ -1309,7 +1318,7 @@ void Simulation::choose_import_volume(const std::string& volume_id) {const auto kind = subject.volume == kImportDropVolume && volume_id == kImportDropVolume ? ImportRequestKind::MoveIntoPlayden: ImportRequestKind::CopyIntoPlayden;if (import_choice_game_.valid()) {- // A game already added (its page's Import into Playden): the transfer starts on its page.+ // A game already added (its page's Copy to storage): the transfer starts on its page.const auto id = import_choice_game_;start_import_transfer(id, kind, volume_id);open_game_page(id);@@ -6429,6 +6438,10 @@ void Simulation::rebuild_view() {runtime_game != state_.runtime_games.end() && runtime_game->second.maintenance_running)item.value = "Working…";}+ else if (action_key == "import-remove" && setup_under_way(state_, state_.navigation.selected_game_id)) {+ item.enabled = false;+ item.subtitle = "Waits for setup to finish";+ }else if (action_key == "verify" || action_key == "uninstall") {if (!is_installed(state_, state_.navigation.selected_game_id)) { item.enabled = false; item.subtitle = "Game is not installed"; }} else if (action_key == "hide") item.title = state_.library.hidden.contains(state_.navigation.selected_game_id) ? "Unhide" : "Hide";@@ -6922,8 +6935,9 @@ void Simulation::rebuild_view() {}}if (imported) {- // An imported game: Import into Playden while it plays from its folder (the copy's- // progress while it runs), then Remove from library; a copy in Playden uninstalls.+ // An imported game: Copy to storage while it plays from its folder (the copy's progress+ // while it runs), then Remove from library; a copy in Playden uninstalls. Both wait for setup.+ const bool setup_busy = setup_under_way(state_, game->id);const auto starting = copying || !in_place ? import_transfers_starting_.end(): import_transfers_starting_.find(game->id);if (starting != import_transfers_starting_.end()) {@@ -6941,12 +6955,13 @@ void Simulation::rebuild_view() {row("details-cancel-copy", RowKind::Action, "Cancel copy…", "import-cancel-copy");} else if (const auto* external = in_place ? external_game(game->id) : nullptr; external && external->available) {// Its drive is there: a folder the PS5 can't play from (its name) can still be copied.- row("details-copy", RowKind::Action, "Import into Playden…",- "import-copy-game");+ // The drop folder's game leaves it; a drive keeps its copy.+ row("details-copy", RowKind::Action, external->volume_id == kImportDropVolume ? "Move to storage…" : "Copy to storage…",+ "import-copy-game").enabled = !setup_busy;}if (in_place) {row("details-remove", RowKind::Action, "Remove from library…", "import-remove").enabled =- !copying && starting == import_transfers_starting_.end();+ !copying && starting == import_transfers_starting_.end() && !setup_busy;// Where it plays from, under the buttons.for (const auto& candidate : state_.import_candidates)if (candidate.imported == game->id && installation->available) {@@ -9536,8 +9551,9 @@ void Simulation::activate() {} else if (action_name == "import-play-in-place" || action_name == "import-copy") {choose_import(action_name);} else if (action_name == "import-copy-game") {- // An imported game playing from its folder: Import into Playden opens the drive choice.+ // An imported game playing from its folder: Copy to storage opens the drive choice.const auto id = state_.navigation.detail_id.value_or(state_.navigation.selected_game_id);+ if (setup_under_way(state_, id)) return;if (const auto* external = external_game(id); external && external->available && !import_copy_job(id)) open_import_storage(id);} else if (action_name == "import-cancel-copy") {// The same cancel as Queue's, from the game's page.@@ -9556,7 +9572,7 @@ void Simulation::activate() {// Out of the library; the folder stays where it is.const auto id = state_.navigation.detail_id.value_or(state_.navigation.selected_game_id);const auto* game = find_game(state_, id);- if (!game || !external_game(id)) return;+ if (!game || !external_game(id) || setup_under_way(state_, id)) return;pending_destructive_action_ = action_name;destructive_target_ = id;ModalEntry confirmation{"confirmation", "Remove " + game->title + " from the library?", state_.navigation.focus_key,diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex efed426..baba424 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -1465,7 +1465,7 @@ private:// The import wizard. Step 1 (surface import-choice), for the program picked in the open program// list: play the game from its folder, or Import into Playden. Step 2 (surface import-storage):// the drive the game goes to, for that program's folder or for a game already added- // (import_choice_game_ valid: its page's Import into Playden opens step 2 directly).+ // (import_choice_game_ valid: its page's Copy to storage opens step 2 directly).void open_import_choice(std::size_t program);void open_import_storage(GameId game = {});void choose_import(const std::string& action);diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cppindex 7459d8a..8c707b8 100644--- a/tests/homebrew_library_model_test.cpp+++ b/tests/homebrew_library_model_test.cpp@@ -3941,26 +3941,51 @@ void live_import_choice_and_details() {model.UpdateInstalls({}, {});// Its page while it plays from the drive, then while it copies.- check(find_row(model, "details-copy") && find_row(model, "details-copy")->title == "Import into Playden…" &&+ check(find_row(model, "details-copy") && find_row(model, "details-copy")->title == "Copy to storage…" &&find_row(model, "details-remove") && !has_row(model, "details-cloud") && !has_row(model, "details-uninstall"),- "an imported game on a drive offers Copy into Playden and Remove from library");- // The page's Import into Playden opens step 2 with the folder's size (from the scan, the game has none).+ "an imported game on a drive offers Copy to storage and Remove from library");+ {+ // Both wait while the game is set up, and so does Remove in its actions.+ using playden::homebrew::LiveRuntimeGame;+ using playden::homebrew::RuntimeState;+ check(find_row(model, "details-copy")->enabled && find_row(model, "details-remove")->enabled, "both work when nothing runs");+ for (int state = 0; state < 4; ++state) {+ LiveRuntimeGame busy; busy.game_id = id; busy.status = state == 0 ? "Preparing" : "Ready";+ if (state == 1) busy.queued = true;+ if (state == 2) busy.maintenance_running = true;+ if (state == 3) busy.play_work = "Installing PhysX…";+ model.UpdateRuntime(RuntimeState::Ready, {busy});+ check(!find_row(model, "details-copy")->enabled && !find_row(model, "details-remove")->enabled, "both wait for setup");+ if (model.action("focus:details-remove")) model.action("cross");+ check(model.state().navigation.modals.empty(), "Remove can't be pressed during setup");+ }+ activate(model, "details-more");+ check(find_row(model, "import-remove") && !find_row(model, "import-remove")->enabled, "Game actions' Remove waits too");+ model.action("circle");+ LiveRuntimeGame done; done.game_id = id; done.status = "Ready"; done.ready = done.can_play = true;+ model.UpdateRuntime(RuntimeState::Ready, {done});+ check(find_row(model, "details-copy")->enabled && find_row(model, "details-remove")->enabled, "both are back after setup");+ model.UpdateExternalGames({{id, "internal", true, ""}});+ check(find_row(model, "details-copy")->title == "Move to storage…", "a game in the drop folder moves");+ model.UpdateExternalGames({{id, "usb0", true, ""}});+ }+ // The page's Copy to storage opens step 2 with the folder's size (from the scan, the game has none).activate(model, "details-copy");check(model.view().surface == "import-storage" && model.view().subtitle == "8.9 GB will be copied there." &&!find_row(model, "volume-usb0")->enabled && model.view().eyebrow == "Import games · Rally",- "the page's Import into Playden opens the drive choice with the folder's size");+ "the page's Copy to storage opens the drive choice with the folder's size");model.action("circle");check(model.state().navigation.modals.empty(), "Back closes the page's drive choice");// A folder the PS5 can't play from (its name) still offers the copy.model.UpdateExternalGames({{id, "usb0", true, "The game's folder name has characters the PS5 can't play from."}});check(has_row(model, "details-installed") && has_row(model, "details-copy") && has_row(model, "details-remove"),- "a copy-only folder says why and offers Import into Playden");+ "a copy-only folder says why and offers Copy to storage");model.UpdateExternalGames({{id, "usb0", true, ""}});model.UpdateInstalls({{id, playden::homebrew::JobState::Downloading, 4'450'000'000, 8'900'000'000, {}, "usb1"}}, {});const auto* copying = find_row(model, "details-download");check(copying && copying->title == "Copying" && copying->progress > 0.49F && copying->progress < 0.51F &&!has_row(model, "details-copy") && !find_row(model, "details-remove")->enabled,- "the copy's progress replaces Import into Playden");+ "the copy's progress replaces Copy to storage");// A failed copy can be cancelled from the page; the game plays in place again.model.UpdateInstalls({{id, playden::homebrew::JobState::Failed, 4'450'000'000, 8'900'000'000, "Copy failed", "usb1"}}, {});check(find_row(model, "details-cancel-copy") && !find_row(model, "details-remove")->enabled, "a failed copy offers Cancel copy");diff --git a/tests/homebrew_management_tour_test.cpp b/tests/homebrew_management_tour_test.cppindex 29126c7..272eb01 100644--- a/tests/homebrew_management_tour_test.cpp+++ b/tests/homebrew_management_tour_test.cpp@@ -211,7 +211,7 @@ int main(int argc, char** argv) {choose(importing, "details-copy");require(importing.view().surface == "import-storage" && has_row(importing, "volume-internal") &&!has_row(importing, "import-play-in-place"),- "Import into Playden asks for the drive");+ "Copy to storage asks for the drive");choose(importing, "volume-internal");require(importing.state().navigation.route == Route::Details && has_row(importing, "details-download") &&!has_row(importing, "details-copy"),diff --git a/tests/homebrew_simulation_test.cpp b/tests/homebrew_simulation_test.cppindex f4fb25f..060230e 100644--- a/tests/homebrew_simulation_test.cpp+++ b/tests/homebrew_simulation_test.cpp@@ -1346,10 +1346,10 @@ static void t18_imported_game_page(const std::filesystem::path& fixtures, const};check(simulation.scenario("import-details"), "T18 import-details scenario");check(simulation.state().navigation.route == Route::Details && row("details-play") && row("details-play")->title == "Play" &&- row("details-copy")->title == "Import into Playden…" && row("details-remove")->title == "Remove from library…" &&+ row("details-copy")->title == "Copy to storage…" && row("details-remove")->title == "Remove from library…" &&row("details-folder")->title == "Plays from /mnt/usb0/playden/import/Night Sky" && !row("details-cloud"),"T18 an imported game's page plays in place and offers Import and Remove");- // Import into Playden: the wizard's drive choice at once; Back closes it.+ // Copy to storage: the wizard's drive choice at once; Back closes it.press("details-copy");check(simulation.view().surface == "import-storage" && simulation.view().title == "Choose storage" &&simulation.view().subtitle == "412 MB will be copied there." &&@@ -1359,7 +1359,7 @@ static void t18_imported_game_page(const std::filesystem::path& fixtures, const!row("volume-readonly")->enabled && row("volume-readonly")->subtitle == "No write access" &&simulation.state().navigation.focus_key == "volume-external" &&simulation.view().legends.front() == "Cross Import here" && simulation.view().rows.back().title == "Back",- "T18 Import into Playden from the page opens the drive choice, the default drive focused");+ "T18 Copy to storage from the page opens the drive choice, the default drive focused");simulation.action("circle");check(simulation.state().navigation.modals.empty() && simulation.state().navigation.route == Route::Details,"T18 Back from the page's drive choice closes it");