Add utility to guess Steam user ID

This commit is contained in:
Patrick Nicolas
2026-02-13 14:36:47 +01:00
parent c0a061b4be
commit 9af70baa58
4 changed files with 50 additions and 3 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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"
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "steam_app_info.h"
#include "steam_info.h"
#include <bit>
#include <cstring>
#include <fstream>
@@ -272,3 +272,48 @@ std::vector<wivrn::steam_shortcut> wivrn::read_steam_shortcuts(std::filesystem::
return res;
}
std::optional<uint32_t> 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<uint32_t> 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<char> key;
std::vector<char> value;
while (in)
{
std::getline(in, line);
key.resize(line.size());
value.resize(line.size());
if (sscanf(line.c_str(), "\t\"%ld\"", &current))
{
}
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 {};
}
}
@@ -42,4 +42,6 @@ struct steam_shortcut
std::unordered_map<uint32_t, steam_icon> read_steam_icons(std::filesystem::path path);
std::vector<steam_shortcut> read_steam_shortcuts(std::filesystem::path path);
std::optional<uint32_t> guess_steam_userid(std::filesystem::path steam_root);
} // namespace wivrn