-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUplayGameIDs.py
71 lines (51 loc) · 2.57 KB
/
UplayGameIDs.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import logging
import os
import platform
import sys
if platform.system() == 'Windows':
import winreg
else:
logging.error("This code is intended for Windows operating systems only.")
sys.exit(1)
def get_uplay_game_ids():
try:
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as base_reg:
sub_key_path = r"SOFTWARE\WOW6432Node\Ubisoft\Launcher\Installs"
with winreg.OpenKey(base_reg, sub_key_path, 0, winreg.KEY_READ) as sub_key:
num_sub_keys, num_values, _ = winreg.QueryInfoKey(sub_key)
game_names = [] # List to store game names
for i in range(num_sub_keys):
try:
game_id = winreg.EnumKey(sub_key, i)
game_name_key_path = os.path.join(sub_key_path, game_id)
with winreg.OpenKey(base_reg, game_name_key_path, 0, winreg.KEY_READ) as game_name_key:
_, name, _ = winreg.EnumValue(game_name_key, 1)
game_path = os.path.dirname(name)
game_name = os.path.basename(game_path)
# Add combined game name and ID to the list
combined_name_id = f"Game: {game_name} - ID: {game_id}\n\tURL Scheme Handler (Shortcut): " \
f"\t\tuplay://launch/{game_id}/0\n"
print(combined_name_id)
logging.info(combined_name_id)
game_names.append(combined_name_id)
except OSError as e:
logging.error("Error while processing game ID:", e)
game_names.sort() # Sort the game_names list alphabetically
# Export the list of game names and IDs to a text file in the current working directory
export_game_names(game_names)
except Exception as e:
logging.error("Error accessing the Windows Registry:", e)
def export_game_names(game_names, file_path="UplayGameIDs.txt"):
try:
with open(file_path, "w") as file:
for game_name_id in game_names:
file.write(game_name_id + "\n")
logging.info(f"UplayGameIDs exported to {file_path}")
except Exception as e:
logging.error("Error exporting game names:", e)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, filename='app.log', filemode='w',
format='%(asctime)s - %(levelname)s - %(message)s')
# Call the function to execute the code
get_uplay_game_ids()
os.system("pause")