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
This commit is contained in:
@@ -237,7 +237,7 @@ std::unordered_map<std::string, application> list_applications()
|
|||||||
application{
|
application{
|
||||||
.name = std::move(app.name),
|
.name = std::move(app.name),
|
||||||
.exec = cmd + app.url,
|
.exec = cmd + app.url,
|
||||||
.icon_path = steam.get_icon(app.appid),
|
.icon_path = std::move(app.icon),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+133
-119
@@ -27,6 +27,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -174,11 +175,46 @@ std::optional<uint32_t> guess_steam_userid(const std::filesystem::path & root)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
std::unordered_set<uint64_t> installed_appids(std::filesystem::path root)
|
||||||
|
|
||||||
void read_steam_icons(std::filesystem::path path, std::unordered_map<uint32_t, wivrn::steam::icon> & icons)
|
|
||||||
{
|
{
|
||||||
binary_reader in{std::ifstream{path}};
|
wivrn::vdf::root vdf(root / "config/libraryfolders.vdf");
|
||||||
|
using values_t = std::vector<wivrn::vdf::keyvalue>;
|
||||||
|
if (vdf.key != "libraryfolders")
|
||||||
|
return {};
|
||||||
|
|
||||||
|
std::unordered_set<uint64_t> res;
|
||||||
|
for (const auto & kv: std::get<values_t>(vdf.value))
|
||||||
|
{
|
||||||
|
for (const auto & [appid, _]: std::get<values_t>(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<uint64_t> owned_appids(std::filesystem::path localconfig)
|
||||||
|
{
|
||||||
|
wivrn::vdf::root localconfig_vdf(localconfig);
|
||||||
|
using values_t = std::vector<wivrn::vdf::keyvalue>;
|
||||||
|
if (localconfig_vdf.key != "UserLocalConfigStore")
|
||||||
|
return {};
|
||||||
|
|
||||||
|
std::unordered_set<uint64_t> res;
|
||||||
|
for (const auto & [k, entries]: std::get<values_t>(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<wivrn::steam::application> read_appinfo(std::filesystem::path root, std::unordered_set<uint64_t> const & appids)
|
||||||
|
{
|
||||||
|
binary_reader in{std::ifstream{root / "appcache/appinfo.vdf"}};
|
||||||
|
|
||||||
uint32_t magic = in.read<uint32_t>();
|
uint32_t magic = in.read<uint32_t>();
|
||||||
if ((magic & 0xff'ff'ff'00) != 0x07'56'44'00)
|
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<uint32_t, w
|
|||||||
string_table = in.string_table();
|
string_table = in.string_table();
|
||||||
string_table_ptr = &string_table;
|
string_table_ptr = &string_table;
|
||||||
}
|
}
|
||||||
|
std::vector<wivrn::steam::application> res;
|
||||||
|
|
||||||
|
enum section
|
||||||
|
{
|
||||||
|
common,
|
||||||
|
other,
|
||||||
|
};
|
||||||
struct V
|
struct V
|
||||||
{
|
{
|
||||||
wivrn::steam::icon current{};
|
std::vector<enum section> 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)
|
void begin_dict(const std::string & key)
|
||||||
{
|
{
|
||||||
|
if (key == "common")
|
||||||
|
section.push_back(section::common);
|
||||||
|
else
|
||||||
|
section.push_back(section::other);
|
||||||
}
|
}
|
||||||
void end_dict()
|
void end_dict()
|
||||||
{
|
{
|
||||||
|
section.pop_back();
|
||||||
}
|
}
|
||||||
void on_string(const std::string & key, std::string && val)
|
void on_string(const std::string & key, std::string && val)
|
||||||
{
|
{
|
||||||
if (strcasecmp(key.c_str(), "clienticon") == 0)
|
switch (section.back())
|
||||||
current.clienticon = std::move(val);
|
{
|
||||||
else if (strcasecmp(key.c_str(), "linuxclienticon") == 0)
|
case common:
|
||||||
current.linuxclienticon = std::move(val);
|
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)
|
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)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -237,25 +318,40 @@ void read_steam_icons(std::filesystem::path path, std::unordered_map<uint32_t, w
|
|||||||
+ 4 // checksum
|
+ 4 // checksum
|
||||||
+ 1 // type
|
+ 1 // type
|
||||||
);
|
);
|
||||||
try
|
if (appids.contains(app_id))
|
||||||
{
|
{
|
||||||
V v;
|
try
|
||||||
read_dict(in, v, string_table_ptr);
|
{
|
||||||
if (not(v.current.clienticon.empty() and v.current.linuxclienticon.empty()))
|
v.clear();
|
||||||
icons.emplace(app_id, std::move(v.current));
|
read_dict(in, v, string_table_ptr);
|
||||||
}
|
if (v.VR)
|
||||||
catch (...)
|
{
|
||||||
{
|
auto & item = res.emplace_back(std::move(v.current));
|
||||||
// Ignore errors
|
item.appid = app_id;
|
||||||
|
item.url = std::format("steam://launch/{}/VR", app_id);
|
||||||
|
|
||||||
|
if (auto icon_path = root / "steam/games" / (v.clienticon + ".ico"); std::filesystem::exists(icon_path))
|
||||||
|
item.icon = icon_path;
|
||||||
|
|
||||||
|
else if (auto icon_path = root / "steam/games" / (v.linuxclienticon + ".zip"); std::filesystem::exists(icon_path))
|
||||||
|
item.icon = icon_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
// Ignore errors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
in.seekg(pos + size_data);
|
in.seekg(pos + size_data);
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void read_steam_shortcuts(
|
void read_steam_shortcuts(
|
||||||
const std::filesystem::path & path,
|
const std::filesystem::path & path,
|
||||||
std::vector<wivrn::steam::application> & apps,
|
std::vector<wivrn::steam::application> & apps)
|
||||||
std::unordered_map<uint32_t, std::filesystem::path> & icons)
|
|
||||||
{
|
{
|
||||||
if (not std::filesystem::exists(path))
|
if (not std::filesystem::exists(path))
|
||||||
return;
|
return;
|
||||||
@@ -270,11 +366,9 @@ void read_steam_shortcuts(
|
|||||||
struct V
|
struct V
|
||||||
{
|
{
|
||||||
std::vector<wivrn::steam::application> & apps;
|
std::vector<wivrn::steam::application> & apps;
|
||||||
std::unordered_map<uint32_t, std::filesystem::path> & icons;
|
|
||||||
|
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
wivrn::steam::application current{};
|
wivrn::steam::application current{};
|
||||||
std::filesystem::path icon;
|
|
||||||
bool VR = false;
|
bool VR = false;
|
||||||
|
|
||||||
void begin_dict(const std::string & key)
|
void begin_dict(const std::string & key)
|
||||||
@@ -283,7 +377,6 @@ void read_steam_shortcuts(
|
|||||||
if (depth == 1)
|
if (depth == 1)
|
||||||
{
|
{
|
||||||
current = decltype(current){};
|
current = decltype(current){};
|
||||||
icon.clear();
|
|
||||||
VR = false;
|
VR = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,8 +387,6 @@ void read_steam_shortcuts(
|
|||||||
{
|
{
|
||||||
if (VR)
|
if (VR)
|
||||||
{
|
{
|
||||||
if (not icon.empty())
|
|
||||||
icons[current.appid] = std::move(icon);
|
|
||||||
// ¯\_(ツ)_/¯
|
// ¯\_(ツ)_/¯
|
||||||
current.appid = (current.appid << 32) | 0x02000000;
|
current.appid = (current.appid << 32) | 0x02000000;
|
||||||
current.url = std::format("steam://rungameid/{}", current.appid);
|
current.url = std::format("steam://rungameid/{}", current.appid);
|
||||||
@@ -310,7 +401,7 @@ void read_steam_shortcuts(
|
|||||||
if (strcasecmp(key.c_str(), "AppName") == 0)
|
if (strcasecmp(key.c_str(), "AppName") == 0)
|
||||||
current.name[""] = std::move(val);
|
current.name[""] = std::move(val);
|
||||||
else if (strcasecmp(key.c_str(), "icon") == 0 and not val.empty())
|
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)
|
void on_uint32_t(const std::string & key, uint32_t val)
|
||||||
@@ -323,7 +414,7 @@ void read_steam_shortcuts(
|
|||||||
VR = val;
|
VR = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} v{apps, icons};
|
} v{apps};
|
||||||
|
|
||||||
read_dict(in, v);
|
read_dict(in, v);
|
||||||
}
|
}
|
||||||
@@ -371,64 +462,17 @@ std::vector<wivrn::steam> wivrn::steam::find_installations()
|
|||||||
std::vector<wivrn::steam::application> wivrn::steam::list_applications()
|
std::vector<wivrn::steam::application> wivrn::steam::list_applications()
|
||||||
{
|
{
|
||||||
std::vector<wivrn::steam::application> res;
|
std::vector<wivrn::steam::application> res;
|
||||||
// Steam games, from VR manifest
|
const auto installed = installed_appids(root);
|
||||||
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;
|
|
||||||
|
|
||||||
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)
|
if (default_userid)
|
||||||
{
|
{
|
||||||
try
|
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)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
@@ -441,7 +485,14 @@ std::vector<wivrn::steam::application> wivrn::steam::list_applications()
|
|||||||
for (auto const & entry: std::filesystem::directory_iterator{root / "userdata", ec})
|
for (auto const & entry: std::filesystem::directory_iterator{root / "userdata", ec})
|
||||||
try
|
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)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
@@ -451,43 +502,6 @@ std::vector<wivrn::steam::application> wivrn::steam::list_applications()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::filesystem::path> 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
|
std::string wivrn::steam::get_steam_command() const
|
||||||
{
|
{
|
||||||
if (flatpak)
|
if (flatpak)
|
||||||
|
|||||||
@@ -35,19 +35,13 @@ public:
|
|||||||
// localised names, with empty locale for default
|
// localised names, with empty locale for default
|
||||||
std::unordered_map<std::string, std::string> name;
|
std::unordered_map<std::string, std::string> name;
|
||||||
std::string url;
|
std::string url;
|
||||||
};
|
std::filesystem::path icon;
|
||||||
struct icon
|
|
||||||
{
|
|
||||||
std::string clienticon;
|
|
||||||
std::string linuxclienticon;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::filesystem::path root;
|
std::filesystem::path root;
|
||||||
bool flatpak;
|
bool flatpak;
|
||||||
std::optional<uint32_t> default_userid;
|
std::optional<uint32_t> default_userid;
|
||||||
std::optional<std::unordered_map<uint32_t, icon>> icons;
|
|
||||||
std::unordered_map<uint32_t, std::filesystem::path> shortcut_icons;
|
|
||||||
|
|
||||||
steam(std::filesystem::path root, bool flatpak);
|
steam(std::filesystem::path root, bool flatpak);
|
||||||
|
|
||||||
@@ -55,7 +49,6 @@ public:
|
|||||||
static std::vector<steam> find_installations();
|
static std::vector<steam> find_installations();
|
||||||
|
|
||||||
std::vector<application> list_applications();
|
std::vector<application> list_applications();
|
||||||
std::optional<std::filesystem::path> get_icon(uint64_t app_id);
|
|
||||||
std::string get_steam_command() const;
|
std::string get_steam_command() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "vdf.h"
|
#include "vdf.h"
|
||||||
|
|
||||||
#include <boost/iostreams/device/mapped_file.hpp>
|
#include <boost/iostreams/device/mapped_file.hpp>
|
||||||
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -132,6 +133,16 @@ bool wivrn::vdf::string::operator==(const char * b) const
|
|||||||
return *b == '\0';
|
return *b == '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wivrn::vdf::keyvalue const & wivrn::vdf::keyvalue::operator[](const char * key) const
|
||||||
|
{
|
||||||
|
for (auto const & kv: std::get<std::vector<keyvalue>>(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)
|
wivrn::vdf::root::root(const std::filesystem::path & file)
|
||||||
{
|
{
|
||||||
boost::iostreams::mapped_file in{file};
|
boost::iostreams::mapped_file in{file};
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ struct keyvalue
|
|||||||
{
|
{
|
||||||
string key;
|
string key;
|
||||||
std::variant<string, std::vector<keyvalue>> value;
|
std::variant<string, std::vector<keyvalue>> value;
|
||||||
|
|
||||||
|
keyvalue const & operator[](const char *) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct root : public keyvalue
|
struct root : public keyvalue
|
||||||
|
|||||||
Reference in New Issue
Block a user