-def get_default_visualstudio_version(env):
- """Returns the version set in the env, or the latest version
- installed, if it can find it, or '6.0' if all else fails. Also
- updated the environment with what it found."""
-
- version = '6.0'
- versions = [version]
- if not env.has_key('MSVS') or type(env['MSVS']) != types.DictType:
- env['MSVS'] = {}
-
- if env.has_key('MSVS_VERSION'):
- version = env['MSVS_VERSION']
- versions = [version]
- else:
- if SCons.Util.can_read_reg:
- versions = get_visualstudio_versions()
- if versions:
- version = versions[0] #use highest version by default
-
- env['MSVS_VERSION'] = version
- env['MSVS']['VERSIONS'] = versions
- env['MSVS']['VERSION'] = version
-
- return version
-
-def get_visualstudio_versions():
- """
- Get list of visualstudio versions from the Windows registry. Return a
- list of strings containing version numbers; an exception will be raised
- if we were unable to access the registry (eg. couldn't import
- a registry-access module) or the appropriate registry keys weren't
- found.
- """
-
- if not SCons.Util.can_read_reg:
- return []
-
- HLM = SCons.Util.HKEY_LOCAL_MACHINE
- K = r'Software\Microsoft\VisualStudio'
- L = []
- try:
- k = SCons.Util.RegOpenKeyEx(HLM, K)
- i = 0
- while 1:
- try:
- p = SCons.Util.RegEnumKey(k,i)
- except SCons.Util.RegError:
- break
- i = i + 1
- if not p[0] in '123456789' or p in L:
- continue
- # Only add this version number if there is a valid
- # registry structure (includes the "Setup" key),
- # and at least some of the correct directories
- # exist. Sometimes VS uninstall leaves around
- # some registry/filesystem turds that we don't
- # want to trip over. Also, some valid registry
- # entries are MSDN entries, not MSVS ('7.1',
- # notably), and we want to skip those too.
- try:
- tst = SCons.Util.RegOpenKeyEx(HLM, K + '\\' + p + '\\Setup')
- except SCons.Util.RegError:
- continue
-
- id = []
- idk = SCons.Util.RegOpenKeyEx(HLM, K + '\\' + p)
- # This is not always here -- it only exists if the
- # user installed into a non-standard location (at
- # least in VS6 it works that way -- VS7 seems to
- # always write it)
- try:
- id = SCons.Util.RegQueryValueEx(idk, 'InstallDir')
- except SCons.Util.RegError:
- pass
-
- # If the InstallDir key doesn't exist,
- # then we check the default locations.
- if not id or not id[0]:
- files_dir = SCons.Platform.win32.get_program_files_dir()
- if float(p) < 7.0:
- vs = r'Microsoft Visual Studio\Common\MSDev98'
- else:
- vs = r'Microsoft Visual Studio .NET\Common7\IDE'
- id = [ os.path.join(files_dir, vs) ]
- if os.path.exists(id[0]):
- L.append(p)
- except SCons.Util.RegError:
- pass
-
- if not L:
- return []
-
- # This is a hack to get around the fact that certain Visual Studio
- # patches place a "6.1" version in the registry, which does not have
- # any of the keys we need to find include paths, install directories,
- # etc. Therefore we ignore it if it is there, since it throws all
- # other logic off.
- try:
- L.remove("6.1")
- except ValueError:
- pass
-
- L.sort()
- L.reverse()
-
- return L
-
-def is_msvs_installed():
- """
- Check the registry for an installed visual studio.
- """
- try:
- v = SCons.Tool.msvs.get_visualstudio_versions()
- return v
- except (SCons.Util.RegError, SCons.Errors.InternalError):
- return 0
-
-def get_msvs_install_dirs(version = None):
- """
- Get installed locations for various msvc-related products, like the .NET SDK
- and the Platform SDK.
- """
-
- if not SCons.Util.can_read_reg:
- return {}
-
- if not version:
- versions = get_visualstudio_versions()
- if versions:
- version = versions[0] #use highest version by default
- else:
- return {}
-
- K = 'Software\\Microsoft\\VisualStudio\\' + version
-
- # vc++ install dir
- rv = {}
- try:
- if (float(version) < 7.0):
- (rv['VCINSTALLDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- K + r'\Setup\Microsoft Visual C++\ProductDir')
- else:
- (rv['VCINSTALLDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- K + r'\Setup\VC\ProductDir')
- except SCons.Util.RegError:
- pass
-
- # visual studio install dir
- if (float(version) < 7.0):
- try:
- (rv['VSINSTALLDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- K + r'\Setup\Microsoft Visual Studio\ProductDir')
- except SCons.Util.RegError:
- pass
-
- if not rv.has_key('VSINSTALLDIR') or not rv['VSINSTALLDIR']:
- if rv.has_key('VCINSTALLDIR') and rv['VCINSTALLDIR']:
- rv['VSINSTALLDIR'] = os.path.dirname(rv['VCINSTALLDIR'])
- else:
- rv['VSINSTALLDIR'] = os.path.join(SCons.Platform.win32.get_program_files_dir(),'Microsoft Visual Studio')
- else:
- try:
- (rv['VSINSTALLDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- K + r'\Setup\VS\ProductDir')
- except SCons.Util.RegError:
- pass
-
- # .NET framework install dir
- try:
- (rv['FRAMEWORKDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- r'Software\Microsoft\.NETFramework\InstallRoot')
- except SCons.Util.RegError:
- pass
-
- if rv.has_key('FRAMEWORKDIR'):
- # try and enumerate the installed versions of the .NET framework.
- contents = os.listdir(rv['FRAMEWORKDIR'])
- l = re.compile('v[0-9]+.*')
- versions = []
- for entry in contents:
- if l.match(entry):
- versions.append(entry)
-
- def versrt(a,b):
- # since version numbers aren't really floats...
- aa = a[1:]
- bb = b[1:]
- aal = aa.split('.')
- bbl = bb.split('.')
- c = int(bbl[0]) - int(aal[0])
- if c == 0:
- c = int(bbl[1]) - int(aal[1])
- if c == 0:
- c = int(bbl[2]) - int(aal[2])
- return c
-
- versions.sort(versrt)
-
- rv['FRAMEWORKVERSIONS'] = versions
- # assume that the highest version is the latest version installed
- rv['FRAMEWORKVERSION'] = versions[0]
-
- # .NET framework SDK install dir
- try:
- if rv.has_key('FRAMEWORKVERSION') and rv['FRAMEWORKVERSION'][:4] == 'v1.1':
- key = r'Software\Microsoft\.NETFramework\sdkInstallRootv1.1'
- else:
- key = r'Software\Microsoft\.NETFramework\sdkInstallRoot'
-
- (rv['FRAMEWORKSDKDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,key)
-
- except SCons.Util.RegError:
- pass
-
- # MS Platform SDK dir
- try:
- (rv['PLATFORMSDKDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- r'Software\Microsoft\MicrosoftSDK\Directories\Install Dir')
- except SCons.Util.RegError:
- pass
-
- if rv.has_key('PLATFORMSDKDIR'):
- # if we have a platform SDK, try and get some info on it.
- vers = {}
- try:
- loc = r'Software\Microsoft\MicrosoftSDK\InstalledSDKs'
- k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,loc)
- i = 0
- while 1:
- try:
- key = SCons.Util.RegEnumKey(k,i)
- sdk = SCons.Util.RegOpenKeyEx(k,key)
- j = 0
- name = ''
- date = ''
- version = ''
- while 1:
- try:
- (vk,vv,t) = SCons.Util.RegEnumValue(sdk,j)
- if vk.lower() == 'keyword':
- name = vv
- if vk.lower() == 'propagation_date':
- date = vv
- if vk.lower() == 'version':
- version = vv
- j = j + 1
- except SCons.Util.RegError:
- break
- if name:
- vers[name] = (date, version)
- i = i + 1
- except SCons.Util.RegError:
- break
- rv['PLATFORMSDK_MODULES'] = vers
- except SCons.Util.RegError:
- pass
-
- return rv;
-