Skip to content

Commit

Permalink
Add support for Snap Steam installations
Browse files Browse the repository at this point in the history
Add support for Steam installations using Snap.

The Snap Steam is packaged by Canonical and Valve developers recommend
Steam's own `.deb` instead of the Snap. In any case, we should support
this though we should be wary in case some issues are caused by the Snap
version.
  • Loading branch information
Matoking committed Sep 7, 2024
1 parent f2f48e2 commit a1d1b77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Added
- `--cwd-app` flag to set working directory to the game's installation directory
- Add support Snap Steam installations

### Changed
- `protontricks -c` and `protontricks-launch` now use the current working directory instead of the game's installation directory. `--cwd-app` can be used to restore old behavior. Scripts can also `$STEAM_APP_PATH` environment variable to determine the game's installation directory; this has been supported (albeit undocumented) since 1.8.0.
Expand Down
13 changes: 12 additions & 1 deletion src/protontricks/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .config import get_config
from .flatpak import get_inaccessible_paths
from .util import get_cache_dir
from .steam import SNAP_STEAM_DIRS

APP_ICON_SIZE = (32, 32)

Expand Down Expand Up @@ -251,7 +252,17 @@ def _get_zenity_args():
"/com.valvesoftware.Steam/.local/share/Steam"
)
)
install_type = "Flatpak" if is_flatpak else "Native"
is_snap = any(
str(steam_path).endswith(snap_dir)
for snap_dir in SNAP_STEAM_DIRS
)

if is_flatpak:
install_type = "Flatpak"
elif is_snap:
install_type = "Snap"
else:
install_type = "Native"

cmd_input.append(f"{i+1}: {install_type} - {steam_path}")

Expand Down
14 changes: 12 additions & 2 deletions src/protontricks/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
".local/share/Steam",
]

SNAP_STEAM_DIRS = [
"snap/steam",
".snap/data/steam"
]

OS_RELEASE_PATHS = [
"/run/host/os-release", # The host file if we're inside a Flatpak sandbox
"/etc/os-release"
Expand Down Expand Up @@ -388,14 +393,19 @@ def has_runtime_dir(path):

candidates[(str(steam_path), str(steam_root_))] = True

# Check for Flatpak Steam separately and ensure we don't mix steam_root
# and steam_path from Flatpak and non-Flatpak installations of Steam.
# Check for Flatpak and Snap Steam separately and ensure we don't mix steam_root
# and steam_path from Flatpak/Snap and native installations of Steam.
steam_path = \
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam"
steam_path = steam_path.resolve()
if has_steamapps_dir(steam_path):
candidates[(str(steam_path), str(steam_path))] = True

for steam_dir in SNAP_STEAM_DIRS:
steam_path = (Path.home() / steam_dir).resolve()
if has_steamapps_dir(steam_path):
candidates[(str(steam_path), str(steam_path))] = True

for steam_path, _ in candidates.keys():
logger.info("Found Steam directory at %s", steam_path)

Expand Down

0 comments on commit a1d1b77

Please sign in to comment.