Skip to content

Commit 98ff61e

Browse files
committed
Fix Steam detection for multiple Steam installs
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
1 parent 70470a9 commit 98ff61e

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
## [Unreleased]
99
### Fixed
1010
- Fix Wine crash when the Steam application and Protontricks are running at the same time
11+
- Fix Steam installation detection when both non-Flatpak and Flatpak versions of Steam are installed for the same user
1112

1213
## [1.7.0] - 2022-01-08
1314
### Changed

src/protontricks/steam.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,22 @@ def has_runtime_dir(path):
302302

303303
return None, None
304304

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

313-
for steam_path in steam_dirs_to_search:
320+
for steam_path in COMMON_STEAM_DIRS:
314321
# The common Steam directories are found inside the home directory
315322
steam_path = Path.home() / steam_path
316323
if has_steamapps_dir(steam_path):

tests/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ def steam_root(steam_dir):
9494
yield steam_dir.parent / "root"
9595

9696

97+
@pytest.fixture(scope="function")
98+
def flatpak_sandbox(monkeypatch, tmp_path):
99+
"""
100+
Fake Flatpak sandbox running under Flatpak 1.12.1
101+
"""
102+
flatpak_info_path = tmp_path / "flatpak-info"
103+
104+
flatpak_info_path.write_text(
105+
"[Application]\n"
106+
"name=fake.flatpak.Protontricks\n"
107+
"\n"
108+
"[Instance]\n"
109+
"flatpak-version=1.12.1"
110+
)
111+
112+
monkeypatch.setattr(
113+
"protontricks.util.FLATPAK_INFO_PATH", str(flatpak_info_path)
114+
)
115+
116+
97117
@pytest.fixture(scope="function", autouse=True)
98118
def steam_runtime_dir(steam_dir):
99119
"""

tests/test_steam.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,30 @@ def test_find_steam_path_env(
388388
assert str(steam_paths[0]) == str(custom_path)
389389
assert str(steam_paths[1]) == str(custom_path)
390390

391+
def test_find_steam_path_flatpak(
392+
self, steam_dir, steam_root, tmp_path, home_dir, flatpak_sandbox,
393+
monkeypatch):
394+
"""
395+
Ensure that `steam_path` and `steam_root` both point to the Flatpak
396+
installation of Steam if Flatpak installation is found.
397+
398+
Regression test for flathub/com.github.Matoking.protontricks#10
399+
"""
400+
# Create a symlink to act as the Flatpak installation to keep the test
401+
# simple.
402+
steam_flatpak_dir = (
403+
home_dir / ".var" / "app" / "com.valvesoftware.Steam" / "data"
404+
/ "Steam"
405+
)
406+
steam_flatpak_dir.parent.mkdir(parents=True)
407+
steam_flatpak_dir.symlink_to(steam_dir)
408+
409+
# Since Flatpak is enabled, both paths should point to Flatpak
410+
steam_path, steam_root = find_steam_path()
411+
412+
assert str(steam_path) == str(steam_flatpak_dir)
413+
assert str(steam_root) == str(steam_flatpak_dir)
414+
391415

392416
class TestGetSteamApps:
393417
def test_get_steam_apps_custom_proton(

0 commit comments

Comments
 (0)