-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup_Dev_env.py
115 lines (91 loc) · 3.46 KB
/
Setup_Dev_env.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import winreg
class RegistryPaths:
"""Class to get all the paths of the registry keys.
Args:
hkey (Const): any one of the predefined HKEY_* constants]
{HKEY_CLASSES_ROOT,
HKEY_CURRENT_USER,
HKEY_LOCAL_MACHINE,
HKEY_USERS,
HKEY_CURRENT_CONFIG}
sub_key (str): the subkey to open
value_name (str): the value to retrieve
"""
def __init__(self, hkey=-1, sub_key=-1, value_name=-1):
self.HKEY_constants = hkey
self.sub_key = sub_key
self.value_name = value_name
def get_value_name(self):
return self.value_name
def set_value_name(self, value):
self.value_name = value
def __str__(self):
return f'{self.value_name}'
def get_root_key(self, hkey):
"""Return the root key for the given root key name.
Args:
hkey (str): the name of the root key
Returns:
Const: the root key with winreg module
"""
# Get the root key
if root_key == "HKEY_CLASSES_ROOT":
return winreg.HKEY_CLASSES_ROOT
elif root_key == "HKEY_CURRENT_USER":
return winreg.HKEY_CURRENT_USER
elif root_key == "HKEY_LOCAL_MACHINE":
return winreg.HKEY_LOCAL_MACHINE
elif root_key == "HKEY_USERS":
return winreg.HKEY_USERS
elif root_key == "HKEY_CURRENT_CONFIG":
return winreg.HKEY_CURRENT_CONFIG
else:
raise ValueError("Invalid root key: " + root_key)
@staticmethod
def get_registry_value(sub_key
, value_name):
"""Get a value from the Windows registry by passing the root key,
subkey, and value name.
Args:
HKEY_constants (Const): any one of the predefined HKEY_* constants]
{HKEY_CLASSES_ROOT,
HKEY_CURRENT_USER,
HKEY_LOCAL_MACHINE,
HKEY_USERS,
HKEY_CURRENT_CONFIG}
sub_key (str): the subkey to open
value_name (str): the value to retrieve
Returns:
str: the value from the registry
"""
# Open the registry key
try:
root_key = get_root_key(HKEY_constants)
# Open the registry key
registry_key = winreg.OpenKey(root_key, sub_key)
# Get the value
value, value_type = winreg.QueryValueEx(registry_key, value_name)
# Close the registry key
winreg.CloseKey(registry_key)
return value
except FileNotFoundError:
return "Not found"
keypath = r"Software\Mikero\ArmA3"
mik_tool_path = get_registry_value("HKEY_CURRENT_USER", keypath, "path")
print(mik_tool_path)
# get mikero tools path
# key = HKEY_CURRENT_USER\Software\Mikero\ArmA3p
# ValueName = path
# returns mikero tools path ie C:\Program Files (x86)\Mikero\DePboTools
# get arma3p (pdrive builder) path
# key = HKEY_CURRENT_USER\Software\Mikero\ArmA3p
# valuename = exe
# returns path and.cmd name ie C:\Program Files (x86)\Mikero\DePboTools\bin\ArmA3p.cmd
# get arma3 Addon Builder Path
# key = =HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\bohemia interactive\AddonBuilder
# valuename = path
# returns path ie D:\Games\Steam\steamapps\common\Arma 3 Tools\AddonBuilder
# get Arma3 path
# key = HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\bohemia interactive\ArmA3
# valuename = main
# returns path ie C:\SteamLibrary\steamapps\common\Arma 3