Play your Steam library's Windows games on a jailbroken PS5.
C++
Show a slow license check before a download starts
Leonardo Lobato450b5cea1913
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex c113187..9e24e8f 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -1104,7 +1104,8 @@ void Controller::TickInstalls() {const auto now = std::chrono::steady_clock::now();const bool account_changed = model_.state().account_generation != install_generation_;const bool space_due = now - volume_refreshed_at_ >= std::chrono::seconds(10);- if (snapshot.revision == install_revision_ && !account_changed && !space_due) return;+ const bool licenses_due = licenses_notice_at_ && now >= *licenses_notice_at_;+ if (snapshot.revision == install_revision_ && !account_changed && !space_due && !licenses_due) return;{std::vector<LiveVolume> volumes;for (const auto& volume : snapshot.volumes) {@@ -1123,7 +1124,16 @@ void Controller::TickInstalls() {install_revision_ = snapshot.revision;install_generation_ = model_.state().account_generation;std::vector<LiveInstallJob> jobs;+ // A license check that takes a while shows as its own step (issue #47); a quick one never shows.+ constexpr auto kLicensesNoticeDelay = std::chrono::seconds(3);+ licenses_notice_at_.reset();for (const auto& job : snapshot.jobs) {+ bool checking_licenses = false;+ if (job.state == steam::InstallJobState::kRunning && job.step == steam::InstallStep::kCheckingLicenses) {+ const auto notice_at = job.step_since + kLicensesNoticeDelay;+ checking_licenses = now >= notice_at;+ if (!checking_licenses) licenses_notice_at_ = notice_at;+ }JobState state = JobState::Queued;switch (job.state) {case steam::InstallJobState::kQueued: state = JobState::Queued; break;@@ -1132,7 +1142,7 @@ void Controller::TickInstalls() {case steam::InstallJobState::kFailed: state = JobState::Failed; break;}jobs.push_back({job.id, state, job.done_bytes, job.total_bytes, job.failure, job.volume_id,- job.bytes_per_second, job.eta_seconds, job.held_bytes});+ job.bytes_per_second, job.eta_seconds, job.held_bytes, checking_licenses});}std::vector<LiveInstalledGame> installed;for (const auto& game : snapshot.installed) installed.push_back({game.id, game.install_bytes, game.volume_id, game.available});diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hppindex ccd736f..54459f1 100644--- a/src/homebrew/controller.hpp+++ b/src/homebrew/controller.hpp@@ -181,6 +181,7 @@ class Controller {// A game whose title may be running: Cloud must not touch its saves.bool SessionActive(GameId id) const;std::chrono::steady_clock::time_point volume_refreshed_at_{};+ std::optional<std::chrono::steady_clock::time_point> licenses_notice_at_; // when a license check starts showingstd::optional<GameId> requested_detail_;std::uint64_t requested_generation_ = 0;std::unique_ptr<steam::SteamService> service_;diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex d1bd249..f2f8149 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -1025,6 +1025,7 @@ void Simulation::UpdateInstalls(const std::vector<LiveInstallJob>& jobs, const sjob.completed_bytes = live_job.done_bytes;job.total_bytes = live_job.total_bytes;job.held_bytes = live_job.held_bytes;+ job.checking_licenses = live_job.state == JobState::Downloading && live_job.checking_licenses;job.failure = live_job.failure;job.volume_id = live_job.volume_id;if (live_job.state == JobState::Downloading) {@@ -5313,6 +5314,16 @@ bool Simulation::action(const std::string& logical_action) {if (!job && state_.navigation.focus_key.rfind("job-", 0) == 0) job = find_job(state_, state_.navigation.focus_key.substr(4));if (!job) job = find_job(state_, "job-1");if (job) { job->state = JobState::Failed; job->retry_stage = wanted_stage; job->stage = job->retry_stage; job->failure = injected == "verification-failed" ? "Verification failed" : "Download failed"; }+ } else if (injected == "checking-licenses") {+ const auto active = std::find_if(state_.jobs.begin(), state_.jobs.end(), [](const Job& value) {+ return value.stage == JobStage::Download && value.state != JobState::Downloaded;+ });+ if (active != state_.jobs.end()) {+ active->state = JobState::Downloading;+ active->checking_licenses = true;+ active->completed_bytes = 0;+ active->total_bytes = 0;+ }} else if (injected == "uninstall-failed") {const auto job = std::find_if(state_.jobs.begin(), state_.jobs.end(), [](const Job& value) { return value.kind == "uninstall" && value.state != JobState::Downloaded; });if (job != state_.jobs.end()) { job->state = JobState::Failed; job->stage = JobStage::Uninstall; job->retry_stage = JobStage::Uninstall; job->failure = "Uninstall failed"; }diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hppindex 6b0dc96..e19023d 100644--- a/src/homebrew/simulation.hpp+++ b/src/homebrew/simulation.hpp@@ -54,6 +54,7 @@ struct LiveInstallJob {std::optional<std::uint64_t> bytes_per_second;std::optional<int> eta_seconds;std::uint64_t held_bytes = 0; // installed bytes already on the drive+ bool checking_licenses = false; // a slow Steam license check before the download starts};struct LiveInstalledGame {GameId game_id = 0;@@ -288,6 +289,7 @@ struct Job {bool completion_applied = false;std::uint64_t held_bytes = 0; // live: installed bytes already on the drivestd::int64_t finished_at = 0; // live: when a Downloaded job finished (Unix seconds), 0 unknown+ bool checking_licenses = false; // live: a slow Steam license check before the download starts};struct Volume {diff --git a/src/homebrew/view.cpp b/src/homebrew/view.cppindex 26a602f..94239ed 100644--- a/src/homebrew/view.cpp+++ b/src/homebrew/view.cpp@@ -1551,6 +1551,8 @@ class Render::Impl{if (status.job != nullptr){+ if (status.job->checking_licenses)+ return "Checking licenses";if (status.job->state == JobState::Downloading && status.job->total_bytes > 0)return std::to_string(static_cast<int>(100.0 * status.job->completed_bytes / status.job->total_bytes)) +"% · " + job_state_label(status.job->state);@@ -1802,12 +1804,21 @@ class Render::Implbar.set_bounds({282.0F, 302.0F, 756.0F, 12.0F});bar.set_value(std::clamp(progress, 0.0F, 1.0F), true);bar.draw(canvas);- const std::string bytes = byte_count(primary->completed_bytes) + " / " +- byte_count(primary->total_bytes);- ui::text(scene_, fonts_.regular, bytes, 282.0F, 352.0F, 22.0F, kText);- ui::text(scene_, fonts_.regular, FormatDownloadRate(primary->state == JobState::Downloading ? primary->bytes_per_second : std::nullopt,- primary->state == JobState::Downloading ? primary->eta_seconds : std::nullopt), 1038.0F,- 352.0F, 22.0F, kSecondary, gfx::Align::right);+ if (primary->checking_licenses)+ {+ // Large accounts take a minute here, before Steam gives the download size (issue #47).+ spinner(292.0F, 345.0F, 9.0F, kBlue);+ ui::text(scene_, fonts_.regular, "Checking your Steam licenses…", 314.0F, 352.0F, 22.0F, kText);+ }+ else+ {+ const std::string bytes = byte_count(primary->completed_bytes) + " / " ++ byte_count(primary->total_bytes);+ ui::text(scene_, fonts_.regular, bytes, 282.0F, 352.0F, 22.0F, kText);+ ui::text(scene_, fonts_.regular, FormatDownloadRate(primary->state == JobState::Downloading ? primary->bytes_per_second : std::nullopt,+ primary->state == JobState::Downloading ? primary->eta_seconds : std::nullopt), 1038.0F,+ 352.0F, 22.0F, kSecondary, gfx::Align::right);+ }const bool card_focused = route_focus_ && state.navigation.focus_key == "job-" + primary->id;focus_ring(scene_, active_card, control_focus("job-" + primary->id, card_focused));if (card_focused)diff --git a/src/steam/backend/steam_install_runner.cpp b/src/steam/backend/steam_install_runner.cppindex db1c901..7153240 100644--- a/src/steam/backend/steam_install_runner.cpp+++ b/src/steam/backend/steam_install_runner.cpp@@ -71,7 +71,8 @@ const char* InstallFailureText(InstallError error) {InstallRunner::Result SteamInstallRunner::Install(const StoredSession& session, GameId id, const std::string& root,const std::atomic<bool>& cancel,- const std::function<void(std::uint64_t, std::uint64_t, std::uint64_t)>& progress) {+ const std::function<void(std::uint64_t, std::uint64_t, std::uint64_t)>& progress,+ const std::function<void(InstallStep)>& step) {Result result;current_app_.store(id);installer_.SetTuning(tuning_ ? tuning_() : DownloadTuning{});@@ -100,7 +101,9 @@ InstallRunner::Result SteamInstallRunner::Install(const StoredSession& session,target.app_id = id;target.install_root = root;std::string reason;- // Like the reference, only depots this account's licenses grant are installed.+ // Like the reference, only depots this account's licenses grant are installed. Accounts with+ // thousands of licenses take a minute here (issue #47), so the player sees this step.+ if (step) step(InstallStep::kCheckingLicenses);const auto entitlements = cm_.FetchAcquisitionDates(session, cancel);if (cancel.load()) {result.canceled = true;@@ -127,6 +130,7 @@ InstallRunner::Result SteamInstallRunner::Install(const StoredSession& session,for (const auto& selected : target.depots)if (selected.id == depot.id) ordered.push_back(selected);target.depots = ordered;+ if (step) step(InstallStep::kDownloading);const auto outcome = installer_.Run(session, target, cancel, [&](const InstallProgress& state) {if (progress) progress(state.download_done, state.download_total, state.held_bytes);});diff --git a/src/steam/backend/steam_install_runner.h b/src/steam/backend/steam_install_runner.hindex bf966e9..66b4fbd 100644--- a/src/steam/backend/steam_install_runner.h+++ b/src/steam/backend/steam_install_runner.h@@ -18,7 +18,8 @@ class SteamInstallRunner final : public InstallRunner {SteamInstallRunner(CmClient& cm, CdnClient& cdn) : cm_(cm), installer_(cm, cdn) {}Result Install(const StoredSession& session, GameId id, const std::string& root,const std::atomic<bool>& cancel,- const std::function<void(std::uint64_t, std::uint64_t, std::uint64_t)>& progress) override;+ const std::function<void(std::uint64_t, std::uint64_t, std::uint64_t)>& progress,+ const std::function<void(InstallStep)>& step) override;bool Remove(const std::string& root) override;void SetTuning(std::function<DownloadTuning()> tuning) { tuning_ = std::move(tuning); }// Optional sanitized log: the Steam app ID, step, error category and a short detail; neverdiff --git a/src/steam/install_service.cpp b/src/steam/install_service.cppindex 935dbe5..ac84a9a 100644--- a/src/steam/install_service.cpp+++ b/src/steam/install_service.cpp@@ -536,6 +536,8 @@ void InstallService::Run() {if (job.view.failure == kWaitingForSteam) job.view.failure.clear();job.rate.Reset();job.view.bytes_per_second.reset(); job.view.eta_seconds.reset();+ job.view.step = InstallStep::kStarting;+ job.view.step_since = std::chrono::steady_clock::now();next = job.view.id;next_root = RootOn(job.view.volume_id, job.view.id);active_ = next;@@ -579,6 +581,14 @@ void InstallService::Run() {job->view.held_bytes = held;++revision_; // progress only; the registry is unchanged}+ },+ [this, id = *next](InstallStep step) {+ std::lock_guard<std::mutex> lock(mutex_);+ if (auto* job = Find(id); job && job->view.step != step) {+ job->view.step = step;+ job->view.step_since = std::chrono::steady_clock::now();+ ++revision_;+ }});}diff --git a/src/steam/install_service.h b/src/steam/install_service.hindex bc76e70..c65c5d6 100644--- a/src/steam/install_service.h+++ b/src/steam/install_service.h@@ -5,6 +5,7 @@#include "steam/download_rate.h"#include <atomic>+#include <chrono>#include <condition_variable>#include <cstdint>#include <deque>@@ -28,6 +29,8 @@ struct InstallRequest {std::vector<InstallRequest> ParseInstallRequests(const std::string& text);enum class InstallJobState { kQueued, kRunning, kPaused, kFailed };+// What a running install is doing before its first progress report.+enum class InstallStep { kStarting, kCheckingLicenses, kDownloading };// A place games can be installed: a folder on one drive. `available` means the folder exists and// Playden can write to it now; installs recorded on a volume that is absent stay listed.@@ -48,6 +51,8 @@ struct InstallJobView {std::string volume_id;std::optional<std::uint64_t> bytes_per_second;std::optional<int> eta_seconds;+ InstallStep step = InstallStep::kStarting; // while running+ std::chrono::steady_clock::time_point step_since{};};struct InstalledGame {@@ -99,7 +104,8 @@ class InstallRunner {};virtual Result Install(const StoredSession& session, GameId id, const std::string& root,const std::atomic<bool>& cancel,- const std::function<void(std::uint64_t done, std::uint64_t total, std::uint64_t held)>& progress) = 0;+ const std::function<void(std::uint64_t done, std::uint64_t total, std::uint64_t held)>& progress,+ const std::function<void(InstallStep)>& step) = 0;virtual bool Remove(const std::string& root) = 0;};diff --git a/tests/install_service_test.cpp b/tests/install_service_test.cppindex b6b62c4..a1b7dbf 100644--- a/tests/install_service_test.cpp+++ b/tests/install_service_test.cpp@@ -42,6 +42,7 @@ class Sessions final : public SessionRepository {class Runner final : public InstallRunner {public:std::atomic<bool> block{false};+ std::atomic<bool> checking_licenses{false}; // holds the run in the license checkbool telemetry = false;std::uint64_t held = 0; // bytes the fake install reports on diskstd::atomic<int> installs{0};@@ -51,13 +52,22 @@ class Runner final : public InstallRunner {std::vector<std::string> removed;std::vector<std::string> install_roots;Result Install(const StoredSession&, GameId, const std::string& root, const std::atomic<bool>& cancel,- const std::function<void(std::uint64_t, std::uint64_t, std::uint64_t)>& progress) override {+ const std::function<void(std::uint64_t, std::uint64_t, std::uint64_t)>& progress,+ const std::function<void(InstallStep)>& step) override {++installs;{std::lock_guard<std::mutex> lock(mutex);install_roots.push_back(root);}if (unreachable > 0) { --unreachable; return {false, false, "Could not reach Steam.", 0, true}; }+ if (checking_licenses) {+ step(InstallStep::kCheckingLicenses);+ while (checking_licenses) {+ if (cancel) return {false, true, {}, 0};+ std::this_thread::sleep_for(1ms);+ }+ step(InstallStep::kDownloading);+ }if (telemetry) { progress(9000000000ull, 10000000000ull, held); progress(9100000000ull, 10000000000ull, held); }else progress(10, 100, held);while (block) {@@ -283,7 +293,28 @@ void UnreachableSteamWaits(const std::filesystem::path& root) {std::filesystem::remove_all(root);}+// A running job reports its step, so a slow license check can show before the download starts (issue #47).+void RunningJobReportsItsStep(const std::filesystem::path& root) {+ std::filesystem::remove_all(root);+ Sessions sessions;+ Runner runner;+ runner.checking_licenses = true;+ InstallService service(runner, sessions, root.string());+ const auto before = std::chrono::steady_clock::now();+ service.Install(70);+ AwaitAt(__LINE__, service, [](const InstallSnapshot& s) {+ const auto* job = JobOf(s, 70);+ return job && job->step == InstallStep::kCheckingLicenses;+ });+ const auto checking = service.Snapshot();+ CHECK(JobOf(checking, 70)->state == InstallJobState::kRunning && JobOf(checking, 70)->step_since >= before);+ runner.checking_licenses = false;+ AwaitAt(__LINE__, service, [](const InstallSnapshot& s) { return Installed(s, 70); });+ std::filesystem::remove_all(root);+}+int main() {+ RunningJobReportsItsStep(std::filesystem::temp_directory_path() / ("playden-step-service-" + std::to_string(::getpid())));SpaceAdmission(std::filesystem::temp_directory_path() / ("playden-space-service-" + std::to_string(::getpid())));LiveTelemetryDecaysWithoutCallbacks(std::filesystem::temp_directory_path() / ("playden-rate-service-" + std::to_string(::getpid())));UnreachableSteamWaits(std::filesystem::temp_directory_path() / ("playden-unreachable-service-" + std::to_string(::getpid())));