예제 #1
0
        private static bool TryGetFrameworkVersionFromKey(RegistryKey key, out FrameworkVersion frameworkVersion)
        {
            frameworkVersion = null;

            bool isInstalled;

            if (TryGetIsInstalled(key, out isInstalled) && isInstalled)
            {
                Version version;
                if (!TryGetVersionValue(key, out version))
                {
                    return(false);
                }

                int?servicePack    = null;
                int servicePackRaw = 0;
                if (TryGetServicePackValue(key, out servicePackRaw))
                {
                    servicePack = servicePackRaw;
                }

                frameworkVersion = new FrameworkVersion(
                    version,
                    servicePack,
                    key.Name == "Client" ? FrameworkInstallationType.ClientProfile : FrameworkInstallationType.Full);
                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Determines which versions are installed according to the registry.
        /// </summary>
        /// <returns>An array of .NET Framework versions.</returns>
        public static FrameworkVersion[] GetInstalledVersions()
        {
            if (_versions != null)
            {
                return(_versions);
            }

            var versions = new List <FrameworkVersion>();

            var frameworkSetupNDPNode = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");

            if (frameworkSetupNDPNode != null)
            {
                foreach (var keyName in frameworkSetupNDPNode.GetSubKeyNames())
                {
                    if (keyName[0] == 'v')
                    {
                        var key = frameworkSetupNDPNode.OpenSubKey(keyName);

                        if (key != null)
                        {
                            // key "v4" has a slightly different structure than the previous ones.
                            if (keyName == "v4")
                            {
                                // required by LiteDevelop, so is always installed.
                                versions.Add(new FrameworkVersion(new Version(4, 0), null, FrameworkInstallationType.ClientProfile));
                                versions.Add(new FrameworkVersion(new Version(4, 0), null, FrameworkInstallationType.Full));

                                foreach (var subKeyName in key.GetSubKeyNames())
                                {
                                    var subKey = key.OpenSubKey(subKeyName);

                                    if (subKey != null)
                                    {
                                        IEnumerable <FrameworkVersion> frameworkVersions;

                                        // check if 4.5 and/or 4.5.1 is installed.
                                        if (TryGetFramework45VersionsFromKey(subKey, out frameworkVersions))
                                        {
                                            versions.AddRange(frameworkVersions);
                                            break;
                                        }

                                        subKey.Close();
                                    }
                                }
                            }
                            else
                            {
                                // get 2.0 -> 3.5

                                FrameworkVersion frameworkVersion = null;

                                if (TryGetFrameworkVersionFromKey(key, out frameworkVersion))
                                {
                                    versions.Add(frameworkVersion);
                                }
                            }

                            key.Close();
                        }
                    }
                }

                frameworkSetupNDPNode.Close();
            }

            return(_versions = versions.ToArray());
        }
예제 #3
0
 public bool Equals(FrameworkVersion version)
 {
     return this.Version == version.Version && ServicePack == version.ServicePack && InstallationType == version.InstallationType;
 }
예제 #4
0
        private static bool TryGetFrameworkVersionFromKey(RegistryKey key, out FrameworkVersion frameworkVersion)
        {
            frameworkVersion = null;

            bool isInstalled;
            if (TryGetIsInstalled(key, out isInstalled) && isInstalled)
            {
                Version version;
                if (!TryGetVersionValue(key, out version))
                {
                    return false;
                }

                int? servicePack = null;
                int servicePackRaw = 0;
                if (TryGetServicePackValue(key, out servicePackRaw))
                {
                    servicePack = servicePackRaw;
                }

                frameworkVersion = new FrameworkVersion(
                    version,
                    servicePack,
                    key.Name == "Client" ? FrameworkInstallationType.ClientProfile : FrameworkInstallationType.Full);
                return true;
            }

            return false;
        }
예제 #5
0
 public bool Equals(FrameworkVersion version)
 {
     return(this.Version == version.Version && ServicePack == version.ServicePack && InstallationType == version.InstallationType);
 }