3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Windows registry functions for Microsoft Visual C/C++.
30 from SCons
.Util
import (
36 from .. common
import (
42 from . import Dispatcher
43 Dispatcher
.register_modulename(__name__
)
46 # A null-terminated string that contains unexpanded references to environment variables.
49 def read_value(hkey
, subkey_valname
, expand
: bool=True):
51 rval_t
= RegGetValue(hkey
, subkey_valname
)
53 debug('OSError: hkey=%s, subkey=%s', repr(hkey
), repr(subkey_valname
))
55 rval
, regtype
= rval_t
56 if regtype
== REG_EXPAND_SZ
and expand
:
57 rval
= os
.path
.expandvars(rval
)
58 debug('hkey=%s, subkey=%s, rval=%s', repr(hkey
), repr(subkey_valname
), repr(rval
))
61 def registry_query_path(key
, val
, suffix
, expand
: bool=True):
62 extval
= val
+ '\\' + suffix
if suffix
else val
63 qpath
= read_value(key
, extval
, expand
=expand
)
64 if qpath
and os
.path
.exists(qpath
):
65 qpath
= Util
.normalize_path(qpath
)
68 return (qpath
, key
, val
, extval
)
70 REG_SOFTWARE_MICROSOFT
= [
71 (HKEY_LOCAL_MACHINE
, r
'Software\Wow6432Node\Microsoft'),
72 (HKEY_CURRENT_USER
, r
'Software\Wow6432Node\Microsoft'), # SDK queries
73 (HKEY_LOCAL_MACHINE
, r
'Software\Microsoft'),
74 (HKEY_CURRENT_USER
, r
'Software\Microsoft'),
77 def microsoft_query_paths(suffix
, usrval
=None, expand
: bool=True):
80 for key
, val
in REG_SOFTWARE_MICROSOFT
:
81 extval
= val
+ '\\' + suffix
if suffix
else val
82 qpath
= read_value(key
, extval
, expand
=expand
)
83 if qpath
and os
.path
.exists(qpath
):
84 qpath
= Util
.normalize_path(qpath
)
85 if qpath
not in paths
:
87 records
.append((qpath
, key
, val
, extval
, usrval
))
90 def microsoft_query_keys(suffix
, usrval
=None, expand
: bool=True):
92 for key
, val
in REG_SOFTWARE_MICROSOFT
:
93 extval
= val
+ '\\' + suffix
if suffix
else val
94 rval
= read_value(key
, extval
, expand
=expand
)
96 records
.append((rval
, key
, val
, extval
, usrval
))
99 def microsoft_sdks(version
):
100 return '\\'.join([r
'Microsoft SDKs\Windows', 'v' + version
, r
'InstallationFolder'])
102 def sdk_query_paths(version
):
103 q
= microsoft_sdks(version
)
104 return microsoft_query_paths(q
)
106 def windows_kits(version
):
107 return r
'Windows Kits\Installed Roots\KitsRoot' + version
109 def windows_kit_query_paths(version
):
110 q
= windows_kits(version
)
111 return microsoft_query_paths(q
)
113 def vstudio_sxs_vs7(version
):
114 return '\\'.join([r
'VisualStudio\SxS\VS7', version
])
116 def vstudio_sxs_vc7(version
):
117 return '\\'.join([r
'VisualStudio\SxS\VC7', version
])
119 def devdiv_vs_servicing_component(version
, component
):
120 return '\\'.join([r
'DevDiv\VS\Servicing', version
, component
, 'Install'])