Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Show progress while Play installs a package

Leonardo Lobato41deaa8adc37
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index e5baab4..45480c5 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -1435,6 +1435,7 @@ void Controller::TickRuntime() {
// Play's own work before the launch (a game moved in 0.6 is republished first).
if (const auto progress = snapshot.play_progress.find(NumberIn(snapshot, id)); progress != snapshot.play_progress.end()) {
game.play_status = progress->second; game.can_play = false; game.can_prepare = false;
+ game.play_work = progress->second;
}
if (const auto pending = play_after_prepare_.find(id); pending != play_after_prepare_.end()) {
game.play_status = pending->second.words; game.can_prepare = false;
@@ -1446,7 +1447,8 @@ void Controller::TickRuntime() {
// A retry is in flight: do not republish its previous refusal as a new outcome.
if (play_queued_.count(id) || sync_before_play_.count(id)) game.play_detail.clear();
if (game.ready && cloud_busy_.count(id) && game.play_detail.empty()) game.play_detail = "Waiting for Cloud saves to finish.";
- if (snapshot.work_progress && (IsNumber(snapshot, snapshot.preparing_app, id) || IsNumber(snapshot, snapshot.removing_app, id)))
+ if (snapshot.work_progress && (IsNumber(snapshot, snapshot.preparing_app, id) || IsNumber(snapshot, snapshot.removing_app, id) ||
+ !game.play_work.empty()))
game.progress = snapshot.work_progress;
// Game settings and maintenance: the prepared title's state, the console's answer on
// whether it runs, and the newest maintenance outcome.
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 576aae1..b9edf19 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -984,7 +984,23 @@ std::string RuntimeHost::InstallScriptsStep(const GameFiles& files) {
const auto uses_physx = std::any_of(files.programs.begin(), files.programs.end(), [&files](const std::string& program) {
return rt::ProgramUsesPhysx(files.root.string(), program);
});
- const auto redist = rt::InstallRedistributables(files.root.string(), *install_dir, files.prefix, config_.unix_time(), uses_physx);
+ // A package being installed shows on the game's page as the rest of its setup does: words and a percentage.
+ const auto number = record.runtime_number;
+ bool shown = false;
+ const auto redist = rt::InstallRedistributables(
+ files.root.string(), *install_dir, files.prefix, config_.unix_time(), uses_physx,
+ [&](const std::string& name, std::size_t done, std::size_t total) {
+ if (!shown) {
+ shown = true;
+ const bool physx = rt::RedistIsPhysx(name);
+ Publish([&](RuntimeSnapshot& s) { s.play_progress[number] = physx ? kPlayInstallingPhysx : kPlayInstallingComponent; });
+ }
+ ReportWork(done, total);
+ });
+ if (shown) {
+ ClearWork();
+ Publish([&](RuntimeSnapshot& s) { s.play_progress.erase(number); });
+ }
if (redist.physx_missing) Log("redist app=" + std::to_string(record.runtime_number) + " physx needed, no package in the game folder");
// Names and reasons come from the game's files: one line each, whatever they hold.
const auto field = [](std::string text) {
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index f880d32..b3a604e 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -378,6 +378,8 @@ inline bool PrepareQueued(const RuntimeSnapshot& snapshot, std::uint32_t runtime
}
inline constexpr const char* kPlayUpdatingForLayout = "Updating this game for Playden 0.6…";
+inline constexpr const char* kPlayInstallingPhysx = "Installing PhysX…";
+inline constexpr const char* kPlayInstallingComponent = "Installing a component…";
inline constexpr const char* kPlayDownloadingMfc = "Downloading Microsoft's MFC for this game…";
inline constexpr const char* kPlayMfcNotDownloaded = "Microsoft's MFC could not be downloaded. Play again to retry.";
inline constexpr const char* kPlayMfcNotInstalled = "Microsoft's MFC could not be installed for this game.";
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index bf91b41..23bd0f7 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -6994,6 +6994,11 @@ void Simulation::rebuild_view() {
: status == "Registration pending" ? "Not confirmed" : status == "Removal incomplete" ? "Removing"
: status == "Preparing" && runtime && !runtime->detail.empty() ? runtime->detail : status;
setup.tone = tone;
+ // Play's own work before the game starts: what it is doing, not the state it leaves behind.
+ if (runtime && !runtime->play_work.empty()) {
+ setup.value = runtime->play_work.substr(0, runtime->play_work.rfind("…"));
+ setup.tone = "busy";
+ }
setup.enabled = false;
if (runtime && runtime->queued && runtime->uninstall_status.empty()) {
setup.value = ahead.empty() ? "Queued" : "Waiting for " + ahead;
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index d923f09..eac16ff 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -235,6 +235,7 @@ struct LiveRuntimeGame {
std::string uninstall_status; // e.g. "Syncing saves…", "Removing PS5 title…"; empty when idle
// How far the current copy or deletion is (0–1); absent when it cannot be measured.
std::optional<float> progress;
+ std::string play_work; // Play's own work before the launch, for Setup ("Installing PhysX…")
// Prepared and waiting for the PS5 to register its title, which it does once Playden
// quits: the game is ready to play from Home, and Play quits there.
bool awaiting_registration = false;
diff --git a/src/runtime/redist_install.cpp b/src/runtime/redist_install.cpp
index 0287bfb..0b4b98f 100644
--- a/src/runtime/redist_install.cpp
+++ b/src/runtime/redist_install.cpp
@@ -311,7 +311,7 @@ using CabinetSource = std::function<bool(const std::string& name, std::string* b
// Counts the files written in *files, or gives a reason in *reason.
bool InstallPlan(std::string_view package, const CabinetSource& beside, const std::filesystem::path& prefix,
const RedistEntry& entry, std::int64_t unix_time, const std::function<bool(const MsiFile&)>& keep,
- std::size_t* files, std::string* reason) {
+ std::size_t* files, std::string* reason, const std::function<void(std::size_t, std::size_t)>& progress = {}) {
MsiInstallPlan plan;
if (!ReadMsiPackage(package, &plan, reason)) return false;
if (plan.unsupported_files) {
@@ -334,6 +334,7 @@ bool InstallPlan(std::string_view package, const CabinetSource& beside, const st
}
std::set<const MsiFile*> delivered;
const auto drive = prefix / "drive_c";
+ if (progress) progress(0, plan.files.size());
for (std::size_t index = 0; index < plan.cabinets.size(); ++index) {
if (!used.count(index)) continue;
const auto& cabinet = plan.cabinets[index];
@@ -373,6 +374,7 @@ bool InstallPlan(std::string_view package, const CabinetSource& beside, const st
return false;
}
++*files;
+ if (progress) progress(*files, plan.files.size());
}
return true;
}, reason);
@@ -412,21 +414,22 @@ bool InstallPlan(std::string_view package, const CabinetSource& beside, const st
// package_path), its external cabinets beside that file.
bool InstallPackageBytes(std::string_view package, const std::filesystem::path& package_path,
const std::filesystem::path& prefix, const RedistEntry& entry, std::int64_t unix_time,
- std::size_t* files, std::string* reason) {
+ std::size_t* files, std::string* reason, const std::function<void(std::size_t, std::size_t)>& progress) {
const auto beside = [&](const std::string& name, std::string* bytes) {
return ReadFile(package_path.parent_path() / name, kMaxPackageBytes, bytes);
};
- return InstallPlan(package, beside, prefix, entry, unix_time, {}, files, reason);
+ return InstallPlan(package, beside, prefix, entry, unix_time, {}, files, reason, progress);
}
bool InstallPackage(const std::filesystem::path& package_path, const std::filesystem::path& prefix,
- const RedistEntry& entry, std::int64_t unix_time, std::size_t* files, std::string* reason) {
+ const RedistEntry& entry, std::int64_t unix_time, std::size_t* files, std::string* reason,
+ const std::function<void(std::size_t, std::size_t)>& progress) {
std::string package;
if (!ReadFile(package_path, kMaxPackageBytes, &package)) {
*reason = "the package could not be read";
return false;
}
- return InstallPackageBytes(package, package_path, prefix, entry, unix_time, files, reason);
+ return InstallPackageBytes(package, package_path, prefix, entry, unix_time, files, reason, progress);
}
// A package that reads as one and has files.
@@ -731,8 +734,11 @@ std::string ExtendPath(const std::string& current, const std::vector<std::string
return out;
}
+bool RedistIsPhysx(const std::string& name) { return Lower(name).find("physx") != std::string::npos; }
+
RedistInstallResult InstallRedistributables(const std::string& game_root, const std::string& install_dir,
- const std::string& prefix_dir, std::int64_t unix_time, bool find_physx) {
+ const std::string& prefix_dir, std::int64_t unix_time, bool find_physx,
+ const RedistProgress& progress) {
RedistInstallResult result;
std::vector<std::string> scripts;
{
@@ -759,6 +765,9 @@ RedistInstallResult InstallRedistributables(const std::string& game_root, const
return hash + '\n' + path.parent_path().string();
};
const auto run = [&](const std::string& script, const RedistEntry& entry) {
+ const auto files_done = [&](std::size_t done, std::size_t total) {
+ if (progress) progress(entry.name, done, total);
+ };
RedistOutcome outcome;
outcome.script = script;
outcome.name = entry.name;
@@ -787,7 +796,8 @@ RedistInstallResult InstallRedistributables(const std::string& game_root, const
outcome.detail = package + ": " + earlier->second;
} else {
std::string failure;
- if (!InstallPackageBytes(embedded, path, prefix, entry, unix_time, &outcome.files, &failure)) {
+ files_done(0, 1);
+ if (!InstallPackageBytes(embedded, path, prefix, entry, unix_time, &outcome.files, &failure, files_done)) {
outcome.result = "failed";
} else if (!RecordPackage(prefix, *hash, package)) {
outcome.result = "failed";
@@ -829,7 +839,7 @@ RedistInstallResult InstallRedistributables(const std::string& game_root, const
if (const auto earlier = failed.find(failure_key(*hash, path)); earlier != failed.end()) {
outcome.result = "failed";
failure = earlier->second;
- } else if (!InstallPackage(path, prefix, entry, unix_time, &outcome.files, &failure)) {
+ } else if (files_done(0, 1); !InstallPackage(path, prefix, entry, unix_time, &outcome.files, &failure, files_done)) {
outcome.result = "failed";
} else if (!RecordPackage(prefix, *hash, package)) {
outcome.result = "failed";
diff --git a/src/runtime/redist_install.h b/src/runtime/redist_install.h
index 97170a7..f5cf2fa 100644
--- a/src/runtime/redist_install.h
+++ b/src/runtime/redist_install.h
@@ -41,6 +41,13 @@ struct RedistInstallResult {
bool physx_missing = false; // find_physx, and the game folder has no PhysX package
};
+// Whether a redistributable's name (an install script's entry) is PhysX's.
+bool RedistIsPhysx(const std::string& name);
+
+// A package being installed: called as it starts (done 0, total 1, before its size is known), then with the files
+// written so far of its total, on the calling thread. name is the entry's, which comes from the game's files.
+using RedistProgress = std::function<void(const std::string& name, std::size_t done, std::size_t total)>;
+
// Finds install scripts at the top of game_root and in its redistributable folders
// (_CommonRedist, Redist, Support, __Installer…, up to four folders deep), and installs their
// Windows Installer packages into the stopped bottle at prefix_dir, including a package a setup
@@ -50,7 +57,8 @@ struct RedistInstallResult {
// With find_physx (the game's program uses PhysX, ProgramUsesPhysx) and no script that names PhysX, PhysX's
// packages in those folders are installed the same way, found by name: a game imported from a folder has no script.
RedistInstallResult InstallRedistributables(const std::string& game_root, const std::string& install_dir,
- const std::string& prefix_dir, std::int64_t unix_time, bool find_physx = false);
+ const std::string& prefix_dir, std::int64_t unix_time, bool find_physx = false,
+ const RedistProgress& progress = {});
// Microsoft's MFC library, which Wine doesn't provide, for the games that import it (runtime/game_probe.h
// FindMfcImports): Playden downloads Microsoft's Visual C++ 2015-2022 redistributable once per console, keeps the
diff --git a/tests/homebrew_library_graphical_test.cpp b/tests/homebrew_library_graphical_test.cpp
index 8718ab8..d42ac39 100644
--- a/tests/homebrew_library_graphical_test.cpp
+++ b/tests/homebrew_library_graphical_test.cpp
@@ -232,6 +232,11 @@ int main(int argc,char** argv) {
ready.can_play=false; ready.play_status="Starting…";
live.UpdateRuntime(RuntimeState::Ready, {ready});
capture_live("details-play-disabled.png");
+ {
+ LiveRuntimeGame installing=ready; installing.can_play=false; installing.play_status=installing.play_work="Installing PhysX…"; installing.progress=0.27F;
+ live.UpdateRuntime(RuntimeState::Ready, {installing});
+ capture_live("details-installing-physx.png");
+ }
{
LiveRuntimeGame copying; copying.game_id= SteamId(42); copying.status="Preparing"; copying.has_title=true;
copying.detail="Copying the Windows environment"; copying.progress=0.42F;
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index 8c08c3e..92c360e 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -2627,6 +2627,17 @@ void live_play_does_the_next_useful_thing() {
model.UpdateRuntime(RuntimeState::Ready, {preparing});
check(find_row(model, "details-play")->value.empty() && find_row(model, "details-setup")->value == preparing.detail,
"work without a step number is only named in Setup");
+ {
+ // Play installing a component first: the button counts, Setup says what it installs.
+ LiveRuntimeGame installing; installing.game_id = SteamId(42); installing.status = "Ready"; installing.ready = true;
+ installing.can_prepare = true; installing.play_status = installing.play_work = "Installing PhysX…";
+ installing.progress = 0.27F;
+ model.UpdateRuntime(RuntimeState::Ready, {installing});
+ const auto* play = find_row(model, "details-play");
+ check(play && !play->enabled && play->progress > 0.26F, "Play fills while it installs");
+ check(find_row(model, "details-setup")->value == "Installing PhysX" && find_row(model, "details-setup")->tone == "busy",
+ "Setup names what is being installed");
+ }
for (const auto& [runtime_state, status] : std::vector<std::pair<RuntimeState, std::string>>{
{RuntimeState::Checking, "Checking"}, {RuntimeState::Unavailable, "Unavailable"}}) {
LiveRuntimeGame transient; transient.game_id = SteamId(42); transient.status = status;
diff --git a/tests/runtime_redist_test.cpp b/tests/runtime_redist_test.cpp
index a3dce3d..03168ec 100644
--- a/tests/runtime_redist_test.cpp
+++ b/tests/runtime_redist_test.cpp
@@ -437,13 +437,26 @@ void TestFoundPhysx() {
// Needed: only PhysX's package, once.
prefix = fresh_prefix("needed");
- result = InstallRedistributables(game.string(), "Z:\\games\\1", prefix.string(), 1700000100, true);
+ std::vector<std::pair<std::size_t, std::size_t>> reported;
+ std::string reported_name;
+ result = InstallRedistributables(game.string(), "Z:\\games\\1", prefix.string(), 1700000100, true,
+ [&](const std::string& name, std::size_t done, std::size_t total) {
+ reported_name = name;
+ reported.emplace_back(done, total);
+ });
+ // It says it started before reading the package, then counts its files.
+ CHECK(reported_name == "PhysX" && reported.size() == 5);
+ CHECK(reported.front() == std::make_pair(std::size_t{0}, std::size_t{1}) &&
+ reported[1] == std::make_pair(std::size_t{0}, std::size_t{3}) && reported.back() == std::make_pair(std::size_t{3}, std::size_t{3}));
+ CHECK(RedistIsPhysx("PhysX") && RedistIsPhysx("PhysX Version") && !RedistIsPhysx("Sample"));
CHECK(result.outcomes.size() == 1 && result.outcomes[0].result == "installed" && result.outcomes[0].name == "PhysX" &&
result.outcomes[0].detail == "_Redist/Nvidia PhysX Legacy Driver/PhysX-9.13.0604-SystemSoftware-Legacy.msi");
CHECK(!result.physx_missing);
CHECK(ReadText(prefix / "drive_c/program files (x86)/Vendor Runtime/Common/Loader.dll") == "0123456789");
- result = InstallRedistributables(game.string(), "Z:\\games\\1", prefix.string(), 1700000200, true);
- CHECK(result.outcomes.size() == 1 && result.outcomes[0].result == "already");
+ reported.clear();
+ result = InstallRedistributables(game.string(), "Z:\\games\\1", prefix.string(), 1700000200, true,
+ [&](const std::string&, std::size_t done, std::size_t total) { reported.emplace_back(done, total); });
+ CHECK(result.outcomes.size() == 1 && result.outcomes[0].result == "already" && reported.empty());
// The game's files in one folder of what was imported: its redistributables are a level down.
const auto wrapped = base / "wrapped";