Skip to content

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

C++

Show Steam demos in the Library

Leonardo Lobato59cc369f3c0a
diff --git a/src/homebrew/browse.cpp b/src/homebrew/browse.cpp
index 6d4ea49..83b021f 100644
--- a/src/homebrew/browse.cpp
+++ b/src/homebrew/browse.cpp
@@ -137,6 +137,9 @@ std::vector<const Game*> filtered_games(const State& state)
}
if (state.library.filters.contains("installed") && !installed(state, game.id))
continue;
+ // Demos show unless the player hides them, so the stored filter is the hiding one.
+ if (state.library.filters.contains("hide-demos") && game.demo)
+ continue;
if (state.library.filters.contains("genre-adventure") &&
std::find(game.genres.begin(), game.genres.end(), "Adventure") == game.genres.end())
continue;
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index 3b14a62..8a68a16 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -481,7 +481,7 @@ std::string action_label(const std::string& key) {
{"sort-name", "Name"}, {"sort-recent-played", "Recently played"}, {"sort-recent-added", "Recently added"},
{"sort-playtime", "Playtime"}, {"sort-install-size", "Install size"}, {"filter-installed", "Installed"},
{"filter-genre-adventure", "Adventure"}, {"filter-controller-full", "Full controller support"},
- {"filter-compat-playable", "Playable"}, {"filters-reset", "Reset filters"}, {"refresh-library", "Refresh library"}, {"advance-clock", "Advance fixture clock"},
+ {"filter-compat-playable", "Playable"}, {"filter-hide-demos", "Demos"}, {"filters-reset", "Reset filters"}, {"refresh-library", "Refresh library"}, {"advance-clock", "Advance fixture clock"},
{"inject-download-failed", "Inject download failure"}, {"inject-verification-failed", "Inject verification failure"},
{"inject-uninstall-failed", "Inject uninstall failure"},
{"inject-storage-disconnect", "Disconnect storage"}, {"inject-controller-disconnect", "Disconnect controller"},
@@ -2397,6 +2397,7 @@ bool Simulation::UpdateLibrary(LibraryUpdate update) {
game.last_played = static_cast<std::int64_t>(*summary.last_played_unix_seconds);
if (summary.added_at_unix_seconds)
game.added_at = static_cast<std::int64_t>(*summary.added_at_unix_seconds);
+ game.demo = summary.demo;
if (const auto facts = store_facts_.find(game.id); facts != store_facts_.end()) {
if (!facts->second.description.empty()) game.description = facts->second.description;
game.genres = facts->second.genres;
@@ -2930,6 +2931,7 @@ void Simulation::load_fixtures() {
if (const auto added = optional_uint(item.get("added_at"))) game.added_at = static_cast<std::int64_t>(*added);
if (const auto played = optional_uint(item.get("last_played"))) game.last_played = static_cast<std::int64_t>(*played);
game.playtime_minutes = optional_uint(item.get("playtime_minutes"));
+ game.demo = bool_value(item.get("demo"));
state_.games.push_back(std::move(game));
}
}
@@ -3504,6 +3506,23 @@ bool Simulation::scenario(const std::string& name) {
} else if (name == "reduced-motion") {
state_.reduced_motion = true;
save_profile();
+ } else if (name == "demos") {
+ // A demo next to the full game, as Steam lists one after "Download demo".
+ state_.navigation.route = Route::Library;
+ Game demo;
+ demo.id = GameId::Steam(900025);
+ demo.title = "Tiny Astronaut Demo";
+ demo.description = "A synthetic demo. UI fixture only; this is not an owned game.";
+ demo.source = "Steam";
+ demo.controller_support = "full";
+ demo.download_bytes = demo.install_bytes = 536870912;
+ demo.demo = true;
+ if (const auto* full = find_game(state_, GameId::Steam(900021))) {
+ demo.cover_key = full->cover_key, demo.hero_key = full->hero_key, demo.logo_key = full->logo_key;
+ demo.genres = full->genres;
+ }
+ if (!find_game(state_, demo.id)) state_.games.push_back(std::move(demo));
+ reconcile_library_selection(state_);
} else if (name == "stress") {
const auto source = read_file(fixture_directory_.parent_path() / "library.json");
const auto root = json::parse(source);
@@ -3815,6 +3834,12 @@ void Simulation::rebuild_view() {
for (const auto& action_key : modal.action_keys) {
auto& item = row(action_key, RowKind::Action, action_label(action_key), action_key);
item.dangerous = modal.destructive && action_key != "cancel";
+ // Demos is on unless the player hid them.
+ if (action_key == "filter-hide-demos") {
+ item.kind = RowKind::Toggle;
+ item.selected = !state_.library.filters.contains("hide-demos");
+ item.value = item.selected ? "On" : "Off";
+ }
// The menu's Favorite says what it will do for this game.
if (modal.id == "context" && action_key == "favorite")
item.title = state_.library.favorites.contains(state_.navigation.selected_game_id) ? "Remove from Favorites"
@@ -7834,6 +7859,9 @@ bool Simulation::action(const std::string& logical_action) {
const bool dated = state_.library.sort == "recent-added" ||
std::any_of(state_.games.begin(), state_.games.end(),
[](const Game& game) { return game.added_at.has_value(); });
+ // Demos is listed while there are demos, or while they are hidden so they can be shown again.
+ const bool demos = state_.library.filters.contains("hide-demos") ||
+ std::any_of(state_.games.begin(), state_.games.end(), [](const Game& game) { return game.demo; });
std::vector<std::string> actions = live()
? (dated ? std::vector<std::string>{"sort-name", "sort-recent-played", "sort-recent-added", "sort-playtime",
"filter-compat-playable", "filters-reset", "refresh-library", "cancel"}
@@ -7842,6 +7870,8 @@ bool Simulation::action(const std::string& logical_action) {
: std::vector<std::string>{"sort-name", "sort-recent-played", "sort-recent-added", "sort-playtime", "sort-install-size",
"filter-installed", "filter-genre-adventure", "filter-controller-full", "filter-compat-playable",
"filters-reset", "refresh-library", "cancel"};
+ if (demos)
+ actions.insert(std::find(actions.begin(), actions.end(), "filters-reset"), "filter-hide-demos");
open_modal({"filters", "Sort and filters", state_.navigation.focus_key, std::move(actions), 0, false});
}
}
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index 44cde9d..2be496b 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -412,6 +412,7 @@ struct Game {
std::optional<std::int64_t> last_played;
std::optional<std::uint64_t> playtime_minutes;
std::optional<bool> windows_installable; // from Steam app info; absent until fetched
+ bool demo = false; // a Steam demo; Sort and filters › Demos hides it
bool art_pending = false;
bool art_failed = false;
};
diff --git a/src/library/cache.cpp b/src/library/cache.cpp
index 7fbc617..842e16d 100644
--- a/src/library/cache.cpp
+++ b/src/library/cache.cpp
@@ -7,8 +7,8 @@ namespace playden {
namespace {
constexpr std::size_t kMaximumCacheBytes = 16 * 1024 * 1024;
constexpr std::size_t kMaximumGames = 100000;
-// Schema 5 names each game by store and value; 4 and older hold Steam app IDs only.
-constexpr unsigned kLatestSchema = 5;
+// Schema 5 names each game by store and value; 4 and older hold Steam app IDs only. 6 marks demos.
+constexpr unsigned kLatestSchema = 6;
constexpr std::size_t kMaximumGameValue = 48;
const Bytes kMagic = {'P','D','L','I','B',0,1,0};
bool ValidAccount(const std::string& account) {
@@ -69,11 +69,12 @@ Result<void> LibraryCache::Save(const std::string& account,const LibrarySnapshot
if(!ValidGame(game,snapshot.schema_version)||!seen.insert(game.id).second)return Invalid("Invalid or duplicate cached game.");
if(snapshot.schema_version==1 && (game.playtime_minutes || game.last_played_unix_seconds))return Invalid("Cache schema cannot preserve game history.");
if(snapshot.schema_version<4 && game.added_at_unix_seconds)return Invalid("Cache schema cannot preserve acquisition dates.");
+ if(snapshot.schema_version<6 && game.demo)return Invalid("Cache schema cannot preserve demos.");
if(snapshot.schema_version>=5){Number(encoded,static_cast<std::uint8_t>(game.id.store),1);String(encoded,game.id.value);}
else Number(encoded,*game.id.steam_app(),4);
String(encoded,game.title);String(encoded,game.artwork_source);String(encoded,game.description);String(encoded,game.developer);
if(snapshot.schema_version>=2){
- Number(encoded,(game.playtime_minutes?1u:0u)|(game.last_played_unix_seconds?2u:0u)|(game.added_at_unix_seconds?4u:0u),1);
+ Number(encoded,(game.playtime_minutes?1u:0u)|(game.last_played_unix_seconds?2u:0u)|(game.added_at_unix_seconds?4u:0u)|(game.demo?8u:0u),1);
if(game.playtime_minutes)Number(encoded,*game.playtime_minutes,8);
if(game.last_played_unix_seconds)Number(encoded,*game.last_played_unix_seconds,8);
if(game.added_at_unix_seconds)Number(encoded,*game.added_at_unix_seconds,8);
@@ -115,10 +116,11 @@ Result<LibrarySnapshot> LibraryCache::Load(const std::string& account) const {
game.artwork_source=reader.String(8192);game.description=reader.String(65536);game.developer=reader.String(4096);
if(snapshot.schema_version>=2){
const auto flags=reader.Number(1);
- if(flags>(snapshot.schema_version>=4?7u:3u))return invalid();
+ if(flags>(snapshot.schema_version>=6?15u:snapshot.schema_version>=4?7u:3u))return invalid();
if(flags&1)game.playtime_minutes=reader.Number(8);
if(flags&2)game.last_played_unix_seconds=reader.Number(8);
if(flags&4)game.added_at_unix_seconds=reader.Number(8);
+ game.demo=(flags&8)!=0;
}
if(!reader.okay||!ValidGame(game,snapshot.schema_version)||!seen.insert(game.id).second)return invalid();
snapshot.games.push_back(std::move(game));
diff --git a/src/library/model.h b/src/library/model.h
index 3ee2d22..1136ac0 100644
--- a/src/library/model.h
+++ b/src/library/model.h
@@ -16,5 +16,7 @@ struct GameSummary {
std::optional<std::uint64_t> last_played_unix_seconds;
// Earliest license acquisition, from the Steam CM; absent when CM was unavailable.
std::optional<std::uint64_t> added_at_unix_seconds;
+ // A Steam demo (PICS type "demo"), which the Library can hide.
+ bool demo = false;
};
} // namespace playden
diff --git a/src/library/organization.cpp b/src/library/organization.cpp
index f6d6e53..50c0f64 100644
--- a/src/library/organization.cpp
+++ b/src/library/organization.cpp
@@ -112,8 +112,9 @@ bool ValidSort(const std::string& value) {
value == "playtime";
}
-bool ValidFilter(const std::string& value) {
- return value == "compat-playable";
+// Version 1 knows only Playable; version 2 also keeps demos hidden (they show by default).
+bool ValidFilter(const std::string& value, std::uint16_t version) {
+ return value == "compat-playable" || (version != kVersion1 && value == "hide-demos");
}
// Version 1 stores Steam app IDs only; version 2 any valid game.
@@ -174,9 +175,9 @@ bool Validate(const OrganizationSnapshot& snapshot, std::uint16_t version) {
return false;
}
}
- if (snapshot.filters.size() > 1) return false;
+ if (snapshot.filters.size() > (version == kVersion1 ? 1u : 2u)) return false;
for (const auto& filter : snapshot.filters) {
- if (!ValidText(filter, kMaximumFilterBytes, false) || !ValidFilter(filter)) return false;
+ if (!ValidText(filter, kMaximumFilterBytes, false) || !ValidFilter(filter, version)) return false;
}
return true;
}
@@ -503,7 +504,7 @@ Loaded DecodeV2(const Bytes& bytes) {
if (!reader.String(snapshot.query, kMaximumQueryBytes) ||
!reader.String(snapshot.scope, kMaximumScopeBytes) ||
!reader.String(snapshot.sort, kMaximumSortBytes) ||
- !reader.U32(filter_count) || filter_count > 1) {
+ !reader.U32(filter_count) || filter_count > 2) {
return InvalidLoad("view state");
}
for (std::uint32_t index = 0; index < filter_count; ++index) {
diff --git a/src/library/repository.h b/src/library/repository.h
index a6ec167..7d7f55f 100644
--- a/src/library/repository.h
+++ b/src/library/repository.h
@@ -9,7 +9,8 @@
namespace playden {
struct LibrarySnapshot {
- std::uint32_t schema_version = 4; // 5 names games by store and value (other stores than Steam)
+ // 5 names games by store and value (other stores than Steam); 6 marks demos.
+ std::uint32_t schema_version = 4;
std::uint64_t retrieved_at_unix_seconds = 0;
std::vector<GameSummary> games;
bool metadata_partial = false;
diff --git a/src/library/service.cpp b/src/library/service.cpp
index 2643a57..a849ea7 100644
--- a/src/library/service.cpp
+++ b/src/library/service.cpp
@@ -294,6 +294,9 @@ void LibraryService::ExecuteRefresh(const Job& job) {
if (previous != previous_added_at.end()) game.added_at_unix_seconds = previous->second;
}
snapshot.metadata_partial = result.metadata_partial;
+ // Only a library with demos needs schema 6; one without stays readable by older versions.
+ if (std::any_of(snapshot.games.begin(), snapshot.games.end(), [](const GameSummary& game) { return game.demo; }))
+ snapshot.schema_version = 6;
if (cache_) {
const auto saved = cache_->Save(job.account, snapshot);
if (!Current(job)) return;
diff --git a/src/steam/backend/entitled_library.cpp b/src/steam/backend/entitled_library.cpp
index adb2ffc..aa27cf6 100644
--- a/src/steam/backend/entitled_library.cpp
+++ b/src/steam/backend/entitled_library.cpp
@@ -72,7 +72,8 @@ void EntitledLibraryBackend::AddLicensedGames(const StoredSession& session,
const auto info = ParseAppInfo(app, found->second);
std::string type = info ? info->type : std::string();
std::transform(type.begin(), type.end(), type.begin(), [](unsigned char c) { return std::tolower(c); });
- if (info && type == "game" && info->name != "app_" + std::to_string(app)) name = info->name;
+ if (info && (type == "game" || type == "demo") && info->name != "app_" + std::to_string(app)) name = info->name;
+ if (!name.empty() && type == "demo") demos_.insert(app);
if (!name.empty() && info && !info->icon.empty())
icons_[app] = "https://media.steampowered.com/steamcommunity/public/images/apps/" + std::to_string(app) +
"/" + info->icon + ".jpg";
@@ -84,6 +85,7 @@ void EntitledLibraryBackend::AddLicensedGames(const StoredSession& session,
const auto found = looked_up_.find(app);
if (found == looked_up_.end() || found->second.empty()) continue;
GameSummary game{GameId::Steam(app), found->second, {}, {}, {}};
+ game.demo = demos_.count(app) != 0;
if (const auto icon = icons_.find(app); icon != icons_.end()) game.artwork_source = icon->second;
if (const auto added = acquisitions.acquired_at.find(app); added != acquisitions.acquired_at.end())
game.added_at_unix_seconds = added->second;
diff --git a/src/steam/backend/entitled_library.h b/src/steam/backend/entitled_library.h
index a9225e0..7dcdcd0 100644
--- a/src/steam/backend/entitled_library.h
+++ b/src/steam/backend/entitled_library.h
@@ -5,6 +5,7 @@
#include <mutex>
#include <unordered_map>
+#include <unordered_set>
namespace playden::steam {
@@ -12,8 +13,9 @@ namespace playden::steam {
// reference, both run in parallel and a CM failure is never fatal: games then simply lack a date.
// A CM logon rejection never reports revoked credentials.
// GetOwnedGames leaves out free-to-play games added to the library but never played. Licensed
-// packages none of whose apps are listed are looked up in PICS, and their games are added. Each
-// app is looked up once per run, so after the first load a refresh only asks about new licenses.
+// packages none of whose apps are listed are looked up in PICS, and their games and demos (marked)
+// are added. Each app is looked up once per run, so after the first load a refresh only asks about
+// new licenses.
class EntitledLibraryBackend final : public LibraryBackend {
public:
EntitledLibraryBackend(LibraryBackend& owned, AcquisitionSource& acquisitions)
@@ -34,10 +36,12 @@ class EntitledLibraryBackend final : public LibraryBackend {
AcquisitionSource& acquisitions_;
LicensedDepots* licensed_ = nullptr;
std::atomic<CmError> last_error_{CmError::kNone};
- // App ID -> its name when PICS calls it a game, empty when it is something else or undescribed.
+ // App ID -> its name when PICS calls it a game or a demo, empty when it is something else or
+ // undescribed. Demos are also in demos_.
std::mutex looked_up_mutex_;
std::unordered_map<std::uint32_t, std::string> looked_up_;
std::unordered_map<std::uint32_t, std::string> icons_;
+ std::unordered_set<std::uint32_t> demos_;
};
} // namespace playden::steam
diff --git a/tests/entitled_library_test.cpp b/tests/entitled_library_test.cpp
index a74ea36..11b9b1a 100644
--- a/tests/entitled_library_test.cpp
+++ b/tests/entitled_library_test.cpp
@@ -143,10 +143,33 @@ void LicensedFreeGamesAreAdded() {
assert(result.games.size() == 4 && acquisitions.app_info_requests.size() == 2);
}
+// A demo comes in a free package of its own, which GetOwnedGames leaves out. It is added and marked,
+// so the Library can hide it; games stay unmarked. A cached lookup keeps the mark.
+void LicensedDemosAreAddedAndMarked() {
+ Owned owned;
+ Acquisitions acquisitions;
+ acquisitions.result.package_apps = {{600, {60}}, {700, {70}}};
+ acquisitions.app_info = {{60, AppInfoText(60, "Synthetic Demo", "Demo")},
+ {70, AppInfoText(70, "Synthetic Free", "game")}};
+ EntitledLibraryBackend backend(owned, acquisitions);
+ std::atomic<bool> cancel{false};
+ for (int pass = 0; pass < 2; ++pass) {
+ const auto result = backend.Fetch(Session(), cancel);
+ assert(result.error == LibraryError::kNone && result.games.size() == 4);
+ const auto demo = std::find_if(result.games.begin(), result.games.end(),
+ [](const auto& game) { return game.id == SteamId(60); });
+ assert(demo != result.games.end() && demo->title == "Synthetic Demo" && demo->demo);
+ assert(std::none_of(result.games.begin(), result.games.end(),
+ [](const auto& game) { return game.demo && game.id != SteamId(60); }));
+ }
+ assert(acquisitions.app_info_requests.size() == 1);
+}
+
} // namespace
int main() {
LicensedFreeGamesAreAdded();
+ LicensedDemosAreAddedAndMarked();
DatesMergeIntoOwnedGames();
CmFailureIsNeverFatal();
OwnedFailureStopsTheCmSession();
diff --git a/tests/homebrew_browse_test.cpp b/tests/homebrew_browse_test.cpp
index c393712..e300199 100644
--- a/tests/homebrew_browse_test.cpp
+++ b/tests/homebrew_browse_test.cpp
@@ -75,6 +75,21 @@ void filtering_uses_real_fixture(const std::filesystem::path& fixtures)
check(filtered_games(state).size() == 2, "compatibility filter accepts Works and Playable only");
state.library.filters.clear();
+ const auto every_game = filtered_games(state).size();
+ auto& demo = *std::find_if(state.games.begin(), state.games.end(), [](const Game& game) { return game.id == SteamId(900010); });
+ demo.demo = true;
+ check(filtered_games(state).size() == every_game, "demos show with no filter");
+ state.library.filters = {"hide-demos"};
+ const auto without_demos = filtered_games(state);
+ check(without_demos.size() == every_game - 1 &&
+ std::none_of(without_demos.begin(), without_demos.end(), [](const Game* game) { return game->demo; }),
+ "hiding demos leaves the full games");
+ state.library.ratings[SteamId(900010)] = Compatibility::Works;
+ state.library.filters = {"compat-playable", "hide-demos"};
+ check(filtered_games(state).size() == 2, "hiding demos composes with Playable");
+ state.library.ratings.erase(SteamId(900010));
+ state.library.filters.clear();
+ demo.demo = false;
state.account().authentication = AuthState::SignedOut;
state.account().cache_available = false;
check(filtered_games(state).empty(), "signed out without cache has no browsable catalog");
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index a7f5685..2d93381 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -872,6 +872,7 @@ void live_filters_only_use_available_facts() {
for(const auto& unavailable:{"sort-recent-added","sort-install-size","filter-installed","filter-genre-adventure","filter-controller-full"})
check(std::find(actions.begin(),actions.end(),unavailable)==actions.end(),"unknown facts are not filter choices");
check(std::find(actions.begin(),actions.end(),"filter-compat-playable")!=actions.end(),"personal compatibility remains filterable");
+ check(std::find(actions.begin(),actions.end(),"filter-hide-demos")==actions.end(),"a library without demos has no Demos row");
// A CM acquisition date makes "Recently added" a real fact, sorted newest first.
auto dated=make_live();
@@ -890,6 +891,38 @@ void live_filters_only_use_available_facts() {
"newest acquisition first, undated last");
}
+// Demos show by default. Sort and filters › Demos hides them, the organization keeps that, and the
+// row stays while demos are hidden so they can be shown again.
+void live_demos_filter_defaults_on() {
+ auto model=make_live();
+ model.UpdateAccount({AuthState::SignedIn,"123","Synthetic",{},{},true});
+ auto demo=game(SteamId(43),"Synthetic Demo");demo.demo=true;
+ check(model.UpdateLibrary({{game(SteamId(42),"Synthetic"),demo},false,{},false,false,{}}),"library with a demo loaded");
+ check(model.state().games.back().demo && !model.state().games.front().demo,"demo mark projected");
+ check(model.action("r1") && model.visible_games().size()==2,"demos show by default");
+ check(model.action("triangle"),"live filter modal opens");
+ const auto* row=find_row(model,"filter-hide-demos");
+ check(row!=nullptr && row->title=="Demos" && row->kind==RowKind::Toggle && row->selected && row->value=="On","Demos is a toggle, on");
+ activate(model,"filter-hide-demos");
+ check(model.visible_games().size()==1 && model.visible_games().front()->id==SteamId(42),"turning Demos off hides the demo");
+ check(model.ExportOrganization().filters==std::set<std::string>{"hide-demos"},"hidden demos are saved");
+ check(model.action("triangle"),"filter modal opens again");
+ row=find_row(model,"filter-hide-demos");
+ check(row!=nullptr && !row->selected && row->value=="Off","Demos shows off");
+ activate(model,"filter-hide-demos");
+ check(model.visible_games().size()==2 && model.ExportOrganization().filters.empty(),"turning Demos on shows it again");
+
+ // Hidden demos the library no longer has can still be shown again.
+ auto restored=make_live();
+ restored.UpdateAccount({AuthState::SignedIn,"123","Synthetic",{},{},true});
+ check(restored.UpdateLibrary({{game(SteamId(42),"Synthetic")},false,{},false,false,{}}),"library without demos loaded");
+ auto organization=restored.ExportOrganization();organization.filters={"hide-demos"};
+ check(restored.ApplyOrganization(1,restored.BeginOrganizationLoad(1),organization),"saved organization applies");
+ check(restored.action("r1") && restored.action("triangle"),"filter modal opens");
+ row=find_row(restored,"filter-hide-demos");
+ check(row!=nullptr && !row->selected,"Demos stays listed while demos are hidden");
+}
+
// Sort and filters offers Refresh library: it asks the controller for Steam's current list and the
// Library stays on screen. While a refresh runs, the row waits.
void live_sort_sheet_refreshes_the_library() {
@@ -3071,6 +3104,7 @@ int main() {
live_saves_upload_all();
live_store_without_cloud_never_asks_the_cloud();
live_filters_only_use_available_facts();
+ live_demos_filter_defaults_on();
live_sort_sheet_refreshes_the_library();
continue_playing_more_keeps_the_chosen_sort();
live_empty_filter_keeps_the_signed_in_account();
diff --git a/tests/library_cache_test.cpp b/tests/library_cache_test.cpp
index a3d32d6..80641db 100644
--- a/tests/library_cache_test.cpp
+++ b/tests/library_cache_test.cpp
@@ -64,6 +64,16 @@ int main(){
Check(dated_restored.value().games[0].added_at_unix_seconds==1500000000u&&!dated_restored.value().games[1].added_at_unix_seconds,"acquisition date roundtrip; unknown stays unknown");
auto lossy_dated=dated;lossy_dated.schema_version=3;
Check(!cache.Save("76561198000000005",lossy_dated).ok(),"schema three cannot silently discard acquisition dates");
+ LibrarySnapshot demos{6,123461,{{SteamId(60),"Synthetic Demo","","",""},{SteamId(61),"Full Game","","",""}}};
+ demos.games[0].demo=true;demos.games[0].added_at_unix_seconds=1600000000;
+ Check(cache.Save("76561198000000006",demos).ok(),"save schema six demos");
+ auto demos_restored=cache.Load("76561198000000006");
+ Check(demos_restored.ok()&&demos_restored.value().schema_version==6,"load schema six");
+ Check(demos_restored.value().games[0].demo&&demos_restored.value().games[0].added_at_unix_seconds==1600000000u&&
+ !demos_restored.value().games[1].demo,"demo mark roundtrip; games stay unmarked");
+ auto lossy_demos=demos;lossy_demos.schema_version=5;
+ Check(!cache.Save("76561198000000006",lossy_demos).ok(),"schema five cannot silently discard demos");
+ Check(!dated_restored.value().games[0].demo,"older schemas hold no demos");
auto zero_dated=dated;zero_dated.games[0].added_at_unix_seconds=0;
Check(!cache.Save("76561198000000005",zero_dated).ok(),"zero acquisition date rejected");
auto future=partial;future.retrieved_at_unix_seconds=std::uint64_t{1}<<63;
diff --git a/tests/library_organization_test.cpp b/tests/library_organization_test.cpp
index caa5479..40aac75 100644
--- a/tests/library_organization_test.cpp
+++ b/tests/library_organization_test.cpp
@@ -352,11 +352,19 @@ void V2RoundTripsEveryStore() {
expected.ratings[kLocalGame] = playden::CompatibilityRating::kPlayable;
expected.notes[kLocalGame] = "Imported";
expected.selected_game_id = kLocalGame;
+ expected.filters.insert("hide-demos");
Check(playden::OrganizationSnapshotIsValid(expected), "a Local game is valid organization");
Check(store.Save(kDevice, expected).ok(), "device organization saves");
const auto restored = store.Load(kDevice);
Check(restored.ok() && restored.value() && *restored.value() == expected,
- "a Local game round trips in favorites, hidden, collections, ratings, notes and selection");
+ "a Local game round trips in favorites, hidden, collections, ratings, notes, selection and filters");
+ auto v1_demos = Example();
+ v1_demos.schema_version = 1;
+ v1_demos.filters = {"hide-demos"};
+ Check(!store.SaveV1(kFirstAccount, v1_demos).ok(), "version 1 cannot hold hidden demos");
+ auto three_filters = expected;
+ three_filters.filters.insert("controller-full");
+ Check(!store.Save(kDevice, three_filters).ok(), "version 2 holds at most Playable and hidden demos");
playden::OrganizationSnapshot unselected;
Check(store.Save(kDevice, unselected).ok(), "no selection saves");
const auto empty = store.Load(kDevice);
diff --git a/tests/library_sync_test.cpp b/tests/library_sync_test.cpp
index 11696cd..5d1b091 100644
--- a/tests/library_sync_test.cpp
+++ b/tests/library_sync_test.cpp
@@ -40,5 +40,7 @@ void ClearFailureAndShutdown(){ {Sessions s;Backend b;Cache c;c.snapshots[123]=S
void ShutdownCancelsNetwork(){Sessions s;Backend b;b.block=true;LibraryService service(b,s);service.Refresh(123,1);Wait(b.entered);service.Shutdown();assert(b.canceled&&service.Pump(8).empty());}
void GenerationsAndNoCache(){Sessions s;Backend b;LibraryService service(b,s);service.Invalidate(5);assert(service.Refresh(123,4)==0&&service.LoadCached(123,4)==0&&service.Clear(123,4)==0);assert(service.Refresh(123,5));auto e=Until(service,LibraryEventKind::kComplete);assert(e.back().cache_error==StorageError::kNone&&!e.back().cache_available);}
}
+// A library with demos is saved as schema 6, the first that can mark them; one without keeps the older schema.
+void DemosChooseTheCacheSchema(){Sessions s;Backend b;Cache c;LibraryService service(b,s,&c,[]{return std::uint64_t{2000};});service.Refresh(123,1);Until(service,LibraryEventKind::kComplete);{std::lock_guard<std::mutex>l(c.mutex);assert(c.snapshots[123].schema_version==4);}b.result.games[0].demo=true;service.Refresh(123,1);auto e=Until(service,LibraryEventKind::kComplete);assert(e.back().games[0].demo);std::lock_guard<std::mutex>l(c.mutex);assert(c.snapshots[123].schema_version==6&&c.snapshots[123].games[0].demo);}
void AcquisitionDatesCarryForward(){Sessions s;Backend b;Cache c;auto cached=Snapshot(1);cached.games[0].added_at_unix_seconds=900;c.snapshots[123]=cached;LibraryService service(b,s,&c,[]{return std::uint64_t{2000};});service.Refresh(123,1);auto e=Until(service,LibraryEventKind::kComplete);assert(e.back().games[0].added_at_unix_seconds==900u);{std::lock_guard<std::mutex>l(c.mutex);assert(c.snapshots[123].games[0].added_at_unix_seconds==900u);}b.result.games[0].added_at_unix_seconds=1000;service.Refresh(123,1);e=Until(service,LibraryEventKind::kComplete);assert(e.back().games[0].added_at_unix_seconds==1000u);}
-int main(){AcquisitionDatesCarryForward();CachedThenNetworkAndSave();OfflineCacheOnly();FailureAndSaveError();AccountSwitchDuringLoad();SessionIdentityPrecedesCache();ClearWaitsForSave();ClearFailureAndShutdown();ShutdownCancelsNetwork();GenerationsAndNoCache();}
+int main(){AcquisitionDatesCarryForward();DemosChooseTheCacheSchema();CachedThenNetworkAndSave();OfflineCacheOnly();FailureAndSaveError();AccountSwitchDuringLoad();SessionIdentityPrecedesCache();ClearWaitsForSave();ClearFailureAndShutdown();ShutdownCancelsNetwork();GenerationsAndNoCache();}