Play your Steam library's Windows games on a jailbroken PS5.
C++
Add a Downloads for slow networks setting
Leonardo Lobatof828672a9b6e
diff --git a/README.md b/README.mdindex fb775de..c264da3 100644--- a/README.md+++ b/README.md@@ -238,17 +238,9 @@ build/homebrew-host/playden-homebrew --simulation --scenario signed-out- Two game settings, "120 Hz output" and "OpenGL worker thread", are not available with this kit.- When you close a game from the PS5 menu, it can stay suspended. Pressing Play again resumes it instead of startingit again.-- Downloads can be slow (about 1 MB/s) on some networks, far from a fast Steam server. Playden downloads 4 pieces at- the same time. To try 8, put a file named `download-tuning.txt` in `/data/homebrew/FAKE77031/dev/` over FTP, with- these two lines:-- ```- slots=8- ahead=256- ```-- The next download uses it. `slots` can be 1 to 8. On a fast connection 8 can be slower than 4; delete the file to- go back. ([#29](https://github.com/leolobato/playden-ps5/issues/29))+- Downloads can be slow (about 1 MB/s) on some networks, far from a fast Steam server. Turn on Settings › Storage ›+ **Downloads for slow networks**: Playden then downloads 8 pieces at the same time instead of 4. On a fast connection+ it can be slower, so turn it off again if downloads get slower.See the [compatibility list](COMPATIBILITY.md) for what we know about each game.diff --git a/src/app/preferences.cpp b/src/app/preferences.cppindex b0d2714..5281696 100644--- a/src/app/preferences.cpp+++ b/src/app/preferences.cpp@@ -33,7 +33,7 @@ PreferencesLoadResult PreferencesStore::Load() const {const std::string serialized = ToString(read.value());// Version 1 holds only reduce_motion; version 2 adds title_store_suffix; version 3 cloud_saves_auto;- // version 4 steam_sign_in_password.+ // version 4 steam_sign_in_password; version 5 downloads_slow_network.for (const int motion : {0, 1}) {if (serialized == std::string("version=1\nreduce_motion=") + char('0' + motion) + "\n") {Preferences preferences;@@ -71,6 +71,22 @@ PreferencesLoadResult PreferencesStore::Load() const {preferences.steam_sign_in_password = password == 1;return PreferencesLoadResult{preferences, PreferencesLoadStatus::kLoaded, std::string()};}+ for (const int suffix : {0, 1})+ for (const int cloud : {0, 1})+ for (const int password : {0, 1})+ for (const int slow : {0, 1})+ if (serialized == std::string("version=5\nreduce_motion=") + char('0' + motion) ++ "\ntitle_store_suffix=" + char('0' + suffix) + "\ncloud_saves_auto=" + char('0' + cloud) ++ "\nsteam_sign_in_password=" + char('0' + password) ++ "\ndownloads_slow_network=" + char('0' + slow) + "\n") {+ Preferences preferences;+ preferences.reduce_motion = motion == 1;+ preferences.title_store_suffix = suffix == 1;+ preferences.cloud_saves_auto = cloud == 1;+ preferences.steam_sign_in_password = password == 1;+ preferences.downloads_slow_network = slow == 1;+ return PreferencesLoadResult{preferences, PreferencesLoadStatus::kLoaded, std::string()};+ }}return PreferencesLoadResult{Preferences{}, PreferencesLoadStatus::kDefaultCorrupt,@@ -80,10 +96,11 @@ PreferencesLoadResult PreferencesStore::Load() const {Result<void> PreferencesStore::Save(const Preferences& preferences) const {const auto ready=storage_.EnsureRootDirectory();if(!ready.ok()) return ready;- const std::string text = std::string("version=4\nreduce_motion=") + (preferences.reduce_motion ? "1" : "0") ++ const std::string text = std::string("version=5\nreduce_motion=") + (preferences.reduce_motion ? "1" : "0") +"\ntitle_store_suffix=" + (preferences.title_store_suffix ? "1" : "0") +"\ncloud_saves_auto=" + (preferences.cloud_saves_auto ? "1" : "0") +- "\nsteam_sign_in_password=" + (preferences.steam_sign_in_password ? "1" : "0") + "\n";+ "\nsteam_sign_in_password=" + (preferences.steam_sign_in_password ? "1" : "0") ++ "\ndownloads_slow_network=" + (preferences.downloads_slow_network ? "1" : "0") + "\n";return storage_.WriteAtomic(kPreferencesPath, Bytes(text.begin(), text.end()));}diff --git a/src/app/preferences.h b/src/app/preferences.hindex 3d94148..1d3428b 100644--- a/src/app/preferences.h+++ b/src/app/preferences.h@@ -16,6 +16,9 @@ struct Preferences {bool cloud_saves_auto = false;// The sign-in screen opens on the account name and password form: the last sign-in used it.bool steam_sign_in_password = false;+ // Downloads for slow networks: 8 pieces at a time instead of 4. Far from a fast Steam server each piece waits+ // long for its answer, and more of them in flight make up for it (#29); on a fast connection 4 is quicker.+ bool downloads_slow_network = false;};enum class PreferencesLoadStatus {diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cppindex 8627f7e..ce4bb7e 100644--- a/src/homebrew/ps5.cpp+++ b/src/homebrew/ps5.cpp@@ -142,6 +142,8 @@ struct UsbKeyboard {std::string title_root = "/app0";std::string log_root = "/app0/logs";+// Settings › Downloads for slow networks, read by the install worker when a download starts.+std::atomic<bool> downloads_slow_network{false};// Development requests are processed in file order on the first frame.std::vector<playden::steam::InstallRequest> take_install_requests(bool runtime_ready) {const std::string request_path = title_root + "/dev/install-request.txt";@@ -277,7 +279,12 @@ int main() {playden::steam::CdnClient install_cdn(paths.trust_store);playden::steam::SteamInstallRunner install_runner(install_cm, install_cdn);install_runner.SetTuning([root = paths.title_root] {- return playden::steam::ReadDownloadTuning(root + "/dev/download-tuning.txt");+ // A developer's tuning file wins over the setting.+ const auto file = root + "/dev/download-tuning.txt";+ if (::access(file.c_str(), F_OK) == 0) return playden::steam::ReadDownloadTuning(file);+ playden::steam::DownloadTuning tuning;+ if (downloads_slow_network.load()) tuning.slots = 8;+ return tuning;});install_runner.SetLog([](playden::GameId app, const char* step, const char* category, const char* detail) {char line[640];@@ -581,6 +588,7 @@ int main() {const auto dispatched = hui::sys::monotonic_us();#if !PLAYDEN_UI_SIMULATIONservices.Tick();+ downloads_slow_network.store(simulation.state().downloads_slow_network);#endifconst auto ticked = hui::sys::monotonic_us();if (simulation.state().quit_requested) break;diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex 96160a2..5594f89 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -1797,7 +1797,8 @@ playden::OrganizationSnapshot Simulation::ExportOrganization() const {}playden::Preferences Simulation::ExportPreferences() const {- return {state_.reduced_motion, state_.title_store_suffix, state_.cloud_saves_auto, state_.sign_in_password};+ return {state_.reduced_motion, state_.title_store_suffix, state_.cloud_saves_auto, state_.sign_in_password,+ state_.downloads_slow_network};}void Simulation::apply_organization_snapshot(const playden::OrganizationSnapshot& snapshot) {@@ -2022,6 +2023,7 @@ bool Simulation::ApplyPreferences(PersistenceLoadToken token,state_.title_store_suffix = loaded.preferences.title_store_suffix;state_.cloud_saves_auto = loaded.preferences.cloud_saves_auto;state_.sign_in_password = loaded.preferences.steam_sign_in_password;+ state_.downloads_slow_network = loaded.preferences.downloads_slow_network;captured_preferences_ = loaded.preferences;preferences_saved_revision_ = preferences_revision_;}@@ -2098,7 +2100,8 @@ bool Simulation::record_live_persistence() {(after_preferences.reduce_motion != captured_preferences_.reduce_motion ||after_preferences.title_store_suffix != captured_preferences_.title_store_suffix ||after_preferences.cloud_saves_auto != captured_preferences_.cloud_saves_auto ||- after_preferences.steam_sign_in_password != captured_preferences_.steam_sign_in_password);+ after_preferences.steam_sign_in_password != captured_preferences_.steam_sign_in_password ||+ after_preferences.downloads_slow_network != captured_preferences_.downloads_slow_network);if (organization_changed && !snapshot_within_model_bounds(after_organization)) {apply_organization_snapshot(captured_organization_);@@ -2120,6 +2123,7 @@ bool Simulation::record_live_persistence() {state_.title_store_suffix = captured_preferences_.title_store_suffix;state_.cloud_saves_auto = captured_preferences_.cloud_saves_auto;state_.sign_in_password = captured_preferences_.steam_sign_in_password;+ state_.downloads_slow_network = captured_preferences_.downloads_slow_network;organization_journal_full_ = true;force_organization_reset_ = false;force_organization_selection_ = false;@@ -3892,6 +3896,13 @@ void Simulation::rebuild_view() {runtime.subtitle = state_.runtime_problem.empty() ? "Games run through prospero-win" : state_.runtime_problem;runtime.kind = RowKind::Status; runtime.action.clear(); runtime.enabled = false;}+ if (live()) {+ auto& slow = add("settings-downloads-slow", RowKind::Toggle, "Downloads for slow networks", "toggle-downloads-slow");+ slow.selected = state_.downloads_slow_network;+ slow.subtitle = state_.downloads_slow_network+ ? "8 pieces at a time. Turn it off if downloads got slower."+ : "Off: 4 pieces at a time. Turn it on if downloads stay near 1 MB/s.";+ }section = "Display";auto& motion = add("settings-motion", RowKind::Toggle, "Reduced motion", "toggle-motion");motion.selected = state_.reduced_motion;@@ -5846,6 +5857,10 @@ void Simulation::activate() {else if (action_name == "toggle-motion") { state_.reduced_motion = !state_.reduced_motion; save_profile(); }else if (action_name == "toggle-title-store") { state_.title_store_suffix = !state_.title_store_suffix; save_profile(); }else if (action_name == "toggle-cloud-saves") { state_.cloud_saves_auto = !state_.cloud_saves_auto; save_profile(); }+ else if (action_name == "toggle-downloads-slow") {+ state_.downloads_slow_network = !state_.downloads_slow_network;+ save_profile();+ }else if (action_name == "launch") { state_.session_game_id = state_.navigation.selected_game_id; state_.session = SessionState::Preparing; state_.navigation.route = Route::Session; state_.navigation.focus_key = "session-return"; }else if (action_name == "runtime-status") open_modal({"runtime", "Runtime unavailable", "details-play", {"runtime-retry", "cancel"}, 0, false});else if (action_name == "return-game") state_.session = SessionState::Running;diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex 654de99..346178a 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -484,6 +484,7 @@ struct State {bool reduced_motion = false;bool title_store_suffix = false; // PS5 titles named "<game> (Steam)"bool cloud_saves_auto = false; // Cloud saves move before Play, after sessions and at startup (opt-in)+ bool downloads_slow_network = false; // 8 download pieces at a time instead of 4 (Settings › Storage)bool controller_connected = true;ControllerState controller;bool persistence_available = true;diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cppindex 60c40be..f02f2ac 100644--- a/tests/homebrew_library_model_test.cpp+++ b/tests/homebrew_library_model_test.cpp@@ -1039,8 +1039,17 @@ void live_storage_section_and_installed_games() {check(find_row(model, "settings-storage")->action == "storage-picker", "Games storage opens the drive picker");std::vector<std::string> order;for (const auto& row : model.view().rows) if (row.section == "Storage") order.push_back(row.key);- check(order == std::vector<std::string>{"settings-storage", "settings-installed", "settings-kept", "settings-runtime"},+ check(order == std::vector<std::string>{"settings-storage", "settings-installed", "settings-kept",+ "settings-runtime", "settings-downloads-slow"},"Storage lists its rows in order, without the hidden cleanup row");+ // Downloads for slow networks (#29): off by default, a toggle saved with the preferences.+ check(!find_row(model, "settings-downloads-slow")->selected && !model.ExportPreferences().downloads_slow_network,+ "standard downloads by default");+ activate(model, "settings-downloads-slow");+ check(find_row(model, "settings-downloads-slow")->selected && model.ExportPreferences().downloads_slow_network,+ "the toggle turns downloads for slow networks on");+ activate(model, "settings-downloads-slow");+ check(!model.ExportPreferences().downloads_slow_network, "and off again");std::vector<std::string> sections;for (const auto& row : model.view().rows)if (sections.empty() || sections.back() != row.section) sections.push_back(row.section);@@ -1054,7 +1063,7 @@ void live_storage_section_and_installed_games() {order.clear();for (const auto& row : model.view().rows) if (row.section == "Storage") order.push_back(row.key);check(order == std::vector<std::string>{"settings-storage", "settings-installed", "settings-kept",- "settings-runtime-cleanup", "settings-runtime"},+ "settings-runtime-cleanup", "settings-runtime", "settings-downloads-slow"},"unused settings data sits before Runtime status when there is some");model.SetRuntimeLeftovers(0);// The Settings drive picker changes the default, not one install's drive.@@ -1069,9 +1078,9 @@ void live_storage_section_and_installed_games() {model.view().rows[static_cast<std::size_t>(model.view().focused_row)].section == "Storage","Up on Storage's first row does not leave the section");if (model.state().navigation.tabs_focused) model.action("down");- check(model.action("focus:settings-runtime"), "Runtime status is focused");+ check(model.action("focus:settings-downloads-slow"), "Downloads for slow networks is focused");model.action("down");- check(model.state().navigation.focus_key == "settings-runtime", "Down on Storage's last row stays on it");+ check(model.state().navigation.focus_key == "settings-downloads-slow", "Down on Storage's last row stays on it");model.action("left");model.action("down");model.action("right");diff --git a/tests/preferences_test.cpp b/tests/preferences_test.cppindex 138c80a..89eea45 100644--- a/tests/preferences_test.cpp+++ b/tests/preferences_test.cpp@@ -186,8 +186,9 @@ void SignInMethodPersistsAndVersionThreeOpensQr() {Check(store.Save(preferences).ok(), "sign-in method preference saves");const auto saved = storage.Read("preferences.conf");Check(saved.ok() && std::string(saved.value().begin(), saved.value().end()) ==- "version=4\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=1\nsteam_sign_in_password=1\n",- "version 4 format");+ "version=5\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=1\nsteam_sign_in_password=1\n"+ "downloads_slow_network=0\n",+ "version 5 format");const auto loaded = store.Load();Check(loaded.status == playden::PreferencesLoadStatus::kLoaded && loaded.preferences.steam_sign_in_password &&loaded.preferences.cloud_saves_auto,@@ -200,6 +201,17 @@ void SignInMethodPersistsAndVersionThreeOpensQr() {three.preferences.title_store_suffix && three.preferences.cloud_saves_auto &&!three.preferences.steam_sign_in_password,"version 3 preferences load and sign in with the QR code");+ preferences.downloads_slow_network = true;+ Check(store.Save(preferences).ok() && store.Load().preferences.downloads_slow_network,+ "downloads for slow networks survive restart");+ const std::string version_four =+ "version=4\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=1\nsteam_sign_in_password=1\n";+ Check(storage.WriteAtomic("preferences.conf", playden::Bytes(version_four.begin(), version_four.end())).ok(),+ "version 4 fixture is written");+ const auto four = store.Load();+ Check(four.status == playden::PreferencesLoadStatus::kLoaded && four.preferences.steam_sign_in_password &&+ !four.preferences.downloads_slow_network,+ "version 4 preferences load with standard downloads");const std::string bad = "version=4\nreduce_motion=0\ntitle_store_suffix=0\ncloud_saves_auto=0\nsteam_sign_in_password=2\n";Check(storage.WriteAtomic("preferences.conf", playden::Bytes(bad.begin(), bad.end())).ok(), "bad fixture is written");Check(store.Load().status == playden::PreferencesLoadStatus::kDefaultCorrupt, "bad sign-in value is corrupt");