From 4c7d57bd6d0e1e0abde80dbe998b6daa7737b7e1 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 25 Oct 2026 15:53:52 +0100 Subject: [PATCH] Don't rely on steamapps.vrmanifest The file seems to no longer be updated by Steam. Instead, read installed games from libraryfolders.vdf, owned games from user's localconfig.vdf and data from appinfo.vdf --- common/application.cpp | 2 +- common/utils/steam_info.cpp | 252 +++++++++++++++++++----------------- common/utils/steam_info.h | 9 +- common/utils/vdf.cpp | 11 ++ common/utils/vdf.h | 2 + 5 files changed, 148 insertions(+), 128 deletions(-) diff --git a/common/application.cpp b/common/application.cpp index 54d863cc..833049fc 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -237,7 +237,7 @@ std::unordered_map list_applications() application{ .name = std::move(app.name), .exec = cmd + app.url, - .icon_path = steam.get_icon(app.appid), + .icon_path = std::move(app.icon), }); } } diff --git a/common/utils/steam_info.cpp b/common/utils/steam_info.cpp index a6fb3cc3..fe20e820 100644 --- a/common/utils/steam_info.cpp +++ b/common/utils/steam_info.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace { @@ -174,11 +175,46 @@ std::optional guess_steam_userid(const std::filesystem::path & root) } } -} // namespace - -void read_steam_icons(std::filesystem::path path, std::unordered_map & icons) +std::unordered_set installed_appids(std::filesystem::path root) { - binary_reader in{std::ifstream{path}}; + wivrn::vdf::root vdf(root / "config/libraryfolders.vdf"); + using values_t = std::vector; + if (vdf.key != "libraryfolders") + return {}; + + std::unordered_set res; + for (const auto & kv: std::get(vdf.value)) + { + for (const auto & [appid, _]: std::get(kv["apps"].value)) + { + uint64_t val; + if (std::from_chars(appid.data.begin(), appid.data.end(), val).ec == std::errc()) + res.emplace(val); + } + } + return res; +} + +std::unordered_set owned_appids(std::filesystem::path localconfig) +{ + wivrn::vdf::root localconfig_vdf(localconfig); + using values_t = std::vector; + if (localconfig_vdf.key != "UserLocalConfigStore") + return {}; + + std::unordered_set res; + for (const auto & [k, entries]: std::get(localconfig_vdf["Software"]["Valve"]["Steam"]["apps"].value)) + { + uint64_t val; + if (std::from_chars(k.data.begin(), k.data.end(), val).ec == std::errc()) + res.emplace(val); + } + return res; +} + +std::vector read_appinfo(std::filesystem::path root, std::unordered_set const & appids) +{ + binary_reader in{std::ifstream{root / "appcache/appinfo.vdf"}}; uint32_t magic = in.read(); if ((magic & 0xff'ff'ff'00) != 0x07'56'44'00) @@ -195,28 +231,73 @@ void read_steam_icons(std::filesystem::path path, std::unordered_map res; + enum section + { + common, + other, + }; struct V { - wivrn::steam::icon current{}; + std::vector section; + wivrn::steam::application current{}; + std::string clienticon; + std::string linuxclienticon; + bool VR = false; + + void clear() + { + section.clear(); + current.icon.clear(); + current.name.clear(); + current.url.clear(); + clienticon.clear(); + linuxclienticon.clear(); + VR = false; + section.push_back(section::other); + } void begin_dict(const std::string & key) { + if (key == "common") + section.push_back(section::common); + else + section.push_back(section::other); } void end_dict() { + section.pop_back(); } void on_string(const std::string & key, std::string && val) { - if (strcasecmp(key.c_str(), "clienticon") == 0) - current.clienticon = std::move(val); - else if (strcasecmp(key.c_str(), "linuxclienticon") == 0) - current.linuxclienticon = std::move(val); + switch (section.back()) + { + case common: + if (strcasecmp(key.c_str(), "clienticon") == 0) + clienticon = std::move(val); + else if (strcasecmp(key.c_str(), "linuxclienticon") == 0) + linuxclienticon = std::move(val); + else if (strcasecmp(key.c_str(), "name") == 0) + current.name[""] = std::move(val); + break; + case other: + break; + } } void on_uint32_t(const std::string & key, uint32_t val) { + switch (section.back()) + { + case common: + if (key == "openvrsupport") + VR = val; + break; + case other: + break; + } } - }; + } v; while (true) { @@ -237,25 +318,40 @@ void read_steam_icons(std::filesystem::path path, std::unordered_map & apps, - std::unordered_map & icons) + std::vector & apps) { if (not std::filesystem::exists(path)) return; @@ -270,11 +366,9 @@ void read_steam_shortcuts( struct V { std::vector & apps; - std::unordered_map & icons; int depth = 0; wivrn::steam::application current{}; - std::filesystem::path icon; bool VR = false; void begin_dict(const std::string & key) @@ -283,7 +377,6 @@ void read_steam_shortcuts( if (depth == 1) { current = decltype(current){}; - icon.clear(); VR = false; } } @@ -294,8 +387,6 @@ void read_steam_shortcuts( { if (VR) { - if (not icon.empty()) - icons[current.appid] = std::move(icon); // ¯\_(ツ)_/¯ current.appid = (current.appid << 32) | 0x02000000; current.url = std::format("steam://rungameid/{}", current.appid); @@ -310,7 +401,7 @@ void read_steam_shortcuts( if (strcasecmp(key.c_str(), "AppName") == 0) current.name[""] = std::move(val); else if (strcasecmp(key.c_str(), "icon") == 0 and not val.empty()) - icon = std::move(val); + current.icon = std::move(val); } } void on_uint32_t(const std::string & key, uint32_t val) @@ -323,7 +414,7 @@ void read_steam_shortcuts( VR = val; } } - } v{apps, icons}; + } v{apps}; read_dict(in, v); } @@ -371,64 +462,17 @@ std::vector wivrn::steam::find_installations() std::vector wivrn::steam::list_applications() { std::vector res; - // Steam games, from VR manifest - try - { - std::ifstream manifest(root / "config/steamapps.vrmanifest"); - nlohmann::json json = nlohmann::json::parse(manifest); - for (auto & i: json["applications"]) - { - try - { - // Steam games have an url launch - // shortcuts may be in this file, or may not... - if (i["launch_type"] != "url") - continue; + const auto installed = installed_appids(root); - std::string app_key = i["app_key"]; - const char prefix[] = "steam.app."; - if (not app_key.starts_with(prefix)) - continue; - - application app{ - .appid = stoul(app_key.substr(strlen(prefix))), - .url = i["url"], - }; - - for (auto [locale, items]: i["strings"].items()) - { - if (auto it = items.find("name"); it != items.end()) - app.name[locale] = *it; - } - - if (not app.name.contains("")) - { - auto it = app.name.find("en_us"); - if (it == app.name.end()) - it = app.name.begin(); - if (it != app.name.end()) - app.name[""] = it->second; - else - continue; // skip unnamed app - } - res.push_back(std::move(app)); - } - catch (std::exception & e) - { - std::cerr << "Failed to parse Steam VR manifest: " << e.what() << std::endl; - } - } - } - catch (std::exception & e) - { - } - - // Shortcuts if (default_userid) { try { - read_steam_shortcuts(root / "userdata" / std::to_string(*default_userid) / "config/shortcuts.vdf", res, shortcut_icons); + auto const & config = root / "userdata" / std::to_string(*default_userid) / "config"; + auto ids = owned_appids(config / "localconfig.vdf"); + std::erase_if(ids, [&](auto id) { return not installed.contains(id); }); + res = read_appinfo(root, ids); + read_steam_shortcuts(config / "shortcuts.vdf", res); } catch (std::exception & e) { @@ -441,7 +485,14 @@ std::vector wivrn::steam::list_applications() for (auto const & entry: std::filesystem::directory_iterator{root / "userdata", ec}) try { - read_steam_shortcuts(entry.path() / "config/shortcuts.vdf", res, shortcut_icons); + auto const & config = entry.path() / "config"; + auto ids = owned_appids(config / "localconfig.vdf"); + std::erase_if(ids, [&](auto id) { return not installed.contains(id); }); + auto tmp = read_appinfo(root, ids); + res.insert(res.end(), + std::make_move_iterator(tmp.begin()), + std::make_move_iterator(tmp.end())); + read_steam_shortcuts(config / "shortcuts.vdf", res); } catch (std::exception & e) { @@ -451,43 +502,6 @@ std::vector wivrn::steam::list_applications() return res; } -std::optional wivrn::steam::get_icon(uint64_t appid) -{ - if (appid & 0x02000000) - { - // Shortcut - auto it = shortcut_icons.find(appid >> 32); - if (it != shortcut_icons.end()) - return it->second; - return {}; - } - - if (not icons) - { - icons.emplace(); - try - { - read_steam_icons(root / "appcache/appinfo.vdf", *icons); - } - catch (...) - {} - } - auto it = icons->find(appid); - if (it == icons->end()) - return {}; - - auto icon_path = root / "steam/games" / (it->second.clienticon + ".ico"); - - if (std::filesystem::exists(icon_path)) - return icon_path; - - icon_path = root / "steam/games" / (it->second.linuxclienticon + ".zip"); - if (std::filesystem::exists(icon_path)) - return icon_path; - - return {}; -} - std::string wivrn::steam::get_steam_command() const { if (flatpak) diff --git a/common/utils/steam_info.h b/common/utils/steam_info.h index 0b20c570..1e2d4690 100644 --- a/common/utils/steam_info.h +++ b/common/utils/steam_info.h @@ -35,19 +35,13 @@ public: // localised names, with empty locale for default std::unordered_map name; std::string url; - }; - struct icon - { - std::string clienticon; - std::string linuxclienticon; + std::filesystem::path icon; }; private: std::filesystem::path root; bool flatpak; std::optional default_userid; - std::optional> icons; - std::unordered_map shortcut_icons; steam(std::filesystem::path root, bool flatpak); @@ -55,7 +49,6 @@ public: static std::vector find_installations(); std::vector list_applications(); - std::optional get_icon(uint64_t app_id); std::string get_steam_command() const; }; diff --git a/common/utils/vdf.cpp b/common/utils/vdf.cpp index b23c60d2..ccf202ae 100644 --- a/common/utils/vdf.cpp +++ b/common/utils/vdf.cpp @@ -19,6 +19,7 @@ #include "vdf.h" #include +#include #include namespace @@ -132,6 +133,16 @@ bool wivrn::vdf::string::operator==(const char * b) const return *b == '\0'; } +wivrn::vdf::keyvalue const & wivrn::vdf::keyvalue::operator[](const char * key) const +{ + for (auto const & kv: std::get>(value)) + { + if (kv.key == key) + return kv; + } + throw std::out_of_range{std::format("no key {}", key)}; +} + wivrn::vdf::root::root(const std::filesystem::path & file) { boost::iostreams::mapped_file in{file}; diff --git a/common/utils/vdf.h b/common/utils/vdf.h index 3be53223..c7eb71f1 100644 --- a/common/utils/vdf.h +++ b/common/utils/vdf.h @@ -40,6 +40,8 @@ struct keyvalue { string key; std::variant> value; + + keyvalue const & operator[](const char *) const; }; struct root : public keyvalue