Exemplo n.º 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.");
            }
        }
        protected override string GetJavaSdkPath()
        {
            // 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))
                {
                    return(RegistryEx.GetValueString(root, regKey, MDREG_JAVA_SDK, wow));
                }
            }

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

            Logger(TraceLevel.Info, "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))
                {
                    Logger(TraceLevel.Info, $"  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))
                    {
                        return(RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey + "\\" + "1.8", "JavaHome", wow64));
                    }

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

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

                Logger(TraceLevel.Info, $"  Key {key_name} not found.");
            }

            // We ran out of things to check..
            return(null);
        }
Exemplo n.º 3
0
        private static IEnumerable <string> GetPreferredJdkPaths()
        {
            // 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));
                }
            }
        }
Exemplo n.º 4
0
        private static 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 path = NullIfEmpty(RegistryEx.GetValueString(key, subkey, valueName, wow64));

            if (path == null)
            {
                return(false);
            }

            if (!ProcessUtils.FindExecutablesInDirectory(Path.Combine(path, subdir), exe).Any())
            {
                return(false);
            }

            return(true);
        }
        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 path = NullIfEmpty(RegistryEx.GetValueString(key, subkey, valueName, wow64));

            if (path == null)
            {
                AndroidLogger.LogInfo("sdk", "  Key {0} not found.", key_name);
                return(false);
            }

            if (!FindExecutableInDirectory(exe, Path.Combine(path, subdir)).Any())
            {
                AndroidLogger.LogInfo("sdk", "  Key {0} found:\n    Path does not contain {1} in \\{2} ({3}).", key_name, exe, subdir, path);
                return(false);
            }

            AndroidLogger.LogInfo("sdk", "  Key {0} found:\n    Path contains {1} in \\{2} ({3}).", key_name, exe, subdir, path);

            return(true);
        }
        private static 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 path = NullIfEmpty(RegistryEx.GetValueString(key, subkey, valueName, wow64));

            if (path == null)
            {
                LogMessage("  Key {0} not found.", key_name);
                return(false);
            }

            if (!File.Exists(Path.Combine(path, subdir, exe)))
            {
                LogMessage("  Key {0} found:\n    Path does not contain {1} in \\{2} ({3}).", key_name, exe, subdir, path);
                return(false);
            }

            LogMessage("  Key {0} found:\n    Path contains {1} in \\{2} ({3}).", key_name, exe, subdir, path);

            return(true);
        }
        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 path = NullIfEmpty(RegistryEx.GetValueString(key, subkey, valueName, wow64));

            if (path == null)
            {
                Logger(TraceLevel.Info, $"  Key {key_name} not found.");
                return(false);
            }

            if (!FindExecutableInDirectory(exe, Path.Combine(path, subdir)).Any())
            {
                Logger(TraceLevel.Info, $"  Key {key_name} found:\n    Path does not contain {exe} in \\{subdir} ({path}).");
                return(false);
            }

            Logger(TraceLevel.Info, $"  Key {key_name} found:\n    Path contains {exe} in \\{subdir} ({path}).");

            return(true);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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 path = RegistryEx.GetValueString(key, subkey, valueName, wow64);

            if (string.IsNullOrEmpty(path))
            {
                path = null;
            }

            if (path == null)
            {
                return(false);
            }

            if (!File.Exists(Path.Combine(path, subdir, exe)))
            {
                return(false);
            }

            return(true);
        }