From 9af70baa5803ed9979676aac9121d5fd4fcba2bb Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 26 Jan 2026 14:57:59 +0100 Subject: [PATCH] Add utility to guess Steam user ID --- common/CMakeLists.txt | 2 +- common/application.cpp | 2 +- .../{steam_app_info.cpp => steam_info.cpp} | 47 ++++++++++++++++++- .../utils/{steam_app_info.h => steam_info.h} | 2 + 4 files changed, 50 insertions(+), 3 deletions(-) rename common/utils/{steam_app_info.cpp => steam_info.cpp} (85%) rename common/utils/{steam_app_info.h => steam_info.h} (94%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7a86f39f..b66bcb71 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -42,7 +42,7 @@ if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) add_library(wivrn-common-server STATIC EXCLUDE_FROM_ALL utils/flatpak.cpp utils/xdg_icon_lookup.cpp - utils/steam_app_info.cpp + utils/steam_info.cpp utils/load_icon.cpp utils/ini.cpp application.cpp diff --git a/common/application.cpp b/common/application.cpp index 49c506a6..ad73054d 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -20,7 +20,7 @@ #include "application.h" #include "utils/flatpak.h" -#include "utils/steam_app_info.h" +#include "utils/steam_info.h" #include "utils/xdg_base_directory.h" #include "utils/xdg_icon_lookup.h" diff --git a/common/utils/steam_app_info.cpp b/common/utils/steam_info.cpp similarity index 85% rename from common/utils/steam_app_info.cpp rename to common/utils/steam_info.cpp index df1a68ed..f54c5420 100644 --- a/common/utils/steam_app_info.cpp +++ b/common/utils/steam_info.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "steam_app_info.h" +#include "steam_info.h" #include #include #include @@ -272,3 +272,48 @@ std::vector wivrn::read_steam_shortcuts(std::filesystem:: return res; } + +std::optional wivrn::guess_steam_userid(std::filesystem::path steam_root) +{ + auto localconfig = steam_root / "config/loginusers.vdf"; + if (not std::filesystem::exists(localconfig)) + return {}; + + try + { + std::optional res; + std::ifstream in{localconfig}; + std::string line; + std::getline(in, line); + if (strcasecmp(line.c_str(), "\"users\"")) + return {}; + + uint64_t current = 0; + + std::vector key; + std::vector value; + while (in) + { + std::getline(in, line); + + key.resize(line.size()); + value.resize(line.size()); + + if (sscanf(line.c_str(), "\t\"%ld\"", ¤t)) + { + } + else if (sscanf(line.c_str(), "\t\t%s\t%s", key.data(), value.data())) + { + if (strncasecmp(key.data(), "\"MostRecent\"", key.size()) == 0 and strncasecmp(value.data(), "\"1\"", value.size()) == 0) + res = current; // truncate to 32 bits + } + } + if (current and not res) + res = current; + return res; + } + catch (std::exception & e) + { + return {}; + } +} diff --git a/common/utils/steam_app_info.h b/common/utils/steam_info.h similarity index 94% rename from common/utils/steam_app_info.h rename to common/utils/steam_info.h index 640dcc93..b05a1d0c 100644 --- a/common/utils/steam_app_info.h +++ b/common/utils/steam_info.h @@ -42,4 +42,6 @@ struct steam_shortcut std::unordered_map read_steam_icons(std::filesystem::path path); std::vector read_steam_shortcuts(std::filesystem::path path); +std::optional guess_steam_userid(std::filesystem::path steam_root); + } // namespace wivrn