Skip to content

Commit

Permalink
Fix Steam detection for multiple Steam installs
Browse files Browse the repository at this point in the history
When both Flatpak and non-Flatpak versions of Steam are installed for
the same user, Steam installation detection might return two paths that
correspond to two different installations of Steam.

Ensure that the two paths returned by `find_steam_path` are the same
when Flatpak sandbox is active and Flatpak installation directory is
found.

Refs flathub/com.github.Matoking.protontricks#10
  • Loading branch information
Matoking committed Feb 5, 2022
1 parent 70470a9 commit 98ff61e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Fixed
- Fix Wine crash when the Steam application and Protontricks are running at the same time
- Fix Steam installation detection when both non-Flatpak and Flatpak versions of Steam are installed for the same user

## [1.7.0] - 2022-01-08
### Changed
Expand Down
23 changes: 15 additions & 8 deletions src/protontricks/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,22 @@ def has_runtime_dir(path):

return None, None

# If we're inside a Flatpak sandbox,
# prioritize Flatpak installation of Steam
steam_dirs_to_search = (
[".var/app/com.valvesoftware.Steam/data/Steam"] + COMMON_STEAM_DIRS
if is_flatpak_sandbox()
else COMMON_STEAM_DIRS
)
if is_flatpak_sandbox():
# If we're inside a Flatpak sandbox,
# prioritize Flatpak installation of Steam.
# In this case, ensure we don't mix steam_root and steam_path
# from Flatpak and non-Flatpak installations of Steam.
steam_path = \
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam"
if has_steamapps_dir(steam_path):
logger.info(
"Found Steam directory at %s. You can also define Steam "
"directory manually using $STEAM_DIR",
steam_path
)
return steam_path, steam_path

for steam_path in steam_dirs_to_search:
for steam_path in COMMON_STEAM_DIRS:
# The common Steam directories are found inside the home directory
steam_path = Path.home() / steam_path
if has_steamapps_dir(steam_path):
Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ def steam_root(steam_dir):
yield steam_dir.parent / "root"


@pytest.fixture(scope="function")
def flatpak_sandbox(monkeypatch, tmp_path):
"""
Fake Flatpak sandbox running under Flatpak 1.12.1
"""
flatpak_info_path = tmp_path / "flatpak-info"

flatpak_info_path.write_text(
"[Application]\n"
"name=fake.flatpak.Protontricks\n"
"\n"
"[Instance]\n"
"flatpak-version=1.12.1"
)

monkeypatch.setattr(
"protontricks.util.FLATPAK_INFO_PATH", str(flatpak_info_path)
)


@pytest.fixture(scope="function", autouse=True)
def steam_runtime_dir(steam_dir):
"""
Expand Down
24 changes: 24 additions & 0 deletions tests/test_steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,30 @@ def test_find_steam_path_env(
assert str(steam_paths[0]) == str(custom_path)
assert str(steam_paths[1]) == str(custom_path)

def test_find_steam_path_flatpak(
self, steam_dir, steam_root, tmp_path, home_dir, flatpak_sandbox,
monkeypatch):
"""
Ensure that `steam_path` and `steam_root` both point to the Flatpak
installation of Steam if Flatpak installation is found.
Regression test for flathub/com.github.Matoking.protontricks#10
"""
# Create a symlink to act as the Flatpak installation to keep the test
# simple.
steam_flatpak_dir = (
home_dir / ".var" / "app" / "com.valvesoftware.Steam" / "data"
/ "Steam"
)
steam_flatpak_dir.parent.mkdir(parents=True)
steam_flatpak_dir.symlink_to(steam_dir)

# Since Flatpak is enabled, both paths should point to Flatpak
steam_path, steam_root = find_steam_path()

assert str(steam_path) == str(steam_flatpak_dir)
assert str(steam_root) == str(steam_flatpak_dir)


class TestGetSteamApps:
def test_get_steam_apps_custom_proton(
Expand Down

0 comments on commit 98ff61e

Please sign in to comment.