-
Notifications
You must be signed in to change notification settings - Fork 55
/
gog_utils.py
35 lines (30 loc) · 1.07 KB
/
gog_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Code adapted from EzioTheDeadPoet / erri120:
# https://github.com/ModOrganizer2/modorganizer-basic_games/pull/5
import winreg
from pathlib import Path
def find_games() -> dict[str, Path]:
# List the game IDs from the registry:
game_ids: list[str] = []
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:
games: dict[str, Path] = {}
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