diff options
Diffstat (limited to 'libs/basic_games')
| -rw-r--r-- | libs/basic_games/epic_utils.py | 15 | ||||
| -rw-r--r-- | libs/basic_games/gog_utils.py | 43 | ||||
| -rw-r--r-- | libs/basic_games/steam_utils.py | 23 |
3 files changed, 78 insertions, 3 deletions
diff --git a/libs/basic_games/epic_utils.py b/libs/basic_games/epic_utils.py index 94ae6a9..afdccd5 100644 --- a/libs/basic_games/epic_utils.py +++ b/libs/basic_games/epic_utils.py @@ -87,6 +87,21 @@ def find_legendary_games( def find_heroic_games(errors: ErrorList | None = None): + # Linux: Heroic stores config in ~/.config/heroic/ (or Flatpak equivalent). + for candidate in ( + Path.home() / ".config" / "heroic" / "legendaryConfig", + Path.home() + / ".var" + / "app" + / "com.heroicgameslauncher.hgl" + / "config" + / "heroic" + / "legendaryConfig", + ): + if candidate.is_dir(): + return find_legendary_games(str(candidate), errors) + + # Windows fallback. return find_legendary_games( os.path.expandvars(r"%AppData%\heroic\legendaryConfig"), errors ) diff --git a/libs/basic_games/gog_utils.py b/libs/basic_games/gog_utils.py index e5e6d24..de66ec2 100644 --- a/libs/basic_games/gog_utils.py +++ b/libs/basic_games/gog_utils.py @@ -1,12 +1,50 @@ # Code adapted from EzioTheDeadPoet / erri120: # https://github.com/ModOrganizer2/modorganizer-basic_games/pull/5 +from __future__ import annotations + +import json +import sys import winreg from pathlib import Path +def _find_heroic_gog_games() -> dict[str, Path]: + """Detect GOG games installed via Heroic Launcher on Linux.""" + games: dict[str, Path] = {} + + for candidate in ( + Path.home() / ".config" / "heroic" / "gog_store" / "installed.json", + Path.home() + / ".var" + / "app" + / "com.heroicgameslauncher.hgl" + / "config" + / "heroic" + / "gog_store" + / "installed.json", + ): + if not candidate.is_file(): + continue + try: + with open(candidate, encoding="utf-8") as f: + data = json.load(f) + for game in data.get("installed", []): + app_name = game.get("appName", "") + install_path = game.get("install_path") or game.get("installPath", "") + if app_name and install_path: + games[str(app_name)] = Path(install_path) + except (json.JSONDecodeError, OSError) as e: + print( + f'Unable to parse Heroic GOG installed games from "{candidate}": {e}', + file=sys.stderr, + ) + + return games + + def find_games() -> dict[str, Path]: - # List the game IDs from the registry: + # List the game IDs from the registry (Windows): game_ids: list[str] = [] try: with winreg.OpenKey( @@ -18,7 +56,8 @@ def find_games() -> dict[str, Path]: if game_key.isdigit(): game_ids.append(game_key) except FileNotFoundError: - return {} + # Windows registry not available; try Heroic GOG on Linux. + return _find_heroic_gog_games() # For each game, query the path: games: dict[str, Path] = {} diff --git a/libs/basic_games/steam_utils.py b/libs/basic_games/steam_utils.py index d1d4a06..a3daeaf 100644 --- a/libs/basic_games/steam_utils.py +++ b/libs/basic_games/steam_utils.py @@ -148,7 +148,28 @@ def find_steam_path() -> Path | None: value = winreg.QueryValueEx(key, "SteamExe") return Path(value[0].replace("/", "\\")).parent except FileNotFoundError: - return None + pass + + # Linux: check common Steam install locations. + for candidate in ( + Path.home() / ".local" / "share" / "Steam", + Path.home() / ".steam" / "steam", + Path.home() + / ".var" + / "app" + / "com.valvesoftware.Steam" + / ".local" + / "share" + / "Steam", + Path.home() / "snap" / "steam" / "common" / ".local" / "share" / "Steam", + ): + if ( + candidate.is_dir() + and candidate.joinpath("steamapps", "libraryfolders.vdf").exists() + ): + return candidate + + return None def find_games() -> dict[str, Path]: |
