Example #1
0
        IEnumerable <string> GetJavaHomePathsFromWindowsRegistry()
        {
            if (Path.DirectorySeparatorChar == '/')
            {
                yield break;
            }

            // check the user specified path
            var roots = new [] { RegistryEx.CurrentUser, RegistryEx.LocalMachine };
            const RegistryEx.Wow64 wow = RegistryEx.Wow64.Key32;
            var regKey = GetMDRegistryKey();

            foreach (var root in roots)
            {
                if (CheckRegistryKeyForExecutable(root, regKey, MDREG_JAVA_SDK, wow, "bin", JARSIGNER))
                {
                    yield return(RegistryEx.GetValueString(root, regKey, MDREG_JAVA_SDK, wow));
                }
            }

            string subkey = @"SOFTWARE\JavaSoft\Java Development Kit";

            Log.LogMessage(MessageImportance.Low, "Looking for Java 6 SDK...");

            foreach (var wow64 in new [] { RegistryEx.Wow64.Key32, RegistryEx.Wow64.Key64 })
            {
                string key_name       = string.Format(@"{0}\{1}\{2}", "HKLM", subkey, "CurrentVersion");
                var    currentVersion = RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey, "CurrentVersion", wow64);

                if (!string.IsNullOrEmpty(currentVersion))
                {
                    Log.LogMessage(MessageImportance.Low, $"  Key {key_name} found.");

                    // No matter what the CurrentVersion is, look for 1.6 or 1.7 or 1.8
                    if (CheckRegistryKeyForExecutable(RegistryEx.LocalMachine, subkey + "\\" + "1.8", "JavaHome", wow64, "bin", JARSIGNER))
                    {
                        yield return(RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey + "\\" + "1.8", "JavaHome", wow64));
                    }

                    if (CheckRegistryKeyForExecutable(RegistryEx.LocalMachine, subkey + "\\" + "1.7", "JavaHome", wow64, "bin", JARSIGNER))
                    {
                        yield return(RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey + "\\" + "1.7", "JavaHome", wow64));
                    }

                    if (CheckRegistryKeyForExecutable(RegistryEx.LocalMachine, subkey + "\\" + "1.6", "JavaHome", wow64, "bin", JARSIGNER))
                    {
                        yield return(RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey + "\\" + "1.6", "JavaHome", wow64));
                    }
                }

                Log.LogMessage(MessageImportance.Low, $"  Key {key_name} not found.");
            }
        }
Example #2
0
        private bool CheckRegistryKeyForExecutable(UIntPtr key, string subkey, string valueName, RegistryEx.Wow64 wow64, string subdir, string exe)
        {
            string key_name = string.Format(@"{0}\{1}\{2}", key == RegistryEx.CurrentUser ? "HKCU" : "HKLM", subkey, valueName);

            var value = RegistryEx.GetValueString(key, subkey, valueName, wow64);
            var path  = string.IsNullOrEmpty(value) ? null : value;

            if (path == null)
            {
                Log.LogMessage(MessageImportance.Low, $"  Key {key_name} not found.");
                return(false);
            }

            if (!FindExecutablesInDirectory(Path.Combine(path, subdir), exe).Any())
            {
                Log.LogMessage(MessageImportance.Low, $"  Key {key_name} found:\n    Path does not contain {exe} in \\{subdir} ({path}).");
                return(false);
            }

            Log.LogMessage(MessageImportance.Low, $"  Key {key_name} found:\n    Path contains {exe} in \\{subdir} ({path}).");

            return(true);
        }