Play your Steam library's Windows games on a jailbroken PS5.
C++
Only offer the runtime kit when missing or older
Leonardo Lobatoaf5797c8e631
diff --git a/src/update/release.cpp b/src/update/release.cppindex ffb1b50..d298260 100644--- a/src/update/release.cpp+++ b/src/update/release.cpp@@ -17,6 +17,26 @@ bool SafePrefix(const std::string& prefix) {return !prefix.empty() && prefix.back() == '/' && SafeEntryName(prefix);}+// A number of min_digits to max_digits digits at the front of text, taken off it.+bool TakeNumber(std::string_view* text, std::size_t min_digits, std::size_t max_digits, unsigned* out) {+ std::size_t digits = 0;+ unsigned value = 0;+ while (digits < text->size() && (*text)[digits] >= '0' && (*text)[digits] <= '9') {+ value = value * 10 + static_cast<unsigned>((*text)[digits] - '0');+ if (++digits > max_digits) return false;+ }+ if (digits < min_digits) return false;+ text->remove_prefix(digits);+ *out = value;+ return true;+}++bool TakeChar(std::string_view* text, char c) {+ if (text->empty() || text->front() != c) return false;+ text->remove_prefix(1);+ return true;+}+// The summary shown on the console: plain text with line breaks, no control characters (GitHub's// "\r\n" would draw as "?"), at most one blank line in a row, and short enough for the dialog.std::string Summary(std::string_view text) {@@ -143,6 +163,29 @@ std::optional<std::vector<Release>> ParseReleases(std::string_view json, std::streturn releases;}+std::optional<KitVersion> ParseKitVersion(std::string_view text) {+ KitVersion version;+ if (!TakeNumber(&text, 1, 6, &version.generation) || !TakeChar(&text, '.') ||+ !TakeNumber(&text, 1, 6, &version.revision))+ return std::nullopt;+ if (text.empty()) return version;+ constexpr std::string_view kDevelopment = "-dev.";+ if (text.substr(0, kDevelopment.size()) != kDevelopment) return std::nullopt;+ text.remove_prefix(kDevelopment.size());+ version.development = true;+ if (!TakeNumber(&text, 8, 8, &version.date) || !TakeChar(&text, '.') || !TakeNumber(&text, 1, 6, &version.build) ||+ !text.empty())+ return std::nullopt;+ return version;+}++std::optional<KitVersion> KitVersionFromArtifact(std::string_view artifact) {+ constexpr std::string_view kKit = "-kit-";+ const auto at = artifact.find(kKit);+ if (at == std::string_view::npos) return std::nullopt;+ return ParseKitVersion(artifact.substr(at + kKit.size()));+}+std::optional<UpdateManifest> ParseUpdateManifest(std::string_view json, std::string* error) {auto refuse = [&](const char* reason) -> std::optional<UpdateManifest> {if (error) *error = reason;diff --git a/src/update/release.h b/src/update/release.hindex 6c59f52..c8ae36a 100644--- a/src/update/release.h+++ b/src/update/release.h@@ -44,6 +44,29 @@ struct KitPart {std::string prefix; // folder inside the zip ("playden-kit-0.12/hl2-fw1360-dev1/")};+// A kit's version: "<generation>.<revision>" ("0.12"), or a development build of one with "-dev.<YYYYMMDD>.<N>"+// ("0.13-dev.20261023.1"), which comes before that release and after the one before it.+struct KitVersion {+ unsigned generation = 0;+ unsigned revision = 0;+ bool development = false;+ unsigned date = 0;+ unsigned build = 0;++ friend bool operator<(const KitVersion& a, const KitVersion& b) {+ if (a.generation != b.generation) return a.generation < b.generation;+ if (a.revision != b.revision) return a.revision < b.revision;+ if (a.development != b.development) return a.development;+ if (a.date != b.date) return a.date < b.date;+ return a.build < b.build;+ }+};++// Anything else, such as the letters of kits before 0.10 ("h-r9"), is refused.+std::optional<KitVersion> ParseKitVersion(std::string_view text);+// The version in a kit's runtime artifact name, "<wine revision>-kit-<version>" ("f729534-kit-0.12").+std::optional<KitVersion> KitVersionFromArtifact(std::string_view artifact);+struct UpdateManifest {Version app_version;std::string title_id;diff --git a/src/update/update_service.cpp b/src/update/update_service.cppindex 5185f5e..07d6131 100644--- a/src/update/update_service.cpp+++ b/src/update/update_service.cpp@@ -44,6 +44,22 @@ std::string Quote(const std::string& text) {return out + "\"";}+// The version of the kit in kit_root, from its runtime's artifact name; none for a kit that names none+// (kits before 0.10) or a manifest that can't be read.+std::optional<KitVersion> InstalledKitVersion(const std::string& kit_root) {+ std::string text;+ if (!ReadSmallFile(kit_root + "/manifest.json", &text, 8 << 20)) return std::nullopt;+ steam::json::Limits limits;+ limits.max_bytes = 8 << 20;+ limits.max_values = 1 << 18;+ limits.max_string_bytes = 1 << 20;+ const auto manifest = steam::json::Parse(text, limits);+ const auto* runtime = manifest && manifest->is_object() ? manifest->Find("runtime") : nullptr;+ const auto* artifact = runtime && runtime->is_object() ? runtime->Find("artifact_revision") : nullptr;+ if (!artifact || !artifact->is_string()) return std::nullopt;+ return KitVersionFromArtifact(artifact->text());+}+std::string Gigabytes(std::uint64_t bytes) {char text[32];std::snprintf(text, sizeof text, "%.1f GB", static_cast<double>(bytes) / 1e9);@@ -812,6 +828,17 @@ void UpdateService::DoCheckKit() {if (!manifest) return FailKit("The kit information of " + own->tag + " is not valid.", error);if (manifest->kit.kit_id != config_.kit_id || manifest->kit.manifest_sha256 != config_.kit_manifest_sha256)return unavailable("release " + own->tag + " names kit " + manifest->kit.kit_id + " " + manifest->kit.manifest_sha256);+ // Only a missing or older kit is replaced: one as new or newer (a development kit, or the same version+ // built here) stays. A kit whose version can't be read is older than 0.10, or unreadable.+ if (installed_sha) {+ const auto installed_version = InstalledKitVersion(installed);+ const auto offered_version = ParseKitVersion(manifest->kit.revision);+ if (installed_version && offered_version && !(*installed_version < *offered_version)) {+ Log("kit check: the installed kit is not older than " + manifest->kit.revision + ", kept");+ Set([](UpdateSnapshot& s) { s.kit = {}; s.kit.phase = KitInstallPhase::kNotNeeded; });+ return;+ }+ }// A release whose kit did not change may leave the kit zip out: an older release has the same zip.const Release* source = own;const ReleaseAsset* zip = own->Find(manifest->kit.asset);diff --git a/tests/self_update_release_test.cpp b/tests/self_update_release_test.cppindex 40027cc..4f72142 100644--- a/tests/self_update_release_test.cpp+++ b/tests/self_update_release_test.cpp@@ -85,6 +85,24 @@ int main() {CHECK(IsSha256(kSha) && !IsSha256(std::string(63, 'a')) && !IsSha256(std::string(64, 'A')));CHECK(SafeFolderName("hl2-fw1360-dev1-r9") && !SafeFolderName("a/b") && !SafeFolderName("..") && !SafeFolderName(""));++ // Kit versions: releases "0.12", development builds "0.13-dev.20261023.1" before the release they lead to.+ const auto kit_version = [](const char* text) { return *ParseKitVersion(text); };+ CHECK(kit_version("0.12").generation == 0 && kit_version("0.12").revision == 12 && !kit_version("0.12").development);+ const auto dev = kit_version("0.13-dev.20261023.1");+ CHECK(dev.revision == 13 && dev.development && dev.date == 20261023 && dev.build == 1);+ for (const char* bad : {"", "r9", "h-r9", "0", "0.", ".12", "0.12.1", "0.12-dev", "0.12-dev.2026102.1",+ "0.12-dev.20261023", "0.12-dev.20261023.", "0.12-rc.20261023.1", "0.12 ", "1234567.0"})+ CHECK(!ParseKitVersion(bad));+ CHECK(kit_version("0.9") < kit_version("0.10") && kit_version("0.12") < kit_version("1.0"));+ CHECK(kit_version("0.12") < dev && dev < kit_version("0.13"));+ CHECK(kit_version("0.13-dev.20261023.1") < kit_version("0.13-dev.20261023.2"));+ CHECK(kit_version("0.13-dev.20261023.9") < kit_version("0.13-dev.20261024.1"));+ CHECK(!(kit_version("0.12") < kit_version("0.12")));+ CHECK(KitVersionFromArtifact("f729534-kit-0.12") && KitVersionFromArtifact("f729534-kit-0.12")->revision == 12);+ CHECK(KitVersionFromArtifact("f729534-kit-0.13-dev.20261023.1")->development);+ CHECK(!KitVersionFromArtifact("bceed2d-kit-h-r1") && !KitVersionFromArtifact("f729534") &&+ !KitVersionFromArtifact("0.12"));std::puts("ok");return 0;}diff --git a/tests/self_update_service_test.cpp b/tests/self_update_service_test.cppindex af6a9b6..35b315d 100644--- a/tests/self_update_service_test.cpp+++ b/tests/self_update_service_test.cpp@@ -103,14 +103,15 @@ std::string KitZip() {}void Publish(Server& server, const std::string& tag, const std::string& min_from = "0.2.0",- const std::string& content_version = "00.003.000", bool with_kit = true, bool with_digests = true) {+ const std::string& content_version = "00.003.000", bool with_kit = true, bool with_digests = true,+ const std::string& kit_revision = "r9") {const std::string version_text = tag.substr(1);const std::string app = AppZip(version_text, content_version);const std::string kit = KitZip();const std::string manifest =R"({"format":1,"app":{"version":")" + version_text + R"(","title_id":"FAKE77031","min_from":")" + min_from +R"(","asset":"playden-ps5-)" + version_text + R"(.zip","prefix":"playden-ps5-)" + version_text +- R"(/FAKE77031/"},"kit":{"kit_id":"kitid","revision":"r9","manifest_sha256":")" + kKitSha ++ R"(/FAKE77031/"},"kit":{"kit_id":"kitid","revision":")" + kit_revision + R"(","manifest_sha256":")" + kKitSha +R"(","asset":"playden-kit-h-r9.zip","prefix":"playden-kit-h-r9/kitid/"},"notes":"New things."})";server.files[kDownload + "playden-update.json"] = manifest;server.files[kDownload + "playden-ps5-" + version_text + ".zip"] = app;@@ -237,6 +238,32 @@ int main() {CHECK(Read(test.kits + "/.replaced-kitid-1000/manifest.json") == std::string(64, 'b'));service.Shutdown();}+ // Only a missing or older kit is replaced: a newer one (a development kit) or the same version built elsewhere+ // stays, and nothing is downloaded. An older one is offered as before.+ {+ const auto kit_manifest = [](const std::string& version) {+ return R"({"schema":"playden-prospero-kit/1","runtime":{"artifact_revision":"f729534-kit-)" + version + R"("}})";+ };+ for (const char* kept : {"0.13-dev.20261023.1", "0.12"}) {+ KitOnly test(std::string("kit-kept-") + kept, kit_manifest(kept));+ Publish(test.fixture.server, "v0.3.0", "0.2.0", "00.003.000", true, true, "0.12");+ test.fixture.server.releases = "[" + test.fixture.server.latest + "]";+ UpdateService service(test.Config());+ service.InstallKit(); // checks first+ Wait(service);+ CHECK(service.Snapshot().kit.phase == KitInstallPhase::kNotNeeded);+ CHECK(Read(test.kits + "/kitid/manifest.json") == kit_manifest(kept) && test.fixture.server.kit_downloads == 0);+ service.Shutdown();+ }+ KitOnly test("kit-older-version", kit_manifest("0.11"));+ Publish(test.fixture.server, "v0.3.0", "0.2.0", "00.003.000", true, true, "0.12");+ test.fixture.server.releases = "[" + test.fixture.server.latest + "]";+ UpdateService service(test.Config());+ service.CheckKit();+ Wait(service);+ CHECK(service.Snapshot().kit.phase == KitInstallPhase::kAvailable && service.Snapshot().kit.replaces);+ service.Shutdown();+ }// The running version's release left the kit zip out (its kit did not change): an older release has it.{KitOnly test("kit-older", "");