Skip to content

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

C++

Clear every completed download, not only those shown

Leonardo Lobatoa9d5f9282a1e
diff --git a/src/steam/install_service.cpp b/src/steam/install_service.cpp
index a606ef7..0998ee5 100644
--- a/src/steam/install_service.cpp
+++ b/src/steam/install_service.cpp
@@ -42,9 +42,11 @@ std::vector<InstallRequest> ParseInstallRequests(const std::string& text) {
return requests;
}
-std::vector<CompletedDownload> CompletedDownloads(const std::vector<InstalledGame>& installed,
- const std::vector<std::pair<GameId, std::int64_t>>& dismissed,
- std::int64_t now) {
+namespace {
+// Every install Completed would list, newest first, without the `kMaxCompleted` cap.
+std::vector<CompletedDownload> AllCompletedDownloads(const std::vector<InstalledGame>& installed,
+ const std::vector<std::pair<GameId, std::int64_t>>& dismissed,
+ std::int64_t now) {
std::vector<CompletedDownload> completed;
for (const auto& game : installed) {
if (game.finished_at <= 0 || game.finished_at > now || now - game.finished_at > kCompletedDays * 24 * 60 * 60) continue;
@@ -54,6 +56,14 @@ std::vector<CompletedDownload> CompletedDownloads(const std::vector<InstalledGam
std::stable_sort(completed.begin(), completed.end(), [](const CompletedDownload& left, const CompletedDownload& right) {
return left.finished_at > right.finished_at;
});
+ return completed;
+}
+} // namespace
+
+std::vector<CompletedDownload> CompletedDownloads(const std::vector<InstalledGame>& installed,
+ const std::vector<std::pair<GameId, std::int64_t>>& dismissed,
+ std::int64_t now) {
+ auto completed = AllCompletedDownloads(installed, dismissed, now);
if (completed.size() > kMaxCompleted) completed.resize(kMaxCompleted);
return completed;
}
@@ -323,7 +333,9 @@ void InstallService::DismissCompleted(GameId id) {
void InstallService::ClearCompleted() {
std::lock_guard<std::mutex> lock(mutex_);
- for (const auto& completed : CompletedDownloads(installed_, dismissed_, WallNow())) Dismiss(completed.id);
+ // Every finished download, not only the `kMaxCompleted` the list shows: the older ones would
+ // move up into the list.
+ for (const auto& completed : AllCompletedDownloads(installed_, dismissed_, WallNow())) Dismiss(completed.id);
SaveDismissed();
++revision_;
}
diff --git a/tests/install_service_test.cpp b/tests/install_service_test.cpp
index afead9a..5ce0b20 100644
--- a/tests/install_service_test.cpp
+++ b/tests/install_service_test.cpp
@@ -270,6 +270,23 @@ void CompletedDownloadsList(const std::filesystem::path& root) {
CHECK(text.find("71\t") == 0 && text.find("70\t") == std::string::npos);
}
std::filesystem::remove_all(root);
+
+ // Clear dismisses every finished download, not only the `kMaxCompleted` the list shows.
+ {
+ Runner runner;
+ InstallService service(runner, sessions, root.string());
+ const GameId count = kMaxCompleted + 3;
+ for (GameId id = 100; id < 100 + count; ++id) service.Install(id);
+ AwaitAt(__LINE__, service, [count](const InstallSnapshot& s) {
+ for (GameId id = 100; id < 100 + count; ++id)
+ if (!Installed(s, id)) return false;
+ return true;
+ });
+ CHECK(service.Snapshot().completed.size() == kMaxCompleted);
+ service.ClearCompleted();
+ CHECK(service.Snapshot().completed.empty());
+ }
+ std::filesystem::remove_all(root);
}
// A download that cannot reach Steam keeps its place and waits instead of failing.