Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions pysteam/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,33 @@
# See also the `get_steam()` function, which will return a valid Steam
# instance for the current platform.

def default_osx_userdata_path():
return os.path.join(
os.path.expanduser("~"),
"Library",
"Application Support",
"Steam",
"userdata"
)
def default_osx_userdata_paths():
return [
os.path.join(
os.path.expanduser("~"),
"Library",
"Application Support",
"Steam",
"userdata"
)
]

def default_linux_userdata_path():
return os.path.join(
os.path.expanduser("~"),
".local",
"share",
"Steam",
"userdata"
)
def default_linux_userdata_paths():
return [
os.path.join(
os.path.expanduser("~"),
".local",
"share",
"Steam",
"userdata"
),
os.path.join(
os.path.expanduser("~"),
".steam",
"steam",
"userdata"
)
]

# =============================================================================
# User-specific paths
Expand Down
26 changes: 14 additions & 12 deletions pysteam/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,35 @@

from model import LocalUserContext, Steam

def _resolve_userdata_path(paths):
"""
Helper function which checks if the potential userdata directory exists
and returns a new Steam instance with that userdata directory if it does.
If the directory doesnt exist it returns None instead
"""
if not paths: return None
return next((Steam(path) for path in paths if os.path.exists(path)), None)

def get_steam():
"""
Returns a Steam object representing the current Steam installation on the
users computer. If the user doesn't have Steam installed, returns None.
"""
# Helper function which checks if the potential userdata directory exists
# and returns a new Steam instance with that userdata directory if it does.
# If the directory doesnt exist it returns None instead
helper = lambda udd: Steam(udd) if os.path.exists(udd) else None

# For both OS X and Linux, Steam stores it's userdata in a consistent
# location.
# For both OS X and Linux, Steam stores it's userdata in a few consistent
# locations.
plat = platform.system()
if plat == 'Darwin':
return helper(paths.default_osx_userdata_path())
return _resolve_userdata_path(paths.default_osx_userdata_paths())
if plat == 'Linux':
return helper(paths.default_linux_userdata_path())
return _resolve_userdata_path(paths.default_linux_userdata_paths())

# Windows is a bit trickier. The userdata directory is stored in the Steam
# installation directory, meaning that theoretically it could be anywhere.
# Luckily, Valve stores the installation directory in the registry, so its
# still possible for us to figure out automatically
if plat == 'Windows':
possible_dir = winutils.find_userdata_directory()
# Unlike the others, `possible_dir` might be None (if something odd
# happened with the registry)
return helper(possible_dir) if possible_dir is not None else None
return _resolve_userdata_path([possible_dir])
# This should never be hit. Windows, OS X, and Linux should be the only
# supported platforms.
# TODO: Add logging here so that the user (developer) knows that something
Expand Down