aboutsummaryrefslogtreecommitdiff
path: root/modules/mono/mono_reg_utils.py
diff options
context:
space:
mode:
authorIgnacio Etcheverry2017-10-02 23:24:00 +0200
committerIgnacio Etcheverry2017-10-03 00:01:26 +0200
commite36fb95c50ce0cd0ab9621afe668332895712c2e (patch)
tree5f146ad19fa9364c66fae002b0210a6a967b5e6e /modules/mono/mono_reg_utils.py
parent29b44801b2e9693c5d19d3e4fbb708af367c4904 (diff)
downloadgodot-e36fb95c50ce0cd0ab9621afe668332895712c2e.tar.gz
godot-e36fb95c50ce0cd0ab9621afe668332895712c2e.tar.zst
godot-e36fb95c50ce0cd0ab9621afe668332895712c2e.zip
Diffstat (limited to 'modules/mono/mono_reg_utils.py')
-rw-r--r--modules/mono/mono_reg_utils.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/modules/mono/mono_reg_utils.py b/modules/mono/mono_reg_utils.py
new file mode 100644
index 000000000..6f1620ff4
--- /dev/null
+++ b/modules/mono/mono_reg_utils.py
@@ -0,0 +1,54 @@
+import os
+
+if os.name == 'nt':
+ import _winreg as winreg
+
+
+def _reg_open_key(key, subkey):
+ try:
+ return winreg.OpenKey(key, subkey)
+ except (WindowsError, EnvironmentError) as e:
+ import platform
+ if platform.architecture()[0] == '32bit':
+ bitness_sam = winreg.KEY_WOW64_64KEY
+ else:
+ bitness_sam = winreg.KEY_WOW64_32KEY
+ return winreg.OpenKey(key, subkey, 0, winreg.KEY_READ | bitness_sam)
+
+
+def _find_mono_in_reg(subkey):
+ try:
+ with _reg_open_key(winreg.HKEY_LOCAL_MACHINE, subkey) as hKey:
+ value, regtype = winreg.QueryValueEx(hKey, 'SdkInstallRoot')
+ return value
+ except (WindowsError, EnvironmentError) as e:
+ return None
+
+def _find_mono_in_reg_old(subkey):
+ try:
+ with _reg_open_key(winreg.HKEY_LOCAL_MACHINE, subkey) as hKey:
+ default_clr, regtype = winreg.QueryValueEx(hKey, 'DefaultCLR')
+ if default_clr:
+ return _find_mono_in_reg(subkey + '\\' + default_clr)
+ return None
+ except (WindowsError, EnvironmentError):
+ return None
+
+
+def find_mono_root_dir():
+ dir = _find_mono_in_reg(r'SOFTWARE\Mono')
+ if dir:
+ return dir
+ dir = _find_mono_in_reg_old(r'SOFTWARE\Novell\Mono')
+ if dir:
+ return dir
+ return None
+
+
+def find_msbuild_tools_path_reg():
+ try:
+ with _reg_open_key(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0') as hKey:
+ value, regtype = winreg.QueryValueEx(hKey, 'MSBuildToolsPath')
+ return value
+ except (WindowsError, EnvironmentError) as e:
+ return None