2020-08-06 12:06:25 +02:00
|
|
|
# Code adapted from EzioTheDeadPoet / erri120:
|
|
|
|
|
# https://github.com/ModOrganizer2/modorganizer-basic_games/pull/5
|
|
|
|
|
|
2023-09-15 19:35:32 -05:00
|
|
|
import winreg
|
2020-08-06 12:06:25 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
2023-09-15 19:35:32 -05:00
|
|
|
def find_games() -> dict[str, Path]:
|
2020-08-06 12:06:25 +02:00
|
|
|
# List the game IDs from the registry:
|
2023-09-15 19:35:32 -05:00
|
|
|
game_ids: list[str] = []
|
2020-08-06 12:06:25 +02:00
|
|
|
try:
|
|
|
|
|
with winreg.OpenKey(
|
|
|
|
|
winreg.HKEY_LOCAL_MACHINE, r"Software\Wow6432Node\GOG.com\Games"
|
|
|
|
|
) as key:
|
|
|
|
|
nkeys = winreg.QueryInfoKey(key)[0]
|
|
|
|
|
for ik in range(nkeys):
|
|
|
|
|
game_key = winreg.EnumKey(key, ik)
|
|
|
|
|
if game_key.isdigit():
|
|
|
|
|
game_ids.append(game_key)
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
# For each game, query the path:
|
2023-09-15 19:35:32 -05:00
|
|
|
games: dict[str, Path] = {}
|
2020-08-06 12:06:25 +02:00
|
|
|
for game_id in game_ids:
|
|
|
|
|
try:
|
|
|
|
|
with winreg.OpenKey(
|
|
|
|
|
winreg.HKEY_LOCAL_MACHINE,
|
|
|
|
|
f"Software\\Wow6432Node\\GOG.com\\Games\\{game_id}",
|
|
|
|
|
) as key:
|
|
|
|
|
games[game_id] = Path(winreg.QueryValueEx(key, "path")[0])
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return games
|