-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