Add function to list available Steam accounts

This commit is contained in:
Mathieu Comandon 2023-10-05 19:23:14 -07:00
parent 67e169ba7e
commit 0631f8714a
3 changed files with 35 additions and 26 deletions

View file

@ -85,6 +85,12 @@ class GameActions:
def get_displayed_entries(self):
"""Return a dictionary of actions that should be shown for a game"""
if steam_shortcut.vdf_file_exists():
has_steam_shortcut = steam_shortcut.shortcut_exists(self.game)
is_steam_game = steam_shortcut.is_steam_game(self.game)
else:
has_steam_shortcut = False
is_steam_game = False
return {
"add": not self.game.is_installed,
"duplicate": self.game.is_installed,
@ -115,9 +121,8 @@ class GameActions:
),
"steam-shortcut": (
self.game.is_installed
and steam_shortcut.vdf_file_exists()
and not steam_shortcut.shortcut_exists(self.game)
and not steam_shortcut.is_steam_game(self.game)
and not has_steam_shortcut
and not is_steam_game
),
"rm-desktop-shortcut": bool(
self.game.is_installed
@ -129,9 +134,8 @@ class GameActions:
),
"rm-steam-shortcut": bool(
self.game.is_installed
and steam_shortcut.vdf_file_exists()
and steam_shortcut.shortcut_exists(self.game)
and not steam_shortcut.is_steam_game(self.game)
and has_steam_shortcut
and not is_steam_game
),
"remove": self.is_game_removable,
"view": True,

View file

@ -1,5 +1,4 @@
"""Handle Steam configuration"""
import glob
import os
from collections import OrderedDict
@ -41,17 +40,6 @@ def search_in_steam_dirs(file):
return path
def search_recursive_in_steam_dirs(path_suffix):
"""Perform a recursive search based on glob and returns a
list of hits"""
results = []
for candidate in STEAM_DATA_DIRS:
glob_path = os.path.join(os.path.expanduser(candidate), path_suffix)
for path in glob.glob(glob_path):
results.append(path)
return results
def get_default_acf(appid, name):
"""Return a default configuration usable to
create a runnable game in Steam"""

View file

@ -10,24 +10,41 @@ from lutris.game import Game
from lutris.util import resources, system
from lutris.util.log import logger
from lutris.util.steam import vdf
from lutris.util.steam.config import search_recursive_in_steam_dirs
from lutris.util.steam.config import STEAM_DATA_DIRS
def get_config_path():
config_paths = search_recursive_in_steam_dirs("userdata/**/config/")
if not config_paths:
return None
return config_paths[0]
def get_steam_users():
"""Return the list of Steam users on this system and the base path where the settings are located"""
logger.debug("Fetching Steam users")
for steam_dir in STEAM_DATA_DIRS:
userdata_path = os.path.join(os.path.expanduser(steam_dir), "userdata")
if not os.path.exists(userdata_path):
continue
user_ids = [f for f in os.listdir(userdata_path) if f.isnumeric()]
if user_ids:
return userdata_path, user_ids
return "", []
def get_shortcuts_vdf_path():
def get_config_path() -> str:
userdatapath, user_ids = get_steam_users()
if not user_ids:
return ""
logger.warning("No Steam users found")
if len(user_ids) > 1:
logger.warning("More than 1 Steam user found, returning 1st (%s)", user_ids[0])
config_path = os.path.join(userdatapath, user_ids[0], "config")
return config_path
def get_shortcuts_vdf_path() -> str:
config_path = get_config_path()
if not config_path:
return None
return os.path.join(config_path, "shortcuts.vdf")
def vdf_file_exists():
def vdf_file_exists() -> bool:
try:
return bool(get_shortcuts_vdf_path())
except Exception as ex: