Play your Steam library's Windows games on a jailbroken PS5.
C++
Check updates only on the open game's page
Leonardo Lobato98c999abddbc
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex fa8b018..4525f75 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -2159,21 +2159,25 @@ void Controller::TickAppDetails() {launches_any_branch_.erase(id);if (auto* details = Details(id.store); details && details == app_details_) details->Refresh(id, generation);}- // After a library refresh, installed Steam games are checked for updates again: the refresh reads the- // licenses (DLC bought since), and details answered before the first one couldn't compare at all.+ // Updates are checked for the game whose page is open, never the whole library. A library refresh reads the+ // licenses (DLC bought since): that page is checked again.const bool loading = state.library_loading;- if (library_loading_ && !loading)- for (const auto& [id, root] : game_roots_)- if (auto* details = Details(id.store); details && details == app_details_ && id.steam_app())- details->Refresh(id, generation);+ if (library_loading_ && !loading && state.navigation.detail_id && game_roots_.count(*state.navigation.detail_id))+ if (auto* details = Details(state.navigation.detail_id->store); details && details == app_details_)+ details->Refresh(*state.navigation.detail_id, generation, true);library_loading_ = loading;}- // Fetch Steam app info when the player opens a game's details while signed in.+ // Fetch Steam app info when the player opens a game's details while signed in, ahead of anything queued. An+ // installed game is asked again at each visit: Steam may have a newer version since.+ // Away from a game's page (or its session), the next visit asks again.+ if (state.navigation.route != Route::Details && state.navigation.route != Route::Session) requested_detail_.reset();if (state.account().authentication == AuthState::SignedIn && state.navigation.detail_id &&state.navigation.detail_id != requested_detail_) {requested_detail_ = state.navigation.detail_id;- if (auto* details = Details(requested_detail_->store); details && details == app_details_)- app_details_->Request(*state.navigation.detail_id, generation);+ if (auto* details = Details(requested_detail_->store); details && details == app_details_) {+ if (game_roots_.count(*requested_detail_)) details->Refresh(*requested_detail_, generation, true);+ else details->RequestFirst(*requested_detail_, generation);+ }}for (const auto& details : app_details_->Pump(8)) {if (details.account_generation != generation) continue;diff --git a/src/steam/app_details_service.cpp b/src/steam/app_details_service.cppindex 27f08e5..782c900 100644--- a/src/steam/app_details_service.cpp+++ b/src/steam/app_details_service.cpp@@ -10,7 +10,7 @@ AppDetailsService::AppDetailsService(AppDetailsSource& source, SessionRepositoryAppDetailsService::~AppDetailsService() { Shutdown(); }-void AppDetailsService::Request(GameId id, std::uint64_t account_generation) {+void AppDetailsService::Request(GameId id, std::uint64_t account_generation, bool first) {if (!id.steam_app() || account_generation == 0) return; // Steam games onlystd::lock_guard<std::mutex> lock(mutex_);if (stopping_) return;@@ -25,19 +25,28 @@ void AppDetailsService::Request(GameId id, std::uint64_t account_generation) {cancel_.store(true, std::memory_order_release);measure_cancel_.store(true, std::memory_order_release);}- if (requested_.count(id) || pending_.size() >= kMaxPending) return;+ if (requested_.count(id)) {+ // Queued already: it goes first. In flight or answered: nothing to do.+ if (const auto queued = std::find(pending_.begin(), pending_.end(), id); first && queued != pending_.end()) {+ pending_.erase(queued);+ pending_.push_front(id);+ }+ return;+ }+ if (pending_.size() >= kMaxPending && !first) return;requested_.insert(id);- pending_.push_back(id);+ if (first) pending_.push_front(id);+ else pending_.push_back(id);wake_.notify_all();}-void AppDetailsService::Refresh(GameId id, std::uint64_t account_generation) {+void AppDetailsService::Refresh(GameId id, std::uint64_t account_generation, bool first) {{std::lock_guard<std::mutex> lock(mutex_);if (account_generation == generation_ && std::find(pending_.begin(), pending_.end(), id) == pending_.end())requested_.erase(id);}- Request(id, account_generation);+ Request(id, account_generation, first);}void AppDetailsService::Invalidate(std::uint64_t account_generation) {diff --git a/src/steam/app_details_service.h b/src/steam/app_details_service.hindex 8ce9925..1902eea 100644--- a/src/steam/app_details_service.h+++ b/src/steam/app_details_service.h@@ -128,9 +128,11 @@ class AppDetailsService {AppDetailsService(const AppDetailsService&) = delete;AppDetailsService& operator=(const AppDetailsService&) = delete;- void Request(GameId id, std::uint64_t account_generation);+ // `first`: ahead of what is queued (a game the player opened while installed games are checked for updates);+ // one already queued moves to the front.+ void Request(GameId id, std::uint64_t account_generation, bool first = false);// Asks again for a game already answered in this generation (an installed game whose content changed).- void Refresh(GameId id, std::uint64_t account_generation);+ void Refresh(GameId id, std::uint64_t account_generation, bool first = false);void Invalidate(std::uint64_t account_generation);std::vector<AppDetails> Pump(std::size_t maximum = 8);// Asks for the exact size of one install choice, after the details already asked for. A choice alreadydiff --git a/src/stores/details_source.h b/src/stores/details_source.hindex 6c35e70..45a6883 100644--- a/src/stores/details_source.h+++ b/src/stores/details_source.h@@ -18,8 +18,14 @@ class DetailsSource {virtual ~DetailsSource() = default;virtual Store store() const = 0;virtual void Request(const GameId& id, std::uint64_t generation) = 0;- // Asks again for a game already answered (its install changed); by default, as Request.- virtual void Refresh(const GameId& id, std::uint64_t generation) { Request(id, generation); }+ // Asks again for a game already answered (its install changed, or its page opened again); by default, as Request.+ // `first`: ahead of what is queued.+ virtual void Refresh(const GameId& id, std::uint64_t generation, bool first = false) {+ if (first) RequestFirst(id, generation);+ else Request(id, generation);+ }+ // As Request, ahead of everything queued: the game the player is looking at.+ virtual void RequestFirst(const GameId& id, std::uint64_t generation) { Request(id, generation); }virtual void Invalidate(std::uint64_t generation) = 0;virtual std::vector<GameDetails> Pump(std::size_t maximum) = 0;// The exact size of one install choice (steam::MeasuredSize); a store without it answers nothing.diff --git a/src/stores/steam.h b/src/stores/steam.hindex 0ccc74e..7fa4781 100644--- a/src/stores/steam.h+++ b/src/stores/steam.h@@ -77,8 +77,11 @@ class SteamDetailsSource final : public DetailsSource {void Request(const GameId& id, std::uint64_t generation) override {if (id.steam_app()) service_.Request(id, generation);}- void Refresh(const GameId& id, std::uint64_t generation) override {- if (id.steam_app()) service_.Refresh(id, generation);+ void Refresh(const GameId& id, std::uint64_t generation, bool first = false) override {+ if (id.steam_app()) service_.Refresh(id, generation, first);+ }+ void RequestFirst(const GameId& id, std::uint64_t generation) override {+ if (id.steam_app()) service_.Request(id, generation, true);}void Invalidate(std::uint64_t generation) override { service_.Invalidate(generation); }std::vector<GameDetails> Pump(std::size_t maximum) override { return service_.Pump(maximum); }diff --git a/tests/app_details_test.cpp b/tests/app_details_test.cppindex 5b2f0b6..49d1557 100644--- a/tests/app_details_test.cpp+++ b/tests/app_details_test.cpp@@ -30,7 +30,8 @@ class Source final : public AppDetailsSource {std::vector<std::vector<GameId>> calls;std::vector<SizeRequest> measures;std::atomic<bool> fail{false};- std::atomic<bool> hold{false}; // a size check that waits (on manifests) until released or canceled+ std::atomic<bool> hold{false};+ std::atomic<bool> block_fetch{false}; // Fetch waits until released // a size check that waits (on manifests) until released or canceledMeasuredSize Measure(const StoredSession&, const SizeRequest& request, const std::atomic<bool>& cancel) override {{std::lock_guard<std::mutex> lock(mutex);@@ -52,6 +53,7 @@ class Source final : public AppDetailsSource {std::lock_guard<std::mutex> lock(mutex);calls.push_back(ids);}+ while (block_fetch) std::this_thread::sleep_for(1ms);if (fail) return {};std::vector<AppDetails> result;for (const auto& id : ids) result.push_back({id, 0, true, *id.steam_app() * 10ull, *id.steam_app() * 100ull, true, {}});@@ -188,6 +190,35 @@ void SizeChecksAreAnsweredOncePerChoice() {assert(AwaitMeasured(service, 1)[0].account_generation == 2);}+// The game the player opens goes ahead of installed games checked for updates, queued or not.+void OpenedGameGoesFirst() {+ Sessions sessions;+ Source source;+ source.hold = false;+ AppDetailsService service(source, sessions);+ {+ std::lock_guard<std::mutex> lock(source.mutex);+ source.block_fetch = true;+ }+ for (std::uint32_t app = 100; app < 140; ++app) service.Request(SteamId(app), 1); // the first batch blocks the worker+ const auto deadline = std::chrono::steady_clock::now() + 2s;+ for (;;) {+ {+ std::lock_guard<std::mutex> lock(source.mutex);+ if (!source.calls.empty()) break;+ }+ assert(std::chrono::steady_clock::now() < deadline);+ std::this_thread::sleep_for(1ms);+ }+ service.Request(SteamId(620), 1, true); // not queued yet+ service.Request(SteamId(135), 1, true); // queued at the back+ source.block_fetch = false;+ Await(service, 40);+ std::lock_guard<std::mutex> lock(source.mutex);+ assert(source.calls.size() >= 2 && source.calls[1].size() >= 2);+ assert(source.calls[1][0] == SteamId(135) && source.calls[1][1] == SteamId(620));+}+// A size check waiting on manifests doesn't hold up a game's details: they have their own worker.void SlowSizeChecksDontBlockDetails() {Sessions sessions;@@ -548,6 +579,7 @@ void InstalledGamesCompareWithTheirRecord() {int main() {SizeChecksAreAnsweredOncePerChoice();SlowSizeChecksDontBlockDetails();+ OpenedGameGoesFirst();LargeOverlappingDepotsAreMeasured();SizesCountOnlyLicensedDepots();RequestsAreDeduplicatedPerGeneration();diff --git a/tests/homebrew_installed_locations_test.cpp b/tests/homebrew_installed_locations_test.cppindex 6e98494..8a74f7b 100644--- a/tests/homebrew_installed_locations_test.cpp+++ b/tests/homebrew_installed_locations_test.cpp@@ -992,7 +992,7 @@ class ScriptedDetails final : public playden::stores::DetailsSource {std::lock_guard<std::mutex> lock(mutex);asked.emplace_back(id, false);}- void Refresh(const playden::GameId& id, std::uint64_t) override {+ void Refresh(const playden::GameId& id, std::uint64_t, bool = false) override {std::lock_guard<std::mutex> lock(mutex);asked.emplace_back(id, true);}