private InterpreterConfiguration TryReadConfiguration()

in Python/Product/Cookiecutter/Shared/Interpreters/PythonRegistrySearch.cs [131:236]


        private InterpreterConfiguration TryReadConfiguration(
            string company,
            string tag,
            RegistryKey tagKey,
            RegistryKey installKey,
            bool pythonCoreCompatibility,
            InterpreterArchitecture assumedArch
        ) {
            if (tagKey == null || installKey == null) {
                return null;
            }

            string prefixPath, exePath, exewPath;
            try {
                prefixPath = PathUtils.NormalizePath(installKey.GetValue(null) as string);
                exePath = PathUtils.NormalizePath(installKey.GetValue("ExecutablePath") as string);
                exewPath = PathUtils.NormalizePath(installKey.GetValue("WindowedExecutablePath") as string);
            } catch (ArgumentException ex) {
                Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
                return null;
            }
            if (pythonCoreCompatibility && !string.IsNullOrEmpty(prefixPath)) {
                if (string.IsNullOrEmpty(exePath)) {
                    try {
                        exePath = PathUtils.GetAbsoluteFilePath(prefixPath, CPythonInterpreterFactoryConstants.ConsoleExecutable);
                    } catch (ArgumentException) {
                    }
                }
                if (string.IsNullOrEmpty(exewPath)) {
                    try {
                        exewPath = PathUtils.GetAbsoluteFilePath(prefixPath, CPythonInterpreterFactoryConstants.WindowsExecutable);
                    } catch (ArgumentException) {
                    }
                }
            }

            var version = tagKey.GetValue("Version") as string;
            if (pythonCoreCompatibility && string.IsNullOrEmpty(version) && tag.Length >= 3) {
                version = tag.Substring(0, 3);
            }

            Version sysVersion;
            var sysVersionString = tagKey.GetValue("SysVersion") as string;
            if (pythonCoreCompatibility && string.IsNullOrEmpty(sysVersionString) && tag.Length >= 3) {
                sysVersionString = tag.Substring(0, 3);
            }
            if (string.IsNullOrEmpty(sysVersionString) || !Version.TryParse(sysVersionString, out sysVersion)) {
                sysVersion = new Version(0, 0);
            }

            PythonLanguageVersion langVersion;
            try {
                langVersion = sysVersion.ToLanguageVersion();
            } catch (InvalidOperationException) {
                langVersion = PythonLanguageVersion.None;
                sysVersion = new Version(0, 0);
            }

            InterpreterArchitecture arch;
            if (!InterpreterArchitecture.TryParse(tagKey.GetValue("SysArchitecture", null) as string, out arch)) {
                arch = assumedArch;
            }

            if (arch == InterpreterArchitecture.Unknown && File.Exists(exePath)) {
                switch (NativeMethods.GetBinaryType(exePath)) {
                    case System.Reflection.ProcessorArchitecture.X86:
                        arch = InterpreterArchitecture.x86;
                        break;
                    case System.Reflection.ProcessorArchitecture.Amd64:
                        arch = InterpreterArchitecture.x64;
                        break;
                }
            }

            if (pythonCoreCompatibility && sysVersion != null && sysVersion < new Version(3, 5) && arch == InterpreterArchitecture.x86) {
                // Older versions of CPython did not include
                // "-32" in their Tag, so we will add it here
                // for uniqueness.
                tag += "-32";
            }

            var pathVar = tagKey.GetValue("PathEnvironmentVariable") as string ??
                CPythonInterpreterFactoryConstants.PathEnvironmentVariableName;

            var id = CPythonInterpreterFactoryConstants.GetInterpreterId(company, tag);

            var description = tagKey.GetValue("DisplayName") as string;
            if (string.IsNullOrEmpty(description)) {
                if (pythonCoreCompatibility) {
                    description = "Python {0}{1: ()}".FormatUI(version, arch);
                } else {
                    description = "{0} {1}".FormatUI(company, tag);
                }
            }

            return new InterpreterConfiguration(
                id,
                description,
                prefixPath,
                exePath,
                exewPath,
                pathVar,
                arch,
                sysVersion
            );
        }