Skip to content

Commit

Permalink
Adjust library folder path if Flatpak Steam
Browse files Browse the repository at this point in the history
"~/.local/share/Steam" corresponds to a different directory inside a
Steam Flatpak. Ensure Protontricks doesn't mix them and try to look for
Flatpak Steam apps in the non-Flatpak installation directory.

Refs flathub/com.github.Matoking.protontricks#10
  • Loading branch information
Matoking committed Jan 29, 2022
1 parent 3e6dc84 commit 53f4814
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 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
- Fix Protontricks crash when Proton installation is incomplete
- Fix Protontricks crash when both Flatpak and non-Flatpak versions of Steam are installed

## [1.7.0] - 2022-01-08
### Changed
Expand Down
22 changes: 20 additions & 2 deletions src/protontricks/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,29 @@ def parse_library_folders(data):
for value in library_entries:
if isinstance(value, dict):
# Library data is stored in a dict in newer Steam releases
library_folders.append(Path(value["path"]))
path = Path(value["path"])
else:
# Older releases just store the library path as a string
# and nothing else
library_folders.append(Path(value))
path = Path(value)

xdg_steam_path = Path.home() / ".local/share/Steam"
flatpak_steam_path = \
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam"

is_library_folder_xdg_steam = str(path) == str(xdg_steam_path)
is_flatpak_steam = str(steam_path) == str(flatpak_steam_path)

# Adjust the path if the library folder is "~/.local/share/Steam"
# and we're looking for library folders in
# "~/.var/app/com.valvesoftware.Steam"
# This is because ~/.local/share/Steam inside a Steam Flatpak
# sandbox corresponds to a different location, and we need to
# adjust for that.
if is_library_folder_xdg_steam and is_flatpak_steam:
path = flatpak_steam_path

library_folders.append(path)

logger.info(
"Found %d Steam library folders", len(library_folders)
Expand Down
36 changes: 36 additions & 0 deletions tests/test_steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,42 @@ def test_get_steam_lib_paths_duplicate_paths(
assert steam_dir in library_paths
assert library_dir in library_paths

def test_get_steam_lib_paths_adjust_flatpak_steam_path(
self, steam_dir, steam_library_factory, home_dir):
"""
Retrieve Steam library folders and ensure that the
"~/.local/share/Steam" path is adjusted in the library folder
configuration file if Steam is installed using Flatpak.
Regression test for flathub/com.github.Matoking.protontricks#10
"""
flatpak_steam_dir = \
home_dir / ".var/app/com.valvesoftware.Steam/data/Steam"
flatpak_steam_dir.mkdir(parents=True)
steam_dir.rename(str(flatpak_steam_dir))
shutil.rmtree(str(home_dir / ".local"))

libraryfolders_data = {
"libraryfolders": {
"0": {
"path": str(home_dir / ".local/share/Steam")
}
}
}
(flatpak_steam_dir / "steamapps/libraryfolders.vdf").write_text(
vdf.dumps(libraryfolders_data), "utf-8"
)

library_paths = get_steam_lib_paths(
home_dir / ".var/app/com.valvesoftware.Steam/data/Steam"
)
# The only library folder should point under "~/.var/app", even if the
# path in the configuration file is "~/.local/share/Steam".
# This needs to be done to adjust for the different path in the
# Steam Flatpak sandbox.
assert len(library_paths) == 1
assert str(library_paths[0]) == str(flatpak_steam_dir)


class TestFindAppidProtonPrefix:
def test_find_appid_proton_prefix_steamapps_case(
Expand Down

0 comments on commit 53f4814

Please sign in to comment.