Ejemplo n.º 1
0
        /// <summary>
        /// 获取已安装Python版本,存放于PyUtils类的全局静态变量PythonVersions中。
        /// </summary>
        public static void GetPyVersions()
        {
            PythonVersions.Clear();
            RegistryKey key = Registry.LocalMachine;

            if (RegUtils.IsItemExists(key, @"SOFTWARE\Python\PythonCore"))
            {
                RegistryKey pyVersionKey = key.OpenSubKey(@"SOFTWARE\Python\PythonCore");
                string[]    pyVersions   = pyVersionKey.GetSubKeyNames();
                foreach (string version in pyVersions)
                {
                    string eachPyVarsionPath = @"SOFTWARE\Python\PythonCore\" + version + @"\InstallPath";
                    if (RegUtils.IsItemExists(key, eachPyVarsionPath))
                    {
                        RegistryKey eachPyVerKey = key.OpenSubKey(eachPyVarsionPath);
                        string      pyPath       = eachPyVerKey.GetValue("").ToString();
                        pyPath = FilePathUtils.RemovePathEndBackslash(pyPath);
                        PyUtils.PythonVersions.Add(version, pyPath);
                        eachPyVerKey.Close();
                    }
                }
                pyVersionKey.Close();
            }
            // 计算冗余值列表
            pythonBinaryDuplicatePath.Clear();
            foreach (string version in PythonVersions.Keys)
            {
                pythonBinaryDuplicatePath.Add(PythonVersions[version]);
                pythonBinaryDuplicatePath.Add(PythonVersions[version] + "\\Scripts");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 检测已安装Adopt OpenJDK版本,信息储存至JDKUtils类的全局静态变量JDKVersions中。
        /// </summary>
        private static void getAdpotJDKVersion()
        {
            RegistryKey key = Registry.LocalMachine;

            // 检测Hotspot VM JDK
            if (RegUtils.IsItemExists(key, @"SOFTWARE\Temurin\JDK"))
            {
                RegistryKey jdkVersionKey    = key.OpenSubKey(@"SOFTWARE\Temurin\JDK");
                string[]    adoptJDKVersions = jdkVersionKey.GetSubKeyNames();
                foreach (string adoptJDKVersion in adoptJDKVersions)
                {
                    RegistryKey infoKey = jdkVersionKey.OpenSubKey(adoptJDKVersion + @"\hotspot\MSI");
                    string      path    = infoKey.GetValue("Path").ToString();
                    path = FilePathUtils.RemovePathEndBackslash(path);
                    JDKVersions.Add(adoptJDKVersion + " - Adopt Hotspot OpenJDK", path);
                    infoKey.Close();
                }
                jdkVersionKey.Close();
            }
            if (RegUtils.IsItemExists(key, @"SOFTWARE\Eclipse Foundation\JDK"))
            {
                RegistryKey jdkVersionKey    = key.OpenSubKey(@"SOFTWARE\Eclipse Foundation\JDK");
                string[]    adoptJDKVersions = jdkVersionKey.GetSubKeyNames();
                foreach (string adoptJDKVersion in adoptJDKVersions)
                {
                    RegistryKey infoKey = jdkVersionKey.OpenSubKey(adoptJDKVersion + @"\hotspot\MSI");
                    string      path    = infoKey.GetValue("Path").ToString();
                    path = FilePathUtils.RemovePathEndBackslash(path);
                    JDKVersions.Add(adoptJDKVersion + " - Adopt Hotspot OpenJDK", path);
                    infoKey.Close();
                }
                jdkVersionKey.Close();
            }
            // 检测OpenJ9 VM JDK
            if (RegUtils.IsItemExists(key, @"SOFTWARE\Semeru\JDK"))
            {
                RegistryKey jdkVersionKey    = key.OpenSubKey(@"SOFTWARE\Semeru\JDK");
                string[]    adoptJDKVersions = jdkVersionKey.GetSubKeyNames();
                foreach (string adoptJDKVersion in adoptJDKVersions)
                {
                    RegistryKey infoKey = jdkVersionKey.OpenSubKey(adoptJDKVersion + @"\openj9\MSI");
                    string      path    = infoKey.GetValue("Path").ToString();
                    path = FilePathUtils.RemovePathEndBackslash(path);
                    JDKVersions.Add(adoptJDKVersion + " - Adopt OpenJ9 OpenJDK", path);
                    infoKey.Close();
                }
                jdkVersionKey.Close();
            }
            key.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检测已安装Azul Zulu OpenJDK版本,信息储存至JDKUtils类的全局静态变量JDKVersions中。
        /// </summary>
        private static void getAzulZuluJDKVersion()
        {
            RegistryKey key = Registry.LocalMachine;

            if (RegUtils.IsItemExists(key, @"SOFTWARE\Azul Systems\Zulu"))
            {
                RegistryKey jdkVersionKey   = key.OpenSubKey(@"SOFTWARE\Azul Systems\Zulu");
                string[]    zuluJDKVersions = jdkVersionKey.GetSubKeyNames();
                foreach (string zuluJDKVersion in zuluJDKVersions)
                {
                    RegistryKey infoKey = jdkVersionKey.OpenSubKey(zuluJDKVersion);
                    string      path    = infoKey.GetValue("InstallationPath").ToString();
                    path = FilePathUtils.RemovePathEndBackslash(path);
                    JDKVersions.Add(zuluJDKVersion + " - Azul Zulu OpenJDK", path);
                    infoKey.Close();
                }
                jdkVersionKey.Close();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 检测已安装Microsoft JDK版本,信息储存至JDKUtils类的全局静态变量JDKVersions中。
        /// </summary>
        private static void getMicrosoftJDKVersion()
        {
            RegistryKey key = Registry.LocalMachine;

            if (RegUtils.IsItemExists(key, @"SOFTWARE\Microsoft\JDK"))
            {
                RegistryKey msJDKVersionKey = key.OpenSubKey(@"SOFTWARE\Microsoft\JDK");
                string[]    msJDKVersions   = msJDKVersionKey.GetSubKeyNames();
                foreach (string msJDKVersion in msJDKVersions)
                {
                    RegistryKey jdkInfoKey = msJDKVersionKey.OpenSubKey(msJDKVersion + @"\hotspot\MSI");
                    string      path       = jdkInfoKey.GetValue("Path").ToString();
                    path = FilePathUtils.RemovePathEndBackslash(path);
                    JDKVersions.Add(msJDKVersion + " - Microsoft Build OpenJDK", path);
                    jdkInfoKey.Close();
                }
                msJDKVersionKey.Close();
            }
            key.Close();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 检测已安装Oracle JDK版本,信息储存至JDKUtils类的全局静态变量JDKVersions中。
        /// </summary>
        private static void getOracleJDKVersion()
        {
            RegistryKey key = Registry.LocalMachine;

            //检测jdk8及其以下版本
            if (RegUtils.IsItemExists(key, @"SOFTWARE\JavaSoft\Java Development Kit"))
            {
                RegistryKey jdkOldVersionsKey = key.OpenSubKey(@"SOFTWARE\JavaSoft\Java Development Kit");
                string[]    jdkOldVersions    = jdkOldVersionsKey.GetSubKeyNames();
                foreach (string version in jdkOldVersions)
                {
                    if (Array.IndexOf(NOT_ADD_VERSION_VALUE, version) == -1)
                    {
                        RegistryKey jdkVersionKey = key.OpenSubKey(@"SOFTWARE\JavaSoft\Java Development Kit\" + version);
                        string      path          = jdkVersionKey.GetValue("JavaHome").ToString();
                        path = FilePathUtils.RemovePathEndBackslash(path);
                        JDKVersions.Add(version + " - Oracle JDK", path);
                        jdkVersionKey.Close();
                    }
                }
                jdkOldVersionsKey.Close();
            }
            //检测jdk9及其以上版本
            if (RegUtils.IsItemExists(key, @"SOFTWARE\JavaSoft\JDK"))
            {
                RegistryKey jdkNewVersionsKey = key.OpenSubKey(@"SOFTWARE\JavaSoft\JDK");
                string[]    jdkNewVersions    = jdkNewVersionsKey.GetSubKeyNames();
                foreach (string version in jdkNewVersions)
                {
                    RegistryKey jdkVersionKey = key.OpenSubKey(@"SOFTWARE\JavaSoft\JDK\" + version);
                    string      path          = jdkVersionKey.GetValue("JavaHome").ToString();
                    path = FilePathUtils.RemovePathEndBackslash(path);
                    JDKVersions.Add(version + " - Oracle JDK", path);
                    jdkVersionKey.Close();
                }
                jdkNewVersionsKey.Close();
            }
        }