Skip to content

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

C++

Show the exact download size of game updates

Leonardo Lobatob5af93c8cd76
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index a343aa7..fd1e6db 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -2263,7 +2263,7 @@ void Controller::TickAppDetails() {
}
model_.UpdateAppDetails(details.id, details.download_bytes, details.install_bytes, details.windows_installable,
details.languages, details.dlc_count, std::move(versions),
- {details.update.newer, details.update.new_dlc, details.update.download_bytes}, !check_waits);
+ {details.update.newer, details.update.new_dlc, 0, 0, details.update.target, false}, !check_waits);
if (details.launches_any_branch) launches_any_branch_.insert(details.id);
else launches_any_branch_.erase(details.id);
launch_options_[details.id] = details.launches;
@@ -2290,11 +2290,22 @@ void Controller::TickAppDetails() {
const bool signed_in = model_.state().account().authentication == AuthState::SignedIn;
for (const auto& check : model_.TakeSizeChecks()) {
auto* details = Details(check.id.store);
- if (signed_in && details == app_details_) details->Measure({check.id, check.branch, check.language}, generation);
- else model_.UpdateMeasuredSize(check, false, !signed_in, {});
- }
+ // Not queued: as a check that failed, asked again when the sheet opens next.
+ if (!signed_in || details != app_details_ || !details->Measure({check.id, check.branch, check.language}, generation))
+ model_.UpdateMeasuredSize(check, false, true, {});
+ }
+ // Updates' sizes: the files that change, from the new manifests and each install's tree.
+ if (signed_in)
+ for (const auto id : model_.TakeUpdateSizeChecks())
+ if (!app_details_->Measure({id, {}, {}, true}, generation)) model_.UpdateMeasuredUpdate(id, false, 0, 0, 0);
for (const auto& size : app_details_->PumpMeasured()) {
if (size.account_generation != generation) continue;
+ if (size.request.update) {
+ // Measured for a newer update than the one listed: Steam is asked about the game again.
+ if (model_.UpdateMeasuredUpdate(size.request.id, size.measured, size.target, size.download_bytes, size.staged_bytes))
+ app_details_->Refresh(size.request.id, generation);
+ continue;
+ }
model_.UpdateMeasuredSize({size.request.id, size.request.branch, size.request.language}, size.measured, size.failed,
{size.install_bytes, size.download_bytes});
}
diff --git a/src/homebrew/host.cpp b/src/homebrew/host.cpp
index b34063d..4fecc73 100644
--- a/src/homebrew/host.cpp
+++ b/src/homebrew/host.cpp
@@ -598,6 +598,13 @@ int main(int argc, char** argv) {
if (game.id == playden::GameId::Steam(app) && game.available) return game.record;
return std::nullopt;
});
+ details_source->SetInstallRoot([&installs](std::uint32_t app) -> std::optional<std::string> {
+ if (!installs) return std::nullopt;
+ const auto snapshot = installs->Snapshot();
+ for (const auto& game : snapshot.installed)
+ if (game.id == playden::GameId::Steam(app) && game.available) return game.root;
+ return std::nullopt;
+ });
details_sessions = std::make_unique<playden::LocalSessionRepository>(options->data_directory.string(), playden::LocalSessionRepository::DiagnosticReport{}, session_vault.get());
app_details = std::make_unique<playden::steam::AppDetailsService>(*details_source, *details_sessions);
install_cm = std::make_unique<playden::steam::CmClient>(PLAYDEN_HOMEBREW_CA_BUNDLE, *library_storage);
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index be8d7a8..f1a1124 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -771,6 +771,12 @@ int main() {
if (game.id == playden::GameId::Steam(app) && game.available) return game.record;
return std::nullopt;
});
+ details_source.SetInstallRoot([&installs](std::uint32_t app) -> std::optional<std::string> {
+ const auto snapshot = installs.Snapshot();
+ for (const auto& game : snapshot.installed)
+ if (game.id == playden::GameId::Steam(app) && game.available) return game.root;
+ return std::nullopt;
+ });
playden::steam::CmClient servers_cm(paths.trust_store, library_storage);
servers_cm.SetOwner("servers");
servers_cm.SetSharedSession(steam_cm);
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index 350e840..87d1200 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -1466,11 +1466,12 @@ std::vector<GameId> Simulation::manage_list(ManageTab tab) const {
std::uint64_t bytes = installation.installed_bytes;
// Move: imported games have their own Copy/Move into Playden.
if (tab == ManageTab::Move && id.store == Store::kLocal) continue;
- // Updates: installed Steam games whose update or new DLC Steam told of; their size is the download.
+ // Updates: installed Steam games whose update or new DLC Steam told of; their size is the download (an
+ // unknown one sorts last).
if (updates) {
const auto update = state_.update_check.games.find(id);
if (!id.steam_app() || update == state_.update_check.games.end() || !update->second.available()) continue;
- bytes = update->second.download_bytes;
+ bytes = update->second.sized ? update->second.download_bytes : 0;
}
const auto* game = find_game(state_, id);
entries.push_back({id, bytes, game ? game->last_played : std::nullopt,
@@ -1643,8 +1644,8 @@ void Simulation::ask_manage_uninstall() {
open_modal(std::move(confirmation));
}
-// Updates stage the changed files beside each game, so every drive needs room for its games' downloads.
-// Steam's estimate counts whole depots: it may ask for more room than the update uses, never less.
+// Updates stage the changed files beside each game, so every drive needs room for its games' changed files.
+// A game whose size isn't known yet adds nothing: its download checks the room itself.
Simulation::ManageUpdates Simulation::manage_updates() const {
ManageUpdates result;
const auto found = manage_tabs_.find(ManageTab::Updates);
@@ -1654,9 +1655,11 @@ Simulation::ManageUpdates Simulation::manage_updates() const {
if (!found->second.selected.contains(id) || !manage_blocker(ManageTab::Updates, id).empty()) continue;
const auto* installation = find_installation(state_, id);
const auto update = state_.update_check.games.find(id);
- const std::uint64_t bytes = update == state_.update_check.games.end() ? 0 : update->second.download_bytes;
+ const bool sized = update != state_.update_check.games.end() && update->second.sized;
+ const std::uint64_t bytes = sized ? update->second.staged_bytes : 0;
result.games.push_back(id);
- result.bytes += bytes;
+ result.bytes += sized ? update->second.download_bytes : 0;
+ if (!sized) ++result.unsized;
auto drive = std::find_if(needed.begin(), needed.end(), [&](const auto& entry) { return entry.first == installation->volume_id; });
if (drive == needed.end()) needed.emplace_back(installation->volume_id, bytes);
else drive->second += bytes;
@@ -1665,28 +1668,29 @@ Simulation::ManageUpdates Simulation::manage_updates() const {
for (const auto& volume : state_.volumes) {
const auto drive = std::find_if(needed.begin(), needed.end(), [&](const auto& entry) { return entry.first == volume.id; });
const auto free = drive == needed.end() ? std::nullopt : volume_free(volume);
- // Free space that can't be read is checked by the download itself.
+ // Free space that can't be read is checked by the download itself, which keeps the install margin free.
if (!free) continue;
result.free.emplace_back(volume.label, *free);
- if (drive->second > *free && result.short_drive.empty()) {
+ const auto room = drive->second > 0 ? drive->second + steam::kInstallSpaceMargin : 0;
+ if (room > *free && result.short_drive.empty()) {
result.short_drive = volume.label;
- result.short_bytes = drive->second - *free;
+ result.short_bytes = room - *free;
}
}
return result;
}
// The Updates tab's action: every checked game that can update now goes to the Queue in the list's order.
-// Steam's estimate counts whole depots, so a drive that looks short only warns: the player may go ahead.
+// A drive that looks short only warns (its free space may change before the downloads get there): the player
+// may go ahead.
void Simulation::queue_manage_updates(bool anyway) {
const auto plan = manage_updates();
if (plan.games.empty()) return;
if (!plan.short_drive.empty() && !anyway) {
pending_destructive_action_ = "manage-update-anyway";
ModalEntry warning{"confirmation", "Update anyway?", state_.navigation.focus_key, {"cancel", "confirm-destructive"}, 0, true};
- warning.body = "These updates may need " + format_bytes(plan.short_bytes) + " more on " + plan.short_drive +
- ". Steam's sizes count whole parts of each game, so an update usually downloads less. An update "
- "that runs out of room stops, and its game stays as it was.";
+ warning.body = "These updates need " + format_bytes(plan.short_bytes) + " more on " + plan.short_drive +
+ " for their changed files. An update that runs out of room stops, and its game stays as it was.";
open_modal(std::move(warning));
return;
}
@@ -1989,9 +1993,8 @@ void Simulation::build_manage_games_view() {
game && !game->title.empty() ? game->title : "Steam app " + ToKey(id), "manage-toggle-" + ToKey(id));
item.game_id = id;
item.selected = tab.selected.contains(id);
- const std::uint64_t size = update != check.games.end() ? update->second.download_bytes
- : installation ? installation->installed_bytes : 0;
- item.value = size > 0 ? format_bytes(size) : updates ? "Unknown" : std::string();
+ const std::uint64_t size = installation ? installation->installed_bytes : 0;
+ item.value = update != check.games.end() ? update_size_text(id) : size > 0 ? format_bytes(size) : std::string();
if (item.selected) bytes += size;
// The last-played column.
const auto runtime = state_.runtime_games.find(id);
@@ -2066,11 +2069,14 @@ void Simulation::build_manage_games_view() {
} else if (!updates) {
view_.footer = std::to_string(count) + " selected · frees " + format_bytes(bytes);
} else {
- view_.footer = std::to_string(count) + " selected · " + (bytes ? format_bytes(bytes) : std::string("Size unknown")) + " to download";
- // Each drive's free space, or the drive that may lack room for its games: Update warns when pressed.
+ // Each drive's free space, or the drive that lacks room for its games: Update warns when pressed.
const auto plan = manage_updates();
+ view_.footer = std::to_string(count) + " selected · ";
+ if (plan.unsized == 0) view_.footer += format_bytes(plan.bytes) + " to download";
+ else if (plan.bytes > 0) view_.footer += "at least " + format_bytes(plan.bytes) + " to download";
+ else view_.footer += plan.unsized == 1 ? "size not known yet" : "sizes not known yet";
if (!plan.short_drive.empty()) {
- view_.footer += " · may need " + format_bytes(plan.short_bytes) + " more on " + plan.short_drive;
+ view_.footer += " · needs " + format_bytes(plan.short_bytes) + " more on " + plan.short_drive;
} else {
std::string free_words;
for (const auto& [label, free] : plan.free)
@@ -3162,6 +3168,7 @@ void Simulation::ResetSizeChecks() {
size_checks_.clear();
size_checks_running_.clear();
size_checks_failed_.clear();
+ update_sizes_running_.clear();
rebuild_view();
}
@@ -3209,13 +3216,15 @@ Simulation::UpdateCheck Simulation::update_check(GameId id) const {
const auto* game = find_game(state_, id);
const auto* installation = find_installation(state_, id);
if (!game || !installation) { check.reason = "Not installed"; return check; }
- check.download_bytes = game->update.download_bytes;
+ if (const auto saved = state_.update_check.games.find(id); saved != state_.update_check.games.end() && saved->second.sized)
+ check.download_bytes = saved->second.download_bytes;
+ else if (game->update.sized)
+ check.download_bytes = game->update.download_bytes;
const auto* volume = find_volume(const_cast<State&>(state_), installation->volume_id);
check.volume_label = volume ? volume->label : std::string("its drive");
if (!installation->available || !volume || !volume->available) { check.reason = "Drive disconnected"; return check; }
if (!volume->writable) { check.reason = "Drive is read-only"; return check; }
- // Steam's estimate counts whole depots, not the changed files that download beside the game: it is
- // shown, never checked. The download checks the room its changed files need and fails as an install does.
+ // The download checks the room its changed files need and fails as an install does.
if (volume->capacity_known) {
const auto occupied = std::min(volume->capacity_bytes, volume->used_bytes + volume->reserved_bytes);
check.free_bytes = volume->capacity_bytes - occupied;
@@ -3260,6 +3269,14 @@ bool Simulation::UpdateAppDetails(GameId id, std::optional<std::uint64_t> downlo
std::erase_if(measured_sizes_, [id](const auto& entry) { return std::get<0>(entry.first) == id; });
const auto game = std::find_if(state_.games.begin(), state_.games.end(),
[id](const Game& candidate) { return candidate.id == id; });
+ // A size measured for the same update stays with it.
+ if (const auto saved = state_.update_check.games.find(id);
+ saved != state_.update_check.games.end() && saved->second.sized && !update.sized && update.target != 0 &&
+ saved->second.target == update.target) {
+ update.download_bytes = saved->second.download_bytes;
+ update.staged_bytes = saved->second.staged_bytes;
+ update.sized = true;
+ }
// An installed game's update, from its page or the check, is what the update list saves. Before the
// licenses are read every game answers "no update": that would empty the list.
if (updates_known) set_saved_update(id, update);
@@ -3877,7 +3894,8 @@ void Simulation::ApplyUpdateCheck(std::uint64_t account, std::optional<playden::
check.loaded = true;
if (saved) {
check.checked_at = saved->checked_at;
- for (const auto& [id, game] : saved->games) check.games[id] = {game.newer, game.new_dlc, game.download_bytes};
+ for (const auto& [id, game] : saved->games)
+ check.games[id] = {game.newer, game.new_dlc, game.download_bytes, game.staged_bytes, game.target, game.sized};
}
update_check_saved_revision_ = update_check_revision_;
// Pages opened before the file was read answered for now: they win.
@@ -3892,6 +3910,9 @@ void Simulation::ResetUpdateCheck() {
update_check_requested_ = false;
update_check_waiting_.reset();
update_check_early_.clear();
+ update_sizes_running_.clear();
+ update_sizes_ended_.clear();
+ update_sizes_newer_.clear();
update_check_saved_revision_ = update_check_revision_;
}
@@ -3903,7 +3924,7 @@ playden::SavedUpdateCheck Simulation::ExportUpdateCheck() const {
playden::SavedUpdateCheck saved;
saved.checked_at = state_.update_check.checked_at;
for (const auto& [id, update] : state_.update_check.games)
- saved.games[id] = {update.newer, update.new_dlc, update.download_bytes};
+ saved.games[id] = {update.newer, update.new_dlc, update.download_bytes, update.staged_bytes, update.target, update.sized};
return saved;
}
@@ -3965,16 +3986,84 @@ void Simulation::set_saved_update(GameId id, const GameUpdate& update) {
return;
}
auto& games = state_.update_check.games;
+ // Steam answered again: an update whose size couldn't be measured is asked again.
+ std::erase_if(update_sizes_ended_, [id](const auto& key) { return key.first == id; });
if (update.available()) {
const auto found = games.find(id);
- if (found != games.end() && found->second == update) return;
- games[id] = update;
+ auto kept = update;
+ // A size measured for the same update stays with it.
+ if (found != games.end() && found->second.sized && !kept.sized && kept.target != 0 && found->second.target == kept.target) {
+ kept.download_bytes = found->second.download_bytes;
+ kept.staged_bytes = found->second.staged_bytes;
+ kept.sized = true;
+ }
+ if (found != games.end() && found->second == kept) return;
+ games[id] = kept;
} else if (!games.erase(id)) {
return;
}
++update_check_revision_;
}
+std::vector<GameId> Simulation::TakeUpdateSizeChecks() {
+ std::vector<GameId> ids;
+ if (!live() || !state_.update_check.loaded) return ids;
+ for (const auto& [id, update] : state_.update_check.games) {
+ if (!update.available() || update.sized || update_sizes_running_.contains(id) ||
+ update_sizes_ended_.contains({id, update.target}) || !find_installation(state_, id))
+ continue;
+ update_sizes_running_[id] = update.target;
+ ids.push_back(id);
+ }
+ if (!ids.empty()) rebuild_view();
+ return ids;
+}
+
+bool Simulation::UpdateMeasuredUpdate(GameId id, bool measured, std::uint64_t target, std::uint64_t download_bytes,
+ std::uint64_t staged_bytes) {
+ const auto running = update_sizes_running_.find(id);
+ if (running == update_sizes_running_.end()) return false;
+ const auto asked = running->second;
+ update_sizes_running_.erase(running);
+ auto& games = state_.update_check.games;
+ const auto found = games.find(id);
+ // A saved update from before targets were kept (0) takes the size of what Steam has now.
+ const bool applies = found != games.end() && measured && target != 0 && (found->second.target == 0 || found->second.target == target);
+ if (!applies) {
+ update_sizes_ended_.insert({id, asked});
+ rebuild_view();
+ // Steam has a newer update than the one listed: its details list it, and its size is measured then.
+ return found != games.end() && measured && target != 0 && update_sizes_newer_.insert({id, target}).second;
+ }
+ auto& update = found->second;
+ update.target = target;
+ update.download_bytes = download_bytes;
+ update.staged_bytes = staged_bytes;
+ update.sized = true;
+ ++update_check_revision_;
+ const auto game = std::find_if(state_.games.begin(), state_.games.end(), [id](const Game& candidate) { return candidate.id == id; });
+ if (game != state_.games.end() && game->update.available() && (game->update.target == 0 || game->update.target == target)) {
+ game->update.target = target;
+ game->update.download_bytes = download_bytes;
+ game->update.staged_bytes = staged_bytes;
+ game->update.sized = true;
+ }
+ rebuild_view();
+ return false;
+}
+
+std::string Simulation::update_size_text(GameId id) const {
+ const auto found = state_.update_check.games.find(id);
+ if (found != state_.update_check.games.end() && found->second.sized) return format_bytes(found->second.download_bytes);
+ if (found == state_.update_check.games.end()) {
+ const auto* game = find_game(state_, id);
+ if (game && game->update.sized) return format_bytes(game->update.download_bytes);
+ }
+ const bool waiting = found != state_.update_check.games.end() && !update_sizes_ended_.contains({id, found->second.target}) &&
+ state_.account().authentication == AuthState::SignedIn;
+ return waiting ? "Checking size…" : "Size unknown";
+}
+
void Simulation::PreferencesSaveResult(std::uint64_t revision, playden::StorageError error) {
if (!live() || revision > preferences_revision_) return;
if (error == playden::StorageError::kNone) {
@@ -4582,7 +4671,7 @@ bool Simulation::scenario(const std::string& name) {
const auto& seed = seeds[index];
state_.installations.push_back({game.id, seed.volume, seed.bytes, true, true, true});
game.last_played = seed.played > 0 ? std::optional<std::int64_t>(seed.played) : std::nullopt;
- if (seed.download > 0) state_.update_check.games[game.id] = {seed.newer, seed.dlc, seed.download};
+ if (seed.download > 0) state_.update_check.games[game.id] = {seed.newer, seed.dlc, seed.download, seed.download, index + 1, true};
}
// The fourth game is running: it can't be uninstalled now.
LiveRuntimeGame running;
@@ -4770,7 +4859,8 @@ bool Simulation::scenario(const std::string& name) {
std::erase_if(state_.jobs, [id](const Job& job) { return job.game_id == id; });
if (auto* installation = find_installation(state_, id)) installation->runtime_ready = true;
if (auto* game = const_cast<Game*>(find_game(state_, id)))
- game->update = name == "dlc-available" ? GameUpdate{true, true, 312'000'000} : GameUpdate{true, false, 1'240'000'000};
+ game->update = name == "dlc-available" ? GameUpdate{true, true, 312'000'000, 330'000'000, 1, true}
+ : GameUpdate{true, false, 1'240'000'000, 1'500'000'000, 1, true};
state_.navigation.route = Route::Details;
state_.navigation.detail_origin = Route::Library;
state_.navigation.detail_id = id;
@@ -5233,7 +5323,7 @@ void Simulation::rebuild_view() {
view_.subtitle += "On " + check.volume_label + ". ";
if (check.free_bytes) view_.subtitle += format_bytes(*check.free_bytes) + " free. ";
view_.subtitle += check.download_bytes
- ? "Downloads up to " + format_bytes(check.download_bytes) + ", only the files that changed. "
+ ? "Downloads " + format_bytes(*check.download_bytes) + ", only the files that changed. "
: "Its size is checked when the download starts. ";
view_.subtitle += check.allowed ? std::string("You can play until the update puts its files in place.")
: check.reason + ".";
@@ -5394,7 +5484,7 @@ void Simulation::rebuild_view() {
}
if (modal.id == "update" && action_key == "update-confirm") {
const auto check = update_check(state_.navigation.detail_id.value_or(state_.navigation.selected_game_id));
- if (check.download_bytes) item.value = "Up to " + format_bytes(check.download_bytes);
+ if (check.download_bytes) item.value = format_bytes(*check.download_bytes);
item.subtitle = check.reason;
item.enabled = check.allowed;
}
@@ -6246,8 +6336,8 @@ void Simulation::rebuild_view() {
auto& button = row("details-update", RowKind::Action, dlc ? "DLC available" : "Update", "details-update");
button.game_id = game->id;
auto& note = row("details-update-note", RowKind::Status, dlc ? "DLC available" : "Update available", "");
- // Steam's size for the changed depots; only the files that changed download.
- if (game->update.download_bytes) note.value = "Up to " + format_bytes(game->update.download_bytes);
+ // What the changed files download, once measured.
+ note.value = update_size_text(game->id);
note.enabled = false;
};
if (!live()) {
@@ -6882,9 +6972,14 @@ void Simulation::rebuild_view() {
item.subtitle = "Steam didn't answer" + (when.empty() ? std::string() : " · last checked " + when);
} else if (!updates.empty()) {
std::uint64_t bytes = 0;
- for (const auto id : updates) bytes += check.games.at(id).download_bytes;
+ bool all_sized = true;
+ for (const auto id : updates) {
+ const auto& found = check.games.at(id);
+ bytes += found.sized ? found.download_bytes : 0;
+ all_sized = all_sized && found.sized;
+ }
item.value = std::to_string(updates.size()) + (updates.size() == 1 ? " update" : " updates") +
- (bytes > 0 ? " · " + format_bytes(bytes) : std::string());
+ (all_sized ? " · " + format_bytes(bytes) : std::string());
} else {
item.value = check.checked_at > 0 ? "Up to date" : "Not checked";
}
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index b6ad997..e2e89e9 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -509,7 +509,12 @@ struct SizeCheckRequest {
struct GameUpdate {
bool newer = false; // a newer version of the game's content
bool new_dlc = false; // DLC the account owns that the install doesn't hold
- std::uint64_t download_bytes = 0; // Steam's estimate for the changed content; 0 unknown
+ // Measured from the manifests against the install's files (`sized`): what the update downloads, and the
+ // changed files' bytes staged beside the game until they go in place.
+ std::uint64_t download_bytes = 0;
+ std::uint64_t staged_bytes = 0;
+ std::uint64_t target = 0; // the depots and manifests updated to (0 unknown): sizes hold for this one only
+ bool sized = false;
[[nodiscard]] bool available() const noexcept { return newer || new_dlc; }
bool operator==(const GameUpdate&) const = default;
};
@@ -896,6 +901,14 @@ public:
// stand (nothing to check, or the check failed; `failed` lets the sheet ask again when it opens next).
[[nodiscard]] std::vector<SizeCheckRequest> TakeSizeChecks();
void UpdateMeasuredSize(const SizeCheckRequest& request, bool measured, bool failed, MeasuredInstallSize size);
+ // Live mode: installed games whose update has no measured size yet, each asked once for what it updates to;
+ // and the answers. `target` is the selection measured: a size for another one than the saved update's is
+ // dropped. Not measured (the network, a full queue): the size stays unknown until Steam answers for the
+ // game again. True when Steam should be asked about the game again (a size for a newer update than the
+ // one listed), once per update measured.
+ [[nodiscard]] std::vector<GameId> TakeUpdateSizeChecks();
+ bool UpdateMeasuredUpdate(GameId id, bool measured, std::uint64_t target, std::uint64_t download_bytes,
+ std::uint64_t staged_bytes);
// The details service dropped what it was asked (another account, or the language changed): checks
// still waiting for an answer are asked again.
void ResetSizeChecks();
@@ -1289,6 +1302,11 @@ private:
bool update_check_requested_ = false;
std::optional<bool> update_check_waiting_; // asked (true: by the player) before the saved check was read
std::map<GameId, GameUpdate> update_check_early_; // results before the saved check was read
+ std::map<GameId, std::uint64_t> update_sizes_running_; // asked, with the target then saved
+ std::set<std::pair<GameId, std::uint64_t>> update_sizes_ended_; // answered without a size: not asked again
+ std::set<std::pair<GameId, std::uint64_t>> update_sizes_newer_; // measured targets Steam was asked about again
+ // An update's size as the screens say it: the download, "Checking size…" while it is measured, else "Size unknown".
+ [[nodiscard]] std::string update_size_text(GameId id) const;
// The screen opened (`forced` false: only a day after the last full check) or Check for updates.
void request_update_check(bool forced);
@@ -1410,7 +1428,8 @@ private:
// the first drive without room for its share (empty when they all fit or free space can't be read).
struct ManageUpdates {
std::vector<GameId> games;
- std::uint64_t bytes = 0;
+ std::uint64_t bytes = 0; // the sized games' downloads
+ std::size_t unsized = 0; // games whose size isn't known yet
std::vector<std::pair<std::string, std::uint64_t>> free; // each drive's label and free space
std::string short_drive;
std::uint64_t short_bytes = 0;
@@ -1511,7 +1530,7 @@ private:
bool allowed = false;
std::string volume_label;
std::optional<std::uint64_t> free_bytes;
- std::uint64_t download_bytes = 0; // 0 unknown
+ std::optional<std::uint64_t> download_bytes; // measured; none unknown
std::string reason; // short, for the confirm row: why not, or what pressing does
};
[[nodiscard]] UpdateCheck update_check(GameId id) const;
diff --git a/src/library/update_check.cpp b/src/library/update_check.cpp
index e99509a..6831c05 100644
--- a/src/library/update_check.cpp
+++ b/src/library/update_check.cpp
@@ -3,9 +3,11 @@
#include "library/store.h"
+#include <algorithm>
#include <limits>
#include <string>
#include <string_view>
+#include <vector>
namespace playden {
namespace {
@@ -13,7 +15,9 @@ namespace {
constexpr std::size_t kMaximumBytes = 1024 * 1024;
constexpr std::size_t kMaximumGames = 20000;
-std::string Path(std::uint64_t account) { return "updates-" + std::to_string(account) + ".v1"; }
+std::string Path(std::uint64_t account, int version = 2) {
+ return "updates-" + std::to_string(account) + ".v" + std::to_string(version);
+}
// Plain decimal, no sign or leading zero (but "0"); the console's libc has no stream parsing.
std::optional<std::uint64_t> Decimal(std::string_view text) {
@@ -31,7 +35,8 @@ std::optional<std::uint64_t> Decimal(std::string_view text) {
} // namespace
bool operator==(const SavedGameUpdate& left, const SavedGameUpdate& right) {
- return left.newer == right.newer && left.new_dlc == right.new_dlc && left.download_bytes == right.download_bytes;
+ return left.newer == right.newer && left.new_dlc == right.new_dlc && left.download_bytes == right.download_bytes &&
+ left.staged_bytes == right.staged_bytes && left.target == right.target && left.sized == right.sized;
}
bool operator==(const SavedUpdateCheck& left, const SavedUpdateCheck& right) {
return left.checked_at == right.checked_at && left.games == right.games;
@@ -41,11 +46,12 @@ Result<void> UpdateCheckStore::Save(std::uint64_t account, const SavedUpdateChec
if (!account) return Result<void>::Failure(StorageError::kInvalidPath, "Invalid update check account.");
if (check.checked_at < 0 || check.games.size() > kMaximumGames)
return Result<void>::Failure(StorageError::kInvalidData, "Update check cannot be saved.");
- std::string text = "version=1\nchecked_at=" + std::to_string(check.checked_at) + "\n";
+ std::string text = "version=2\nchecked_at=" + std::to_string(check.checked_at) + "\n";
for (const auto& [id, game] : check.games) {
if (!id.valid() || (!game.newer && !game.new_dlc)) continue; // only games with something to download
- text += ToKey(id) + " " + std::to_string((game.newer ? 1 : 0) | (game.new_dlc ? 2 : 0)) + " " +
- std::to_string(game.download_bytes) + "\n";
+ const int flags = (game.newer ? 1 : 0) | (game.new_dlc ? 2 : 0) | (game.sized ? 4 : 0);
+ text += ToKey(id) + " " + std::to_string(flags) + " " + std::to_string(game.sized ? game.download_bytes : 0) + " " +
+ std::to_string(game.sized ? game.staged_bytes : 0) + " " + std::to_string(game.target) + "\n";
}
const auto ready = storage_.EnsureRootDirectory();
if (!ready.ok()) return ready;
@@ -55,7 +61,12 @@ Result<void> UpdateCheckStore::Save(std::uint64_t account, const SavedUpdateChec
Result<std::optional<SavedUpdateCheck>> UpdateCheckStore::Load(std::uint64_t account) const {
using Loaded = Result<std::optional<SavedUpdateCheck>>;
if (!account) return Loaded::Failure(StorageError::kInvalidPath, "Invalid update check account.");
- const auto read = storage_.Read(Path(account), kMaximumBytes);
+ int version = 2;
+ auto read = storage_.Read(Path(account), kMaximumBytes);
+ if (!read.ok() && read.error() == StorageError::kNotFound) {
+ version = 1;
+ read = storage_.Read(Path(account, 1), kMaximumBytes);
+ }
if (!read.ok()) {
if (read.error() == StorageError::kNotFound) return Loaded::Success(std::nullopt);
return Loaded::Failure(read.error(), read.message());
@@ -71,7 +82,7 @@ Result<std::optional<SavedUpdateCheck>> UpdateCheckStore::Load(std::uint64_t acc
const std::string_view line(text.data() + start, end - start);
start = end + 1;
if (line_number++ == 0) {
- if (line != "version=1") return invalid();
+ if (line != (version == 1 ? "version=1" : "version=2")) return invalid();
continue;
}
if (line_number == 2) {
@@ -82,14 +93,30 @@ Result<std::optional<SavedUpdateCheck>> UpdateCheckStore::Load(std::uint64_t acc
check.checked_at = static_cast<std::int64_t>(*when);
continue;
}
- const auto first = line.find(' ');
- const auto second = first == std::string_view::npos ? first : line.find(' ', first + 1);
- if (second == std::string_view::npos) return invalid();
- const auto id = ParseKey(line.substr(0, first));
- const auto flags = Decimal(line.substr(first + 1, second - first - 1));
- const auto bytes = Decimal(line.substr(second + 1));
- if (!id || !flags || *flags < 1 || *flags > 3 || !bytes || check.games.size() >= kMaximumGames) return invalid();
- if (!check.games.emplace(*id, SavedGameUpdate{(*flags & 1) != 0, (*flags & 2) != 0, *bytes}).second) return invalid();
+ std::vector<std::string_view> fields;
+ for (std::size_t from = 0;;) {
+ const auto space = line.find(' ', from);
+ fields.push_back(line.substr(from, space == std::string_view::npos ? std::string_view::npos : space - from));
+ if (space == std::string_view::npos) break;
+ from = space + 1;
+ }
+ if (fields.size() != (version == 1 ? 3u : 5u)) return invalid();
+ const auto id = ParseKey(fields[0]);
+ const auto flags = Decimal(fields[1]);
+ std::optional<std::uint64_t> numbers[3];
+ for (std::size_t index = 2; index < fields.size(); ++index) numbers[index - 2] = Decimal(fields[index]);
+ const std::uint64_t most = version == 1 ? 3 : 7;
+ if (!id || !flags || (*flags & 3) == 0 || *flags > most || check.games.size() >= kMaximumGames) return invalid();
+ if (std::any_of(fields.begin() + 2, fields.end(), [](std::string_view field) { return !Decimal(field); })) return invalid();
+ // Version 1 held Steam's whole-depot estimate: only the flags are kept.
+ SavedGameUpdate game{(*flags & 1) != 0, (*flags & 2) != 0};
+ if (version == 2) {
+ game.sized = (*flags & 4) != 0;
+ game.download_bytes = game.sized ? *numbers[0] : 0;
+ game.staged_bytes = game.sized ? *numbers[1] : 0;
+ game.target = *numbers[2];
+ }
+ if (!check.games.emplace(*id, game).second) return invalid();
}
if (line_number < 2) return invalid();
return Loaded::Success(std::move(check));
diff --git a/src/library/update_check.h b/src/library/update_check.h
index f9a7e8d..6a777e3 100644
--- a/src/library/update_check.h
+++ b/src/library/update_check.h
@@ -10,12 +10,16 @@
namespace playden {
-// What a check found for one installed game: a newer version, DLC the install doesn't hold, and Steam's
-// estimate of the download.
+// What a check found for one installed game: a newer version, DLC the install doesn't hold, the selection
+// it updates to (0 unknown) and, once measured from the manifests (`sized`), what the update downloads and
+// stages beside the game.
struct SavedGameUpdate {
bool newer = false;
bool new_dlc = false;
std::uint64_t download_bytes = 0;
+ std::uint64_t staged_bytes = 0;
+ std::uint64_t target = 0;
+ bool sized = false;
};
bool operator==(const SavedGameUpdate& left, const SavedGameUpdate& right);
@@ -36,9 +40,10 @@ class UpdateCheckRepository {
virtual Result<void> Save(std::uint64_t account_id, const SavedUpdateCheck& check) const = 0;
};
-// `updates-<account>.v1` in the storage root, owner-only: "version=1", "checked_at=<seconds>", then one
-// "<game key> <flags> <download bytes>" line per game (flags: 1 newer, 2 new DLC). A damaged file fails
-// the load with kInvalidData.
+// `updates-<account>.v2` in the storage root, owner-only: "version=2", "checked_at=<seconds>", then one
+// "<game key> <flags> <download bytes> <staged bytes> <target>" line per game (flags: 1 newer, 2 new DLC,
+// 4 sized). Without it, `updates-<account>.v1` ("version=1", lines "<game key> <flags> <bytes>" with Steam's
+// whole-depot estimate) is read for its flags only. A damaged file fails the load with kInvalidData.
class UpdateCheckStore final : public UpdateCheckRepository {
public:
explicit UpdateCheckStore(Storage& storage) : storage_(storage) {}
diff --git a/src/steam/app_details_service.cpp b/src/steam/app_details_service.cpp
index d4abc3e..6f3d36d 100644
--- a/src/steam/app_details_service.cpp
+++ b/src/steam/app_details_service.cpp
@@ -84,16 +84,28 @@ InstalledCheck AppDetailsService::CheckProgress() {
return check_;
}
-void AppDetailsService::Measure(SizeRequest request, std::uint64_t account_generation) {
- if (!request.id.steam_app() || account_generation == 0) return;
+bool AppDetailsService::Measure(SizeRequest request, std::uint64_t account_generation) {
+ if (!request.id.steam_app() || account_generation == 0) return false;
std::lock_guard<std::mutex> lock(mutex_);
- if (stopping_) return;
+ if (stopping_) return false;
// Another account: what was asked for the previous one goes, as for Request.
if (account_generation != generation_) Reset(account_generation);
- if (measure_requested_.count(request) || measure_pending_.size() >= kMaxPending) return;
+ if (measure_requested_.count(request)) return true;
+ // Each kind has its own room: updates' sizes waiting never keep out the install sheet's.
+ const auto same_kind = std::count_if(measure_pending_.begin(), measure_pending_.end(),
+ [&](const SizeRequest& queued) { return queued.update == request.update; });
+ if (static_cast<std::size_t>(same_kind) >= kMaxPending) return false;
measure_requested_.insert(request);
- measure_pending_.push_back(std::move(request));
+ // The install sheet's choice is waited for on screen: ahead of the updates' sizes.
+ if (request.update) {
+ measure_pending_.push_back(std::move(request));
+ } else {
+ const auto first_update = std::find_if(measure_pending_.begin(), measure_pending_.end(),
+ [](const SizeRequest& queued) { return queued.update; });
+ measure_pending_.insert(first_update, std::move(request));
+ }
wake_.notify_all();
+ return true;
}
std::vector<MeasuredSize> AppDetailsService::PumpMeasured() {
diff --git a/src/steam/app_details_service.h b/src/steam/app_details_service.h
index 5717835..4eabfcd 100644
--- a/src/steam/app_details_service.h
+++ b/src/steam/app_details_service.h
@@ -68,13 +68,13 @@ struct AppDetails {
std::vector<AppVersion> versions;
// An installed game: what Steam has now against its install record (selected with the record's branch
// and language). `newer`: a depot has another manifest, is new, or left the selection; `new_dlc`: DLC
- // the account owns now that the install doesn't hold. `download_bytes` is Steam's estimate for the
- // changed and new depots (the update downloads only changed files). All false when the licenses or the
- // record's depots are unknown.
+ // the account owns now that the install doesn't hold. `target` names the selection updated to
+ // (UpdateTarget): its download size is measured from the manifests (a SizeRequest with `update`). All
+ // false when the licenses or the record's depots are unknown.
struct Update {
bool newer = false;
bool new_dlc = false;
- std::uint64_t download_bytes = 0;
+ std::uint64_t target = 0;
bool available() const { return newer || new_dlc; }
};
Update update;
@@ -95,16 +95,19 @@ struct InstalledCheck {
};
// One install choice whose exact size is asked for: a version (Steam branch, "public" by default) and a
-// content language.
+// content language. With `update`, an installed game's update instead: the version and language are its
+// install record's, and branch and language stay empty.
struct SizeRequest {
GameId id;
std::string branch;
std::string language;
+ bool update = false;
bool operator==(const SizeRequest& other) const {
- return id == other.id && branch == other.branch && language == other.language;
+ return id == other.id && branch == other.branch && language == other.language && update == other.update;
}
bool operator<(const SizeRequest& other) const {
if (!(id == other.id)) return id < other.id;
+ if (update != other.update) return other.update;
return branch != other.branch ? branch < other.branch : language < other.language;
}
};
@@ -119,6 +122,10 @@ struct MeasuredSize {
bool failed = false; // the check could not finish (no session, the network); asking again may work
std::uint64_t install_bytes = 0;
std::uint64_t download_bytes = 0;
+ // An update's: the changed files' bytes (staged beside the game), and the selection measured
+ // (AppDetails::Update::target); `measured` false when the install keeps no file tree or isn't there.
+ std::uint64_t staged_bytes = 0;
+ std::uint64_t target = 0;
};
// Runs on the service worker; may block on the network.
@@ -157,9 +164,10 @@ class AppDetailsService {
bool CheckInstalled(const std::vector<GameId>& ids, std::uint64_t account_generation);
InstalledCheck CheckProgress();
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 already
- // queued or being checked is not asked twice.
- void Measure(SizeRequest request, std::uint64_t account_generation);
+ // Asks for the exact size of one install choice, after the details already asked for, or of an update
+ // (`request.update`). Install choices go ahead of updates. A request already queued or being checked is not
+ // asked twice. False when it can't be queued (stopping, or kMaxPending of its kind already wait).
+ bool Measure(SizeRequest request, std::uint64_t account_generation);
std::vector<MeasuredSize> PumpMeasured();
void Shutdown();
diff --git a/src/steam/backend/cm_app_details.cpp b/src/steam/backend/cm_app_details.cpp
index fc70819..e20b2af 100644
--- a/src/steam/backend/cm_app_details.cpp
+++ b/src/steam/backend/cm_app_details.cpp
@@ -13,7 +13,6 @@ AppDetails::Update CompareWithRecord(std::uint32_t id, const std::vector<DepotIn
if (record.depots.empty()) return update; // an imported copy, or a record that names no depots
std::set<std::uint32_t> owners{id};
for (const auto& depot : record.depots) owners.insert(depot.owner == 0 ? id : depot.owner);
- std::vector<DepotInfo> download;
for (const auto& depot : selected) {
const auto recorded = std::find_if(record.depots.begin(), record.depots.end(),
[&](const installs::RecordedDepot& entry) { return entry.id == depot.id; });
@@ -25,10 +24,8 @@ AppDetails::Update CompareWithRecord(std::uint32_t id, const std::vector<DepotIn
const auto owner = depot.owner_app == 0 ? id : depot.owner_app;
if (owner != id && !owners.count(owner)) update.new_dlc = true;
else update.newer = true;
- download.push_back(depot);
} else if (depot.manifest_gid.value_or(0) != recorded->gid) {
update.newer = true;
- download.push_back(depot);
}
}
for (const auto& entry : record.depots) {
@@ -37,12 +34,38 @@ AppDetails::Update CompareWithRecord(std::uint32_t id, const std::vector<DepotIn
if (std::none_of(selected.begin(), selected.end(), [&](const DepotInfo& depot) { return depot.id == entry.id; }))
update.newer = true;
}
- std::uint64_t install = 0;
- DepotBytes(download, &install, &update.download_bytes);
- if (update.download_bytes == 0) update.download_bytes = install;
+ if (update.available()) update.target = UpdateTarget(selected);
return update;
}
+std::uint64_t UpdateTarget(const std::vector<DepotInfo>& selected) {
+ // FNV-1a over each depot's ID and manifest.
+ std::uint64_t hash = 14695981039346656037ull;
+ const auto mix = [&hash](std::uint64_t value) {
+ for (int byte = 0; byte < 8; ++byte, value >>= 8) hash = (hash ^ (value & 0xff)) * 1099511628211ull;
+ };
+ for (const auto& depot : selected) {
+ mix(depot.id);
+ mix(depot.manifest_gid.value_or(0));
+ }
+ return hash == 0 ? 1 : hash;
+}
+
+std::vector<DepotInfo> DepotsToUpdate(std::uint32_t id, const std::string& buffer,
+ const std::optional<LicensedDepots::Grant>& licensed,
+ const installs::InstalledRecord& record, const std::vector<AppInfo>& dlc_apps) {
+ const auto app = ParseAppInfo(id, buffer);
+ if (!app || !licensed) return {};
+ DepotSelection selection;
+ if (!record.language.empty()) selection.language = record.language;
+ if (!record.branch.empty()) selection.branch = record.branch;
+ std::set<std::uint32_t> apps{id};
+ apps.insert(licensed->apps.begin(), licensed->apps.end());
+ SelectionResult selected;
+ if (!SelectDepots(*app, dlc_apps, apps, licensed->depots, selection, &selected)) return {};
+ return selected.depots;
+}
+
AppDetails DetailsFromAppInfo(std::uint32_t id, const std::string& buffer,
const std::optional<LicensedDepots::Grant>& licensed,
std::string_view language,
@@ -211,6 +234,7 @@ MeasuredSize CmAppDetailsSource::Measure(const StoredSession& session, const Siz
MeasuredSize result{request};
const auto app = request.id.steam_app();
if (!measurer_ || !measure_client_ || !app) return result;
+ if (request.update) return MeasureUpdate(session, request, cancel);
const auto started = std::chrono::steady_clock::now();
const auto language = !request.language.empty() ? request.language
: language_ ? language_() : std::string(kDefaultContentLanguage);
@@ -281,4 +305,88 @@ MeasuredSize CmAppDetailsSource::Measure(const StoredSession& session, const Siz
return result;
}
+MeasuredSize CmAppDetailsSource::MeasureUpdate(const StoredSession& session, const SizeRequest& request,
+ const std::atomic<bool>& cancel) {
+ MeasuredSize result{request};
+ const auto app = *request.id.steam_app();
+ const auto started = std::chrono::steady_clock::now();
+ std::size_t depot_count = 0;
+ const auto log = [&](const char* outcome, const std::string& extra) {
+ if (!log_) return;
+ const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - started).count();
+ std::string detail = "update depots=" + std::to_string(depot_count);
+ if (result.measured)
+ detail += " download=" + std::to_string(result.download_bytes) + " staged=" + std::to_string(result.staged_bytes);
+ if (!extra.empty()) detail += " " + extra;
+ log_(app, "size", outcome, detail + " ms=" + std::to_string(ms));
+ };
+ const auto record = installed_ ? installed_(app) : std::nullopt;
+ const auto root = install_root_ ? install_root_(app) : std::nullopt;
+ if (!record || record->depots.empty() || !root) {
+ log("skipped", "why=not-installed");
+ return result;
+ }
+ const auto fetched = measure_client_->FetchAppInfo(session, {app}, cancel);
+ if (!fetched.ok()) {
+ result.failed = true;
+ log("failed", "why=appinfo");
+ return result;
+ }
+ const auto buffer = fetched.buffers.find(app);
+ if (buffer == fetched.buffers.end()) {
+ log("failed", "why=no-appinfo");
+ return result;
+ }
+ const auto dlc_apps = FetchDlcApps(*measure_client_, session, app, buffer->second, cancel);
+ if (cancel.load()) {
+ result.failed = true;
+ log("failed", "why=canceled");
+ return result;
+ }
+ const auto depots = DepotsToUpdate(app, buffer->second, licensed_ ? licensed_->Get(session.steam_id) : std::nullopt,
+ *record, dlc_apps);
+ depot_count = depots.size();
+ if (depots.empty()) {
+ log("skipped", "why=no-selection");
+ return result;
+ }
+ result.target = UpdateTarget(depots);
+ std::string key = std::to_string(session.steam_id) + " " + *root;
+ for (const auto& depot : record->depots) key += " " + std::to_string(depot.id) + ":" + std::to_string(depot.gid);
+ key += " >";
+ for (const auto& depot : depots) key += " " + std::to_string(depot.id) + ":" + std::to_string(depot.manifest_gid.value_or(0));
+ if (const auto known = measured_updates_.find(key); known != measured_updates_.end()) {
+ result.measured = true;
+ result.download_bytes = known->second.first;
+ result.staged_bytes = known->second.second;
+ log("cached", {});
+ return result;
+ }
+ const auto branch = record->branch.empty() ? std::string("public") : record->branch;
+ // Without the install's tree its record's manifests say what it holds: the recorded depots Steam still selects,
+ // asked for as the new ones are.
+ std::vector<DepotInfo> installed;
+ for (const auto& depot : depots) {
+ const auto recorded = std::find_if(record->depots.begin(), record->depots.end(),
+ [&](const installs::RecordedDepot& entry) { return entry.id == depot.id; });
+ if (recorded == record->depots.end() || recorded->gid == 0) continue;
+ installed.push_back(depot);
+ installed.back().manifest_gid = recorded->gid;
+ }
+ const auto measure = measurer_->MeasureUpdate(session, app, depots, branch, *root, cancel, installed);
+ if (measure.error != InstallError::kNone) {
+ result.failed = measure.error == InstallError::kNetwork || measure.error == InstallError::kCanceled ||
+ measure.error == InstallError::kNoSession;
+ log("failed", std::string("why=") + InstallErrorName(measure.error) + (measure.detail.empty() ? "" : " (" + measure.detail + ")"));
+ return result;
+ }
+ if (!measure.partial) measured_updates_[key] = {measure.download_bytes, measure.staged_bytes};
+ result.measured = true;
+ result.download_bytes = measure.download_bytes;
+ result.staged_bytes = measure.staged_bytes;
+ result.install_bytes = measure.install_bytes;
+ log("fetched", measure.partial ? "partial=1" : "");
+ return result;
+}
+
} // namespace playden::steam
diff --git a/src/steam/backend/cm_app_details.h b/src/steam/backend/cm_app_details.h
index 9ce88e7..32a5d45 100644
--- a/src/steam/backend/cm_app_details.h
+++ b/src/steam/backend/cm_app_details.h
@@ -31,6 +31,8 @@ class CmAppDetailsSource final : public AppDetailsSource {
void SetInstalled(std::function<std::optional<installs::InstalledRecord>(std::uint32_t app)> installed) {
installed_ = std::move(installed);
}
+ // An installed game's folder, for an update's size (its tree says which files change). Called on the size worker.
+ void SetInstallRoot(std::function<std::optional<std::string>(std::uint32_t app)> root) { install_root_ = std::move(root); }
// What measures an install choice from its manifests (MeasuredSize), and the connection its size checks read
// appinfo on: Measure runs on its own worker beside Fetch, so not the details one. Without them Steam's figures
// stand.
@@ -51,6 +53,7 @@ class CmAppDetailsSource final : public AppDetailsSource {
const std::atomic<bool>& cancel) override;
private:
+ MeasuredSize MeasureUpdate(const StoredSession& session, const SizeRequest& request, const std::atomic<bool>& cancel);
// The game's DLC apps' appinfo (a batch Steam doesn't answer is left out).
std::vector<AppInfo> FetchDlcApps(CmClient& client, const StoredSession& session, std::uint32_t id,
const std::string& buffer, const std::atomic<bool>& cancel);
@@ -58,11 +61,15 @@ class CmAppDetailsSource final : public AppDetailsSource {
const LicensedDepots* licensed_ = nullptr;
std::function<std::string()> language_;
std::function<std::optional<installs::InstalledRecord>(std::uint32_t)> installed_;
+ std::function<std::optional<std::string>(std::uint32_t)> install_root_;
DepotInstaller* measurer_ = nullptr;
CmClient* measure_client_ = nullptr;
std::function<void(std::uint32_t, const char*, const char*, const std::string&)> log_;
// Measured sizes (the size worker's only) by the depots and manifests measured: a manifest never changes, so neither does its size.
std::map<std::string, std::pair<std::uint64_t, std::uint64_t>> measured_;
+ // Updates' download and staged bytes, by the install's folder, the record's manifests and the new ones: the
+ // tree changes only with the record.
+ std::map<std::string, std::pair<std::uint64_t, std::uint64_t>> measured_updates_;
};
// The depots an install of `branch` in `language` selects, as DetailsFromAppInfo selects them, when their
@@ -84,6 +91,16 @@ AppDetails DetailsFromAppInfo(std::uint32_t id, const std::string& buffer,
const std::optional<installs::InstalledRecord>& installed = std::nullopt,
const std::vector<AppInfo>& dlc_apps = {});
+// The selection an update installs (depots and manifests, in order), as a number: an update's size is measured
+// for one. Never 0.
+std::uint64_t UpdateTarget(const std::vector<DepotInfo>& selected);
+
+// The depots an update of `record` selects, as DetailsFromAppInfo compares them: the record's branch and language,
+// with the licenses. Empty without licenses or when they grant nothing.
+std::vector<DepotInfo> DepotsToUpdate(std::uint32_t id, const std::string& buffer,
+ const std::optional<LicensedDepots::Grant>& licensed,
+ const installs::InstalledRecord& record, const std::vector<AppInfo>& dlc_apps);
+
// What `selected` (as an install of the record's branch and language selects now) changes against
// `record`. Recorded depots listed by an app whose appinfo is not in `listed` are not compared: they
// can't have left. Nothing for a record without depots.
diff --git a/src/steam/backend/depot_installer.cpp b/src/steam/backend/depot_installer.cpp
index dc878d1..661c9c7 100644
--- a/src/steam/backend/depot_installer.cpp
+++ b/src/steam/backend/depot_installer.cpp
@@ -343,6 +343,17 @@ std::optional<std::map<std::string, TreeFile>> ReadFileTree(const std::string& p
return tree;
}
+// An update leaves a file alone when the install's tree has the same path with the same SHA-1 and size, and
+// the file on disk still has that size.
+bool UnchangedInTree(const std::map<std::string, TreeFile>& tree, const std::string& key, const ManifestFile& file,
+ const std::string& install_root) {
+ const auto found = tree.find(key);
+ struct stat info {};
+ return found != tree.end() && found->second.path == file.path && found->second.size == file.size &&
+ found->second.sha == Hex(file.sha_content) && lstat((install_root + "/" + file.path).c_str(), &info) == 0 &&
+ S_ISREG(info.st_mode) && static_cast<std::uint64_t>(info.st_size) == file.size;
+}
+
// Whether the file at `path` is a regular file of `size` bytes whose SHA-1 is `sha` (read through a
// heap buffer; worker stacks are small). An empty file needs no hash.
bool SameContent(const std::string& path, std::uint64_t size, const std::array<std::uint8_t, 20>& sha,
@@ -638,14 +649,14 @@ DepotInstaller::DepotInstaller(InstallerHooks hooks) : hooks_(std::move(hooks))
if (!hooks_.free_bytes) hooks_.free_bytes = &DefaultFreeBytes;
}
-InstallMeasure DepotInstaller::Measure(const StoredSession& session, std::uint32_t app_id,
- const std::vector<DepotInfo>& depots, const std::string& branch,
- const std::atomic<bool>& cancel) {
- InstallMeasure measure;
- const auto fail = [&measure](InstallError error, std::string detail) {
- measure.error = error;
- measure.detail = std::move(detail);
- return measure;
+std::optional<DepotMerge> DepotInstaller::MergedManifests(const StoredSession& session, std::uint32_t app_id,
+ const std::vector<DepotInfo>& depots, const std::string& branch,
+ const std::atomic<bool>& cancel,
+ std::vector<DepotManifest>* manifests, InstallMeasure* measure) {
+ const auto fail = [measure](InstallError error, std::string detail) -> std::optional<DepotMerge> {
+ measure->error = error;
+ measure->detail = std::move(detail);
+ return std::nullopt;
};
if (app_id == 0 || depots.empty()) return fail(InstallError::kProtocol, "nothing to measure");
std::vector<DepotRequest> requests;
@@ -656,19 +667,19 @@ InstallMeasure DepotInstaller::Measure(const StoredSession& session, std::uint32
const auto access = hooks_.access(session, app_id, requests, cancel);
if (!access.ok()) return fail(FromCm(access.error), access.detail.empty() ? "depot access failed" : access.detail);
if (access.grants.empty()) return fail(InstallError::kRejected, "no depot granted");
- measure.partial = !access.skipped.empty();
+ measure->partial = !access.skipped.empty();
std::vector<ContentServer> servers;
const auto listed = hooks_.servers(session.cell_id.value_or(0), cancel, &servers);
if (listed == CdnError::kCanceled) return fail(InstallError::kCanceled, "canceled");
if (listed != CdnError::kNone || servers.empty()) return fail(InstallError::kNetwork, "no content servers");
// As Run: another server after a failure or a manifest that doesn't parse, with a pause between.
- std::vector<DepotManifest> manifests(access.grants.size());
+ manifests->assign(access.grants.size(), {});
for (std::size_t index = 0; index < access.grants.size(); ++index) {
InstallError fetched = InstallError::kNetwork;
bool network_failed = false;
const std::size_t attempts = std::min<std::size_t>(std::max<std::size_t>(servers.size() * 2, 4), 6);
for (std::size_t attempt = 0; attempt < attempts; ++attempt) {
- fetched = hooks_.manifest(servers[attempt % servers.size()], access.grants[index], cancel, &manifests[index]);
+ fetched = hooks_.manifest(servers[attempt % servers.size()], access.grants[index], cancel, &(*manifests)[index]);
if (fetched != InstallError::kNetwork && fetched != InstallError::kCorrupt) break;
network_failed = network_failed || fetched == InstallError::kNetwork;
if (hooks_.pause && attempt + 1 < attempts) hooks_.pause(1000 << std::min<std::size_t>(attempt, 3), cancel);
@@ -678,11 +689,61 @@ InstallMeasure DepotInstaller::Measure(const StoredSession& session, std::uint32
if (fetched == InstallError::kCorrupt && network_failed) fetched = InstallError::kNetwork;
if (fetched != InstallError::kNone) return fail(fetched, "manifest unavailable");
}
- const auto merged = MergeDepotManifests(manifests);
+ auto merged = MergeDepotManifests(*manifests);
if (!merged.conflict.empty()) return fail(InstallError::kCorrupt, "conflicting depots");
+ return merged;
+}
+
+InstallMeasure DepotInstaller::Measure(const StoredSession& session, std::uint32_t app_id,
+ const std::vector<DepotInfo>& depots, const std::string& branch,
+ const std::atomic<bool>& cancel) {
+ InstallMeasure measure;
+ std::vector<DepotManifest> manifests;
+ const auto merged = MergedManifests(session, app_id, depots, branch, cancel, &manifests, &measure);
+ if (!merged) return measure;
+ measure.error = InstallError::kNone;
+ measure.install_bytes = merged->install_bytes;
+ measure.download_bytes = merged->download_bytes;
+ return measure;
+}
+
+InstallMeasure DepotInstaller::MeasureUpdate(const StoredSession& session, std::uint32_t app_id,
+ const std::vector<DepotInfo>& depots, const std::string& branch,
+ const std::string& install_root, const std::atomic<bool>& cancel,
+ const std::vector<DepotInfo>& installed) {
+ InstallMeasure measure;
+ auto previous = ReadFileTree(install_root + "/" + kFileTree);
+ if (!previous && installed.empty()) {
+ measure.detail = "no file tree";
+ return measure;
+ }
+ if (!previous) {
+ // The installed version's files, from its manifests.
+ std::vector<DepotManifest> old_manifests;
+ InstallMeasure old_measure;
+ const auto old = MergedManifests(session, app_id, installed, branch, cancel, &old_manifests, &old_measure);
+ if (!old) {
+ measure.error = old_measure.error;
+ measure.detail = "installed " + old_measure.detail;
+ return measure;
+ }
+ previous.emplace();
+ for (const auto& [key, placement] : old->placements) {
+ const auto& file = *placement.file;
+ if (!file.is_directory() && !file.is_symlink()) (*previous)[key] = {Hex(file.sha_content), file.size, file.path};
+ }
+ }
+ std::vector<DepotManifest> manifests;
+ const auto merged = MergedManifests(session, app_id, depots, branch, cancel, &manifests, &measure);
+ if (!merged) return measure;
+ for (const auto& [key, placement] : merged->placements) {
+ const auto& file = *placement.file;
+ if (file.is_directory() || file.is_symlink() || UnchangedInTree(*previous, key, file, install_root)) continue;
+ measure.staged_bytes += file.size;
+ for (const auto& chunk : file.chunks) measure.download_bytes += chunk.compressed_size;
+ }
measure.error = InstallError::kNone;
- measure.install_bytes = merged.install_bytes;
- measure.download_bytes = merged.download_bytes;
+ measure.install_bytes = merged->install_bytes;
return measure;
}
@@ -913,16 +974,8 @@ InstallOutcome DepotInstaller::Run(const StoredSession& session, const InstallTa
const auto& file = *placement.file;
if (file.is_directory() || file.is_symlink()) continue;
const auto path = target.install_root + "/" + file.path;
- bool same = false;
- if (previous) {
- const auto found = previous->find(key);
- struct stat info {};
- same = found != previous->end() && found->second.path == file.path && found->second.size == file.size &&
- found->second.sha == Hex(file.sha_content) && lstat(path.c_str(), &info) == 0 && S_ISREG(info.st_mode) &&
- static_cast<std::uint64_t>(info.st_size) == file.size;
- } else {
- same = SameContent(path, file.size, file.sha_content, cancel);
- }
+ const bool same = previous ? UnchangedInTree(*previous, key, file, target.install_root)
+ : SameContent(path, file.size, file.sha_content, cancel);
if (cancel.load()) return fail(InstallError::kCanceled, "canceled");
if (!same) staged_keys.insert(key);
}
diff --git a/src/steam/backend/depot_installer.h b/src/steam/backend/depot_installer.h
index 1823e33..a95bb5d 100644
--- a/src/steam/backend/depot_installer.h
+++ b/src/steam/backend/depot_installer.h
@@ -192,6 +192,8 @@ struct InstallMeasure {
std::uint64_t install_bytes = 0;
std::uint64_t download_bytes = 0;
bool partial = false; // a depot the account was refused is left out
+ // MeasureUpdate only: the changed files' bytes, staged beside the game until the update puts them in place.
+ std::uint64_t staged_bytes = 0;
};
// Downloads and assembles an app's depots into install_root. Safe to run again after any
@@ -225,6 +227,15 @@ class DepotInstaller {
// written. A depot the account is refused is left out, as an install leaves it.
InstallMeasure Measure(const StoredSession& session, std::uint32_t app_id, const std::vector<DepotInfo>& depots,
const std::string& branch, const std::atomic<bool>& cancel);
+ // What an update of the finished install at `install_root` to `depots` downloads: the files Run's update
+ // would stage (download_bytes: their chunks' compressed bytes; staged_bytes: their sizes), from the
+ // install's tree and the new manifests. install_bytes is the new version's size. An install without a tree
+ // (made before trees were kept) is taken to hold `installed` (the depots and manifests its record names, as
+ // the new selection asks for them): their merged files stand in for the tree, as Run's hashing would find
+ // them. kProtocol without either.
+ InstallMeasure MeasureUpdate(const StoredSession& session, std::uint32_t app_id, const std::vector<DepotInfo>& depots,
+ const std::string& branch, const std::string& install_root, const std::atomic<bool>& cancel,
+ const std::vector<DepotInfo>& installed = {});
// Finishes an update whose files are all staged (phase replacing or deleting): renames them over the
// game's, deletes the files the new version dropped and the folders that leaves empty (never anything
@@ -247,6 +258,11 @@ class DepotInstaller {
static constexpr int kReraceLimit = 2;
private:
+ // Measure's work: the merged manifests of `depots`, or what stopped it in `measure`.
+ std::optional<DepotMerge> MergedManifests(const StoredSession& session, std::uint32_t app_id,
+ const std::vector<DepotInfo>& depots, const std::string& branch,
+ const std::atomic<bool>& cancel, std::vector<DepotManifest>* manifests,
+ InstallMeasure* measure);
InstallerHooks hooks_;
public:
void SetStats(std::function<void(const char*, const InstallStats&)> stats) { hooks_.stats = std::move(stats); }
diff --git a/src/stores/details_source.h b/src/stores/details_source.h
index 47157c7..af29f60 100644
--- a/src/stores/details_source.h
+++ b/src/stores/details_source.h
@@ -32,8 +32,9 @@ class DetailsSource {
// without updates checks nothing and answers false.
virtual bool CheckInstalled(const std::vector<GameId>&, std::uint64_t) { return false; }
virtual steam::InstalledCheck CheckProgress() { return {}; }
- // The exact size of one install choice (steam::MeasuredSize); a store without it answers nothing.
- virtual void Measure(const steam::SizeRequest&, std::uint64_t) {}
+ // The exact size of one install choice or update (steam::MeasuredSize); a store without it answers nothing.
+ // False when the request isn't queued (no answer will come).
+ virtual bool Measure(const steam::SizeRequest&, std::uint64_t) { return false; }
virtual std::vector<steam::MeasuredSize> PumpMeasured() { return {}; }
virtual void Shutdown() = 0;
};
diff --git a/src/stores/steam.h b/src/stores/steam.h
index af5e70a..d24b989 100644
--- a/src/stores/steam.h
+++ b/src/stores/steam.h
@@ -89,8 +89,8 @@ class SteamDetailsSource final : public DetailsSource {
return service_.CheckInstalled(ids, generation);
}
steam::InstalledCheck CheckProgress() override { return service_.CheckProgress(); }
- void Measure(const steam::SizeRequest& request, std::uint64_t generation) override {
- if (request.id.steam_app()) service_.Measure(request, generation);
+ bool Measure(const steam::SizeRequest& request, std::uint64_t generation) override {
+ return request.id.steam_app() && service_.Measure(request, generation);
}
std::vector<steam::MeasuredSize> PumpMeasured() override { return service_.PumpMeasured(); }
void Shutdown() override { service_.Shutdown(); }
diff --git a/tests/app_details_test.cpp b/tests/app_details_test.cpp
index bb3819d..c2d9a10 100644
--- a/tests/app_details_test.cpp
+++ b/tests/app_details_test.cpp
@@ -393,6 +393,35 @@ void SlowSizeChecksDontBlockDetails() {
assert(AwaitMeasured(service, 1)[0].measured);
}
+// The install sheet's size is waited for on screen: it goes ahead of updates' sizes already queued.
+void InstallSizesGoAheadOfUpdates() {
+ Sessions sessions;
+ Source source;
+ source.hold = true;
+ AppDetailsService service(source, sessions);
+ assert(service.Measure({SteamId(500), {}, {}, true}, 1)); // holds the worker
+ const auto deadline = std::chrono::steady_clock::now() + 2s;
+ for (;;) {
+ {
+ std::lock_guard<std::mutex> lock(source.mutex);
+ if (!source.measures.empty()) break;
+ }
+ assert(std::chrono::steady_clock::now() < deadline);
+ std::this_thread::sleep_for(1ms);
+ }
+ assert(service.Measure({SteamId(501), {}, {}, true}, 1) && service.Measure({SteamId(502), {}, {}, true}, 1));
+ // Updates fill their own room: a full one still takes the install sheet's.
+ for (std::uint32_t app = 600; app < 600 + AppDetailsService::kMaxPending - 2; ++app)
+ assert(service.Measure({SteamId(app), {}, {}, true}, 1));
+ assert(!service.Measure({SteamId(700), {}, {}, true}, 1));
+ assert(service.Measure({SteamId(400), "public", "english"}, 1) && service.Measure({SteamId(501), {}, {}, true}, 1));
+ source.hold = false;
+ AwaitMeasured(service, 4 + AppDetailsService::kMaxPending - 2);
+ std::lock_guard<std::mutex> lock(source.mutex);
+ assert(source.measures[1] == (SizeRequest{SteamId(400), "public", "english"}) && source.measures[2].id == SteamId(501) &&
+ source.measures[3].id == SteamId(502));
+}
+
// Only a selection whose merged size can be far from Steam's sum is worth its manifests: two depots or more of
// kMeasureDepotBytes. Portal's 401 and 409 hold mostly the same files.
void LargeOverlappingDepotsAreMeasured() {
@@ -680,16 +709,19 @@ void InstalledGamesCompareWithTheirRecord() {
record.depots = {{8001, 11, 8000, 8000}, {8002, 21, 8000, 8000}, {8011, 31, 8100, 8000}};
// The same manifests: nothing to do.
auto details = DetailsFromAppInfo(8000, buffer, grant, "english", record);
- assert(!details.update.available() && details.update.download_bytes == 0);
- // A new manifest: an update with that depot's download.
+ assert(!details.update.available() && details.update.target == 0);
+ // A new manifest: an update, to what Steam selects now (its target, which DepotsToUpdate selects too).
record.depots[1].gid = 20;
details = DetailsFromAppInfo(8000, buffer, grant, "english", record);
- assert(details.update.newer && !details.update.new_dlc && details.update.download_bytes == 40);
+ assert(details.update.newer && !details.update.new_dlc && details.update.target != 0);
+ const auto to_update = DepotsToUpdate(8000, buffer, grant, record, {});
+ assert(!to_update.empty() && details.update.target == UpdateTarget(to_update));
+ assert(DepotsToUpdate(8000, buffer, std::nullopt, record, {}).empty());
record.depots[1].gid = 21;
// A recorded depot Steam no longer selects (here: no longer licensed... as a removed one reads).
record.depots.push_back({8003, 41, 8000, 8000});
details = DetailsFromAppInfo(8000, buffer, grant, "english", record);
- assert(details.update.newer && details.update.download_bytes == 0);
+ assert(details.update.newer);
record.depots.pop_back();
// A depot listed by a DLC app whose appinfo wasn't read can't have left.
record.depots.push_back({8201, 51, 8200, 8200});
@@ -700,7 +732,7 @@ void InstalledGamesCompareWithTheirRecord() {
const auto bought = record;
record.depots.pop_back();
details = DetailsFromAppInfo(8000, buffer, grant, "english", record);
- assert(details.update.new_dlc && !details.update.newer && details.update.download_bytes == 5);
+ assert(details.update.new_dlc && !details.update.newer);
// A version 1 record names the game as every depot's owner: a held DLC depot is not new DLC.
record = bought;
record.version = 1;
@@ -718,7 +750,10 @@ void InstalledGamesCompareWithTheirRecord() {
record = bought;
record.branch = "beta";
details = DetailsFromAppInfo(8000, buffer, grant, "english", record);
- assert(details.update.newer && details.update.download_bytes == 500);
+ assert(details.update.newer);
+ // Another branch's manifests: another target.
+ const auto beta = DepotsToUpdate(8000, buffer, grant, record, {});
+ assert(details.update.target == UpdateTarget(beta) && UpdateTarget(beta) != UpdateTarget(to_update));
const auto has_beta = [](const AppDetails& value) {
return std::any_of(value.launches.begin(), value.launches.end(),
[](const LaunchOption& option) { return option.executable == "beta.exe"; });
@@ -728,6 +763,7 @@ void InstalledGamesCompareWithTheirRecord() {
int main() {
SizeChecksAreAnsweredOncePerChoice();
+ InstallSizesGoAheadOfUpdates();
SlowSizeChecksDontBlockDetails();
OpenedGameGoesFirst();
LargeOverlappingDepotsAreMeasured();
diff --git a/tests/depot_installer_test.cpp b/tests/depot_installer_test.cpp
index 400f31c..1e83986 100644
--- a/tests/depot_installer_test.cpp
+++ b/tests/depot_installer_test.cpp
@@ -1640,6 +1640,73 @@ void UpdateReplacesChangedFiles(const std::filesystem::path& root) {
CHECK(installer.Run({}, UpdateTarget(root.string() + "-missing"), cancel).error == InstallError::kProtocol);
}
+// MeasureUpdate counts what an update downloads: the files Run stages (changed or new), not whole depots.
+void MeasureUpdateMatchesTheUpdate(const std::filesystem::path& root) {
+ auto world = MakeWorld();
+ InstallBase(world, root);
+ auto& base = world.manifests[441];
+ base.gid = 21;
+ base.files[0] = world.AddFile("game.exe", {"MZ-executable-", "patched-chunk"});
+ base.files.push_back(world.AddFile("new/added.txt", {"added"}));
+ auto target = UpdateTarget(root);
+ target.depots[0].manifest_gid = 21;
+ DepotInstaller installer(world.Hooks());
+ installer.SetTuning({1, 256});
+ std::atomic<bool> cancel{false};
+ world.chunk_calls = 0;
+ const auto measured = installer.MeasureUpdate({}, target.app_id, target.depots, {}, root.string(), cancel);
+ CHECK(measured.error == InstallError::kNone && world.chunk_calls == 0);
+ CHECK(!std::filesystem::exists(root / DepotInstaller::kUpdateDir));
+ CHECK(measured.staged_bytes == 27 + 5 && measured.install_bytes == 27 + 13 + 5);
+ InstallProgress last;
+ CHECK(installer.Run({}, target, cancel, [&](const InstallProgress& progress) { last = progress; }).error == InstallError::kNone);
+ CHECK(measured.download_bytes == last.download_total && measured.download_bytes > 0);
+ // Up to date: nothing to download.
+ const auto same = installer.MeasureUpdate({}, target.app_id, target.depots, {}, root.string(), cancel);
+ CHECK(same.error == InstallError::kNone && same.download_bytes == 0 && same.staged_bytes == 0);
+ // A file changed on disk since (another size) downloads again, as Run would fetch it.
+ std::ofstream(root / "new/added.txt") << "edited by hand";
+ CHECK(installer.MeasureUpdate({}, target.app_id, target.depots, {}, root.string(), cancel).staged_bytes == 5);
+ // Without a tree and the installed manifests, only hashing the files could tell: no size.
+ std::filesystem::remove(root / DepotInstaller::kFileTree);
+ const auto unknown = installer.MeasureUpdate({}, target.app_id, target.depots, {}, root.string(), cancel);
+ CHECK(unknown.error == InstallError::kProtocol && unknown.detail == "no file tree");
+}
+
+// An install from before trees were kept: the manifests its record names stand in for the tree.
+void MeasureUpdateWithoutTreeUsesTheInstalledManifests(const std::filesystem::path& root) {
+ auto world = MakeWorld();
+ InstallBase(world, root);
+ std::filesystem::remove(root / DepotInstaller::kFileTree);
+ const auto installed_base = world.manifests[441];
+ auto& base = world.manifests[441];
+ base.gid = 21;
+ base.files[0] = world.AddFile("game.exe", {"MZ-executable-", "patched-chunk"});
+ base.files.push_back(world.AddFile("new/added.txt", {"added"}));
+ auto hooks = world.Hooks();
+ std::vector<std::pair<std::uint32_t, std::uint64_t>> asked;
+ hooks.manifest = [&](const ContentServer&, const DepotGrant& grant, const std::atomic<bool>&, DepotManifest* out) {
+ asked.emplace_back(grant.depot_id, grant.manifest_gid);
+ *out = grant.depot_id == 441 && grant.manifest_gid == 11 ? installed_base : world.manifests.at(grant.depot_id);
+ return InstallError::kNone;
+ };
+ DepotInstaller installer(hooks);
+ installer.SetTuning({1, 256});
+ std::atomic<bool> cancel{false};
+ auto target = UpdateTarget(root);
+ const auto installed = target.depots; // 441 at 11, 442 at 12
+ target.depots[0].manifest_gid = 21;
+ world.chunk_calls = 0;
+ const auto measured = installer.MeasureUpdate({}, target.app_id, target.depots, {}, root.string(), cancel, installed);
+ CHECK(measured.error == InstallError::kNone && world.chunk_calls == 0);
+ CHECK((asked == std::vector<std::pair<std::uint32_t, std::uint64_t>>{{441, 11}, {442, 12}, {441, 21}, {442, 12}}));
+ CHECK(measured.staged_bytes == 27 + 5);
+ // The update hashes the files and downloads the same ones.
+ InstallProgress last;
+ CHECK(installer.Run({}, target, cancel, [&](const InstallProgress& progress) { last = progress; }).error == InstallError::kNone);
+ CHECK(measured.download_bytes == last.download_total);
+}
+
// A depot that leaves the selection gives its files back to the depot under it: the patch depot won
// level.dat; without it the base depot's level.dat must be written again (it never changed itself).
void UpdateRestoresFilesOfARemovedDepot(const std::filesystem::path& root) {
@@ -2693,6 +2760,8 @@ int main(int argc, char** argv) {
BrokenManifestIsFetchedAgainElsewhere(base / "manifest");
RemovesOnlyManagedFolders(base);
UpdateReplacesChangedFiles(base / "update");
+ MeasureUpdateMatchesTheUpdate(base / "update-measure");
+ MeasureUpdateWithoutTreeUsesTheInstalledManifests(base / "update-measure-no-tree");
UpdateRestoresFilesOfARemovedDepot(base / "update-removed-depot");
UpdateWithoutTreeHashesFiles(base / "update-no-tree");
InterruptedUpdateResumes(base / "update-resume");
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index a1e0c40..83ec6c4 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -3816,22 +3816,22 @@ void live_game_update() {
check(model.action("details:42"), "details open");
check(!has_row(model, "details-update") && !has_row(model, "details-update-note"), "nothing to update, no button");
- model.UpdateAppDetails(SteamId(42), 100, 6'000'000'000, true, {}, 0, {}, GameUpdate{true, false, 1'200'000'000});
+ model.UpdateAppDetails(SteamId(42), 100, 6'000'000'000, true, {}, 0, {}, GameUpdate{true, false, 1'200'000'000, 1'400'000'000, 1, true});
const auto& rows = model.view().rows;
const auto play_at = std::find_if(rows.begin(), rows.end(), [](const auto& row) { return row.key == "details-play"; });
const auto update_at = std::find_if(rows.begin(), rows.end(), [](const auto& row) { return row.key == "details-update"; });
check(play_at != rows.end() && update_at == play_at + 1 && update_at->title == "Update" && update_at->enabled,
"Update follows Play");
const auto* note = find_row(model, "details-update-note");
- check(note && note->title == "Update available" && note->value == "Up to 1.2 GB", "the note says the update's size");
+ check(note && note->title == "Update available" && note->value == "1.2 GB", "the note says the update's size");
activate(model, "details-update");
check(model.view().surface == "update" && model.view().title == "Update game", "Update opens its sheet");
const auto* confirm = find_row(model, "update-confirm");
- check(confirm && confirm->title == "Download and install" && confirm->value == "Up to 1.2 GB" && confirm->enabled &&
+ check(confirm && confirm->title == "Download and install" && confirm->value == "1.2 GB" && confirm->enabled &&
confirm->subtitle == "Starts the download",
"the sheet's confirm row has the size, as the install sheet");
check(model.view().subtitle.find("On Console storage. ") != std::string::npos &&
- model.view().subtitle.find("Downloads up to 1.2 GB") != std::string::npos,
+ model.view().subtitle.find("Downloads 1.2 GB") != std::string::npos,
"the sheet says where and how much");
activate(model, "update-confirm");
auto requests = model.TakeInstallRequests();
@@ -3840,19 +3840,19 @@ void live_game_update() {
check(model.view().surface != "update", "the sheet closes");
// DLC bought since wins the label, even when an update downloads with it.
- model.UpdateAppDetails(SteamId(42), 100, 6'000'000'000, true, {}, 0, {}, GameUpdate{true, true, 300'000'000});
+ model.UpdateAppDetails(SteamId(42), 100, 6'000'000'000, true, {}, 0, {}, GameUpdate{true, true, 300'000'000, 300'000'000, 2, true});
check(find_row(model, "details-update")->title == "DLC available" &&
find_row(model, "details-update-note")->title == "DLC available" &&
- find_row(model, "details-update-note")->value == "Up to 300 MB",
+ find_row(model, "details-update-note")->value == "300 MB",
"new DLC says DLC available");
- // Less room than Steam's whole-depot estimate: only the download knows what the changed files need, so the
- // sheet shows the estimate and lets it start.
+ // Less room than the changed files need: the sheet shows the size and lets it start; the download checks the
+ // room itself.
model.UpdateVolumes({{"internal", "Console storage", true, 100'000'000'000, 200'000'000}}, "internal");
activate(model, "details-update");
confirm = find_row(model, "update-confirm");
- check(confirm && confirm->enabled && confirm->subtitle == "Starts the download", "the estimate doesn't block the update");
- check(model.view().subtitle.find("Downloads up to 300 MB") != std::string::npos, "it is shown as an estimate");
+ check(confirm && confirm->enabled && confirm->subtitle == "Starts the download", "the room doesn't block the update");
+ check(model.view().subtitle.find("Downloads 300 MB") != std::string::npos, "the sheet says the size");
activate(model, "update-confirm");
requests = model.TakeInstallRequests();
check(requests.size() == 1 && requests[0].kind == InstallRequestKind::Update, "the update is sent");
diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cpp
index 1c3023d..0939bd8 100644
--- a/tests/homebrew_live_model_test.cpp
+++ b/tests/homebrew_live_model_test.cpp
@@ -646,7 +646,7 @@ void live_program_change_applies_like_other_settings(const std::filesystem::path
"program: closing the sheet applies the new program");
model.action("circle");
activate(model, "details-play");
- check(model.state().navigation.modals.empty() && model.TakeRuntimePlayRequests() == std::vector<GameId>{SteamId(22380)},
+ check(model.state().navigation.modals.empty() && model.TakeRuntimePlayRequests() == std::vector<playden::GameId>{SteamId(22380)},
"program: Play starts at once");
// Reset to recipe goes back to Steam's launch option, not the program the recipe lists first.
@@ -1464,8 +1464,8 @@ void live_manage_games_tabs(const std::filesystem::path& base) {
model.BeginUpdateCheckLoad(kAccount);
playden::SavedUpdateCheck saved;
saved.checked_at = kNow - 2 * 60 * 60;
- saved.games[SteamId(10)] = {true, false, 2 * gb};
- saved.games[SteamId(20)] = {false, true, 120'000'000};
+ saved.games[SteamId(10)] = {true, false, 2 * gb, 2 * gb, 1, true};
+ saved.games[SteamId(20)] = {false, true, 120'000'000, 120'000'000, 2, true};
model.ApplyUpdateCheck(kAccount, saved);
for (int i = 0; i < 6 && model.state().navigation.route != Route::Settings; ++i) model.action("r1");
activate(model, "settings-installed");
@@ -1598,10 +1598,10 @@ void live_manage_update_selected(const std::filesystem::path& base) {
model.BeginUpdateCheckLoad(kAccount);
playden::SavedUpdateCheck saved;
saved.checked_at = kNow - 60 * 60;
- saved.games[SteamId(10)] = {true, false, 2 * gb};
- saved.games[SteamId(20)] = {false, true, 1 * gb};
- saved.games[SteamId(30)] = {true, false, 3 * gb};
- saved.games[SteamId(40)] = {true, false, 4 * gb};
+ saved.games[SteamId(10)] = {true, false, 2 * gb, 2 * gb, 1, true};
+ saved.games[SteamId(20)] = {false, true, 1 * gb, 1 * gb, 2, true};
+ saved.games[SteamId(30)] = {true, false, 3 * gb, 3 * gb, 3, true};
+ saved.games[SteamId(40)] = {true, false, 4 * gb, 4 * gb, 4, true};
model.ApplyUpdateCheck(kAccount, saved);
for (int i = 0; i < 6 && model.state().navigation.route != Route::Settings; ++i) model.action("r1");
activate(model, "settings-installed");
@@ -1614,13 +1614,14 @@ void live_manage_update_selected(const std::filesystem::path& base) {
activate(model, "manage-toggle-40");
check(!find_row(model, "manage-toggle-40")->selected, "update selected: a game in the Queue can't be checked");
- // Tunic's 3 GB estimate doesn't fit in the USB drive's 2 GB: Triangle warns first, and Cancel queues nothing.
- check(model.view().footer == "3 selected · 6.0 GB to download · may need 1.0 GB more on USB Drive",
- "update selected: the footer names the drive that may lack room");
+ // Tunic's 3 GB of changed files and the install margin don't fit in the USB drive's 2 GB: Triangle warns
+ // first, and Cancel queues nothing.
+ check(model.view().footer == "3 selected · 6.0 GB to download · needs 1.1 GB more on USB Drive",
+ "update selected: the footer names the drive that lacks room");
model.action("triangle");
check(model.TakeInstallRequests().empty(), "update selected: the warning comes before anything is queued");
check(!navigation.modals.empty() && navigation.modals.back().title == "Update anyway?" &&
- navigation.modals.back().body.find("may need 1.0 GB more on USB Drive") != std::string::npos,
+ navigation.modals.back().body.find("need 1.1 GB more on USB Drive") != std::string::npos,
"update selected: the warning names the drive and the room it may lack");
activate(model, "cancel");
check(navigation.route == Route::ManageGames && navigation.modals.empty() && model.TakeInstallRequests().empty(),
@@ -1743,12 +1744,31 @@ void live_settings_manage_rows(const std::filesystem::path& base) {
model.UpdateCheckProgress(32, 24, 40);
check(value("settings-game-updates") == "Checking 24 of 40…", "settings rows: checking with progress");
- // Found: two updates and their download.
- model.UpdateAppDetails(SteamId(10), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{true, false, 2'100'000'000});
- model.UpdateAppDetails(SteamId(20), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{false, true, 200'000'000});
+ // Found: two updates, their sizes not measured yet.
+ model.UpdateAppDetails(SteamId(10), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{true, false, 0, 0, 11});
+ model.UpdateAppDetails(SteamId(20), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{false, true, 0, 0, 21});
model.FinishUpdateCheck(false);
- check(value("settings-game-updates") == "2 updates · 2.3 GB" && subtitle("settings-game-updates") == "Checked just now",
+ check(value("settings-game-updates") == "2 updates" && subtitle("settings-game-updates") == "Checked just now",
"settings rows: updates found");
+ // Each update's size is asked once; one for another target than the saved update's is dropped.
+ auto sizes = model.TakeUpdateSizeChecks();
+ check(sizes == std::vector<playden::GameId>{SteamId(10), SteamId(20)} && model.TakeUpdateSizeChecks().empty(),
+ "settings rows: each update's size is asked once");
+ check(!model.UpdateMeasuredUpdate(SteamId(10), true, 11, 2'100'000'000, 2'500'000'000), "settings rows: a size is kept");
+ check(model.UpdateMeasuredUpdate(SteamId(20), true, 99, 200'000'000, 200'000'000),
+ "settings rows: a size for a newer update asks Steam about the game again");
+ check(value("settings-game-updates") == "2 updates" && model.TakeUpdateSizeChecks().empty(),
+ "settings rows: a size for another update isn't used or asked again");
+ // Steam answers for the game again (the same update): its size is asked again, and a size stays with its update.
+ model.UpdateAppDetails(SteamId(20), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{false, true, 0, 0, 21});
+ model.UpdateAppDetails(SteamId(10), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{true, false, 0, 0, 11});
+ sizes = model.TakeUpdateSizeChecks();
+ check(sizes == std::vector<playden::GameId>{SteamId(20)}, "settings rows: Steam's answer asks an unmeasured size again");
+ model.UpdateMeasuredUpdate(SteamId(20), true, 21, 200'000'000, 200'000'000);
+ check(value("settings-game-updates") == "2 updates · 2.3 GB", "settings rows: measured sizes add up");
+ check(model.state().update_check.games.at(SteamId(10)).staged_bytes == 2'500'000'000 &&
+ model.ExportUpdateCheck().games.at(SteamId(10)).sized,
+ "settings rows: the staged bytes are kept and saved");
check(value("settings-installed") == "3 games · 60.0 GB · 2 updates", "settings rows: Storage counts the updates");
model.SetWallClock(kNow + 2 * 60 * 60);
check(subtitle("settings-game-updates") == "Checked 2 h ago", "settings rows: when it was checked");
@@ -1778,7 +1798,7 @@ void live_settings_manage_rows(const std::filesystem::path& base) {
"settings rows: up to date");
// One update is singular.
- model.UpdateAppDetails(SteamId(30), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{true, false, 48'000'000});
+ model.UpdateAppDetails(SteamId(30), 1, 1, true, {}, 0, {}, playden::homebrew::GameUpdate{true, false, 48'000'000, 48'000'000, 5, true});
check(value("settings-game-updates") == "1 update · 48 MB" && value("settings-installed") == "3 games · 60.0 GB · 1 update",
"settings rows: one update");
}
@@ -1930,7 +1950,7 @@ void live_manage_queue_full(const std::filesystem::path& base) {
model.BeginUpdateCheckLoad(kAccount);
playden::SavedUpdateCheck saved;
saved.checked_at = kNow - 60 * 60;
- saved.games[SteamId(10)] = {true, false, 2 * gb};
+ saved.games[SteamId(10)] = {true, false, 2 * gb, 2 * gb, 1, true};
saved.games[SteamId(20)] = {true, false, 1 * gb};
model.ApplyUpdateCheck(kAccount, saved);
for (int i = 0; i < 6 && model.state().navigation.route != Route::Settings; ++i) model.action("r1");
diff --git a/tests/homebrew_simulation_test.cpp b/tests/homebrew_simulation_test.cpp
index ef3cac7..1deed82 100644
--- a/tests/homebrew_simulation_test.cpp
+++ b/tests/homebrew_simulation_test.cpp
@@ -727,10 +727,10 @@ void game_update_scenarios(const std::filesystem::path& fixtures, const std::fil
};
check(simulation.scenario("update-available"), "update-available loads");
check(row("details-update") && row("details-update")->title == "Update" && row("details-update-note") &&
- row("details-update-note")->title == "Update available" && row("details-update-note")->value == "Up to 1.2 GB",
+ row("details-update-note")->title == "Update available" && row("details-update-note")->value == "1.2 GB",
"update-available offers Update with its size");
check(simulation.action("cross") && simulation.view().surface == "update" && row("update-confirm") &&
- row("update-confirm")->enabled && row("update-confirm")->value == "Up to 1.2 GB",
+ row("update-confirm")->enabled && row("update-confirm")->value == "1.2 GB",
"Update opens the update sheet");
check(simulation.action("circle"), "the sheet closes");
check(simulation.scenario("dlc-available") && row("details-update")->title == "DLC available",
diff --git a/tests/library_update_check_test.cpp b/tests/library_update_check_test.cpp
index 4f682e3..cf1eede 100644
--- a/tests/library_update_check_test.cpp
+++ b/tests/library_update_check_test.cpp
@@ -37,12 +37,12 @@ int main() {
auto missing = store.Load(76561198000000001ull);
Check(missing.ok() && !missing.value(), "an account without a file has no check");
- // A round trip keeps the time and each game's kind and download size.
+ // A round trip keeps the time, each game's kind and target, and the sizes measured for it.
SavedUpdateCheck saved;
saved.checked_at = 1'800'000'000;
- saved.games[SteamId(1091500)] = {true, false, 2'100'000'000};
- saved.games[SteamId(548430)] = {false, true, 120'000'000};
- saved.games[SteamId(220)] = {true, true, 0};
+ saved.games[SteamId(1091500)] = {true, false, 2'100'000'000, 2'600'000'000, 77, true};
+ saved.games[SteamId(548430)] = {false, true, 0, 0, 78, true}; // measured: nothing to download
+ saved.games[SteamId(220)] = {true, true, 0, 0, 79, false};
saved.games[SteamId(440)] = {false, false, 50}; // nothing to download: not saved
Check(store.Save(76561198000000001ull, saved).ok(), "save a check");
auto loaded = store.Load(76561198000000001ull);
@@ -51,15 +51,19 @@ int main() {
expected.games.erase(SteamId(440));
Check(*loaded.value() == expected, "time, kinds and sizes survive the round trip");
struct stat info{};
- Check(stat((std::string(root) + "/updates-76561198000000001.v1").c_str(), &info) == 0 && (info.st_mode & 0777) == 0600,
+ Check(stat((std::string(root) + "/updates-76561198000000001.v2").c_str(), &info) == 0 && (info.st_mode & 0777) == 0600,
"the file is owner-only");
+ // Sizes not measured are not kept.
+ saved.games[SteamId(220)].download_bytes = 5;
+ Check(store.Save(76561198000000001ull, saved).ok() && *store.Load(76561198000000001ull).value() == expected,
+ "an unmeasured size is dropped");
// Accounts don't see each other's checks.
Check(store.Load(76561198000000002ull).ok() && !store.Load(76561198000000002ull).value(),
"another account has none");
SavedUpdateCheck other;
other.checked_at = 1'700'000'000;
- other.games[SteamId(620)] = {true, false, 7};
+ other.games[SteamId(620)] = {true, false, 7, 9, 1, true};
Check(store.Save(76561198000000002ull, other).ok(), "save the other account's check");
Check(*store.Load(76561198000000001ull).value() == expected && *store.Load(76561198000000002ull).value() == other,
"each account reads its own");
@@ -70,19 +74,28 @@ int main() {
// Damaged files fail the load.
const char* damaged[] = {
- "", "version=2\nchecked_at=1\n", "version=1\n", "version=1\nchecked_at=-1\n", "version=1\nchecked_at=01\n",
- "version=1\nchecked_at=1", "version=1\nchecked_at=1\n440 0 5\n", "version=1\nchecked_at=1\n440 4 5\n",
- "version=1\nchecked_at=1\n440 1\n", "version=1\nchecked_at=1\nabc 1 5\n", "version=1\nchecked_at=1\n440 1 5\n440 2 6\n",
- "version=1\nchecked_at=1\n440 1 99999999999999999999999\n"};
+ "", "version=1\nchecked_at=1\n", "version=2\n", "version=2\nchecked_at=-1\n", "version=2\nchecked_at=01\n",
+ "version=2\nchecked_at=1", "version=2\nchecked_at=1\n440 0 5 5 1\n", "version=2\nchecked_at=1\n440 4 5 5 1\n",
+ "version=2\nchecked_at=1\n440 8 5 5 1\n", "version=2\nchecked_at=1\n440 1 5\n", "version=2\nchecked_at=1\nabc 1 5 5 1\n",
+ "version=2\nchecked_at=1\n440 1 5 5 1\n440 2 6 6 1\n", "version=2\nchecked_at=1\n440 1 99999999999999999999999 5 1\n"};
for (const char* text : damaged) {
- Write(storage, "updates-76561198000000004.v1", text);
+ Write(storage, "updates-76561198000000004.v2", text);
const auto result = store.Load(76561198000000004ull);
Check(!result.ok() && result.error() == StorageError::kInvalidData, "a damaged file is refused");
}
- Write(storage, "updates-76561198000000004.v1", "version=1\nchecked_at=5\n440 1 5\nlocal-0123abcd-0000-4000-8000-000000000000 2 9\n");
+ Write(storage, "updates-76561198000000004.v2",
+ "version=2\nchecked_at=5\n440 5 5 6 7\nlocal-0123abcd-0000-4000-8000-000000000000 2 0 0 0\n");
const auto mixed = store.Load(76561198000000004ull);
Check(mixed.ok() && mixed.value()->games.size() == 2, "game keys of any store parse");
+ // Without a version 2 file, version 1's flags are read; its sizes were Steam's whole-depot estimates.
+ Write(storage, "updates-76561198000000005.v1", "version=1\nchecked_at=5\n440 3 5\n");
+ const auto old = store.Load(76561198000000005ull);
+ Check(old.ok() && old.value()->checked_at == 5 && old.value()->games.at(SteamId(440)) == SavedGameUpdate{true, true},
+ "a version 1 file keeps its flags only");
+ Write(storage, "updates-76561198000000005.v1", "version=1\nchecked_at=5\n440 4 5\n");
+ Check(!store.Load(76561198000000005ull).ok(), "a damaged version 1 file is refused");
+
Check(!store.Save(0, saved).ok() && !store.Load(0).ok(), "account 0 is refused");
std::filesystem::remove_all(root);
std::puts("library_update_check_test passed");
diff --git a/tests/persistence_service_test.cpp b/tests/persistence_service_test.cpp
index 0db2b99..570a553 100644
--- a/tests/persistence_service_test.cpp
+++ b/tests/persistence_service_test.cpp
@@ -408,7 +408,7 @@ void UpdateChecksLoadAndSavePerAccount() {
assert(loaded.error == StorageError::kNone && !loaded.update_check && loaded.account_id == 7);
SavedUpdateCheck check;
check.checked_at = 1'800'000'000;
- check.games[SteamId(440)] = {true, false, 12};
+ check.games[SteamId(440)] = {true, false, 12, 30, 99, true};
const auto saved = Await(service, PersistenceEventKind::kUpdateCheckSaved, service.SaveUpdateCheck(7, 3, check));
assert(saved.error == StorageError::kNone && saved.revision == 3 && saved.account_id == 7);
loaded = Await(service, PersistenceEventKind::kUpdateCheckLoaded, service.LoadUpdateCheck(7));
@@ -416,7 +416,7 @@ void UpdateChecksLoadAndSavePerAccount() {
loaded = Await(service, PersistenceEventKind::kUpdateCheckLoaded, service.LoadUpdateCheck(8));
assert(loaded.error == StorageError::kNone && !loaded.update_check);
service.Shutdown();
- std::remove((directory.path() + "/updates-7.v1").c_str());
+ std::remove((directory.path() + "/updates-7.v2").c_str());
}
int main() {