Skip to content

Commit

Permalink
constants: Move valid Steam install check to is_valid_launcher_instal…
Browse files Browse the repository at this point in the history
…lation
  • Loading branch information
sonic2kk committed Feb 24, 2024
1 parent 19c3dcd commit d0e05ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
33 changes: 21 additions & 12 deletions pupgui2/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@
TEMP_DIR = os.path.join(os.getenv('XDG_CACHE_HOME'), 'tmp', 'pupgui2.a70200/') if os.path.exists(os.getenv('XDG_CACHE_HOME', '')) else '/tmp/pupgui2.a70200/'
HOME_DIR = os.path.expanduser('~')

# support different Steam root directories
# valid install dir should have config.vdf and libraryfolders.vdf, to ensure it is not an unused folder with correct directory structure
_POSSIBLE_STEAM_ROOTS = ['~/.local/share/Steam', '~/.steam/root', '~/.steam/steam', '~/.steam/debian-installation']
_STEAM_ROOT = _POSSIBLE_STEAM_ROOTS[0] # Default to '~/.local/share/Steam', but this is not guaranteed to exist
for steam_root in _POSSIBLE_STEAM_ROOTS:
ct_dir = os.path.join(os.path.expanduser(steam_root), 'config')
config_vdf = os.path.join(ct_dir, 'config.vdf')
libraryfolders_vdf = os.path.join(ct_dir, 'libraryfolders.vdf')
if os.path.exists(config_vdf) and os.path.exists(libraryfolders_vdf):
_STEAM_ROOT = steam_root
break
# support different Steam root directories, building paths relative to HOME_DIR (i.e. /home/gaben/.local/share/Steam)
_POSSIBLE_STEAM_ROOTS = [
os.path.join(HOME_DIR, _STEAM_ROOT) for _STEAM_ROOT in ['.local/share/Steam', '.steam/root', '.steam/steam', '.steam/debian-installation']
]

# Steam can be installled in any of the locations at '_POSSIBLE_STEAM_ROOTS' - usually only one, and the others (if they exist) are typically symlinks,
# i.e. '~/.steam/root' is usually a symlink to '~/.local/share/Steam'
# Use os.path.realpath to expand all _STEAM_ROOT paths and only add unique _STEAM_ROOT paths
# These paths may still not be valid installations however, as they could be leftother paths from an old Steam installation without the data files we need ('config.vdf' and 'libraryfolders.vdf')
# We catch this later on in util#is_valid_launcher_installation though
POSSIBLE_INSTALL_LOCATIONS = [
{'install_dir': f'{_STEAM_ROOT}/compatibilitytools.d/', 'display_name': 'Steam', 'launcher': 'steam', 'type': 'native', 'icon': 'steam', 'vdf_dir': f'{_STEAM_ROOT}/config'},
{
'install_dir': f'{os.path.realpath(_STEAM_ROOT)}/compatibilitytools.d/',
'display_name': 'Steam',
'launcher': 'steam',
'type': 'native',
'icon': 'steam',
'vdf_dir': f'{os.path.realpath(_STEAM_ROOT)}/config'
} for _STEAM_ROOT in _POSSIBLE_STEAM_ROOTS if os.path.exists(os.path.realpath(_STEAM_ROOT))
]

# Possible install locations for all other launchers, ensuring Steam paths are at the top of the list
POSSIBLE_INSTALL_LOCATIONS += [
{'install_dir': '~/.var/app/com.valvesoftware.Steam/data/Steam/compatibilitytools.d/', 'display_name': 'Steam Flatpak', 'launcher': 'steam', 'type': 'flatpak', 'icon': 'steam', 'vdf_dir': '~/.var/app/com.valvesoftware.Steam/.local/share/Steam/config'},
{'install_dir': '~/snap/steam/common/.steam/root/compatibilitytools.d/', 'display_name': 'Steam Snap', 'launcher': 'steam', 'type': 'snap', 'icon': 'steam', 'vdf_dir': '~/snap/steam/common/.steam/root/config'},
{'install_dir': '~/.local/share/lutris/runners/wine/', 'display_name': 'Lutris', 'launcher': 'lutris', 'type': 'native', 'icon': 'lutris', 'config_dir': '~/.config/lutris'},
Expand Down
6 changes: 4 additions & 2 deletions pupgui2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ def available_install_directories() -> List[str]:
available_dirs = []
for loc in POSSIBLE_INSTALL_LOCATIONS:
install_dir = os.path.expanduser(loc['install_dir'])
if is_valid_launcher_installation(loc):
# POSSIBLE_INSTALL_LOCATIONS may contain duplicate paths, so only add unique paths to available_dirs
# This avoids adding symlinked Steam paths
if is_valid_launcher_installation(loc) and not install_dir in available_dirs:
available_dirs.append(install_dir)
install_dir = config_custom_install_location().get('install_dir')
if install_dir and os.path.exists(install_dir):
if install_dir and os.path.exists(install_dir) and not install_dir in available_dirs:
available_dirs.append(install_dir)
return available_dirs

Expand Down

0 comments on commit d0e05ce

Please sign in to comment.