/// <summary>
        /// Locate OpenJDK installations by well known path.
        /// </summary>
        /// <returns>List of valid OpenJDK paths in version descending order.</returns>
        private static IEnumerable <string> GetKnownOpenJdkPaths()
        {
            string JdkFolderNamePattern = "microsoft_dist_openjdk_";

            var paths     = new List <Tuple <string, Version> > ();
            var rootPaths = new List <string> {
                Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramW6432%"), "Android", "jdk"),
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Android", "jdk"),
            };

            foreach (var rootPath in rootPaths)
            {
                if (Directory.Exists(rootPath))
                {
                    foreach (var directoryName in Directory.EnumerateDirectories(rootPath, $"{JdkFolderNamePattern}*").ToList())
                    {
                        var versionString = directoryName.Replace($"{rootPath}\\{JdkFolderNamePattern}", string.Empty);
                        if (Version.TryParse(versionString, out Version ver))
                        {
                            paths.Add(new Tuple <string, Version>(directoryName, ver));
                        }
                    }
                }
            }

            return(paths.OrderByDescending(v => v.Item2)
                   .Where(openJdk => ProcessUtils.FindExecutablesInDirectory(Path.Combine(openJdk.Item1, "bin"), _JarSigner).Any())
                   .Select(openJdk => openJdk.Item1));
        }
        /// <summary>
        /// Checks that a value is the location of a Java SDK.
        /// </summary>
        public virtual bool ValidateJavaSdkLocation([NotNullWhen(true)] string?loc)
        {
            bool result = !string.IsNullOrEmpty(loc) && ProcessUtils.FindExecutablesInDirectory(Path.Combine(loc, "bin"), JarSigner).Any();

            Logger(TraceLevel.Verbose, $"{nameof (ValidateJavaSdkLocation)}: `{loc}`, result={result}");
            return(result);
        }
        /// <summary>
        /// Checks that a value is the location of an Android SDK.
        /// </summary>
        public bool ValidateAndroidSdkLocation([NotNullWhen(true)] string?loc)
        {
            bool result = !string.IsNullOrEmpty(loc) && ProcessUtils.FindExecutablesInDirectory(Path.Combine(loc, "platform-tools"), Adb).Any();

            Logger(TraceLevel.Verbose, $"{nameof (ValidateAndroidSdkLocation)}: `{loc}`, result={result}");
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks that a value is the location of an Android SDK.
        /// </summary>
        public bool ValidateAndroidNdkLocation(string loc)
        {
            bool result = !string.IsNullOrEmpty(loc) && ProcessUtils.FindExecutablesInDirectory(loc, NdkStack).Any();

            Logger(TraceLevel.Verbose, $"{nameof (ValidateAndroidNdkLocation)}: `{loc}`, result={result}");
            return(result);
        }
Exemplo n.º 5
0
        public JdkInfo(string homePath)
        {
            if (homePath == null)
            {
                throw new ArgumentNullException(nameof(homePath));
            }
            if (!Directory.Exists(homePath))
            {
                throw new ArgumentException("Not a directory", nameof(homePath));
            }

            HomePath = homePath;

            var binPath = Path.Combine(HomePath, "bin");

            JarPath   = ProcessUtils.FindExecutablesInDirectory(binPath, "jar").FirstOrDefault();
            JavaPath  = ProcessUtils.FindExecutablesInDirectory(binPath, "java").FirstOrDefault();
            JavacPath = ProcessUtils.FindExecutablesInDirectory(binPath, "javac").FirstOrDefault();

            string?jdkJvmPath = GetJdkJvmPath();

            ValidateFile("jar", JarPath);
            ValidateFile("java", JavaPath);
            ValidateFile("javac", JavacPath);
            ValidateFile("jvm", jdkJvmPath);

            JdkJvmPath = jdkJvmPath !;

            var includes   = new List <string> ();
            var jdkInclude = Path.Combine(HomePath, "include");

            if (Directory.Exists(jdkInclude))
            {
                includes.Add(jdkInclude);
                includes.AddRange(Directory.GetDirectories(jdkInclude));
            }


            ReleaseProperties = GetReleaseProperties();

            IncludePath = new ReadOnlyCollection <string> (includes);

            javaProperties = new Lazy <Dictionary <string, List <string> > > (GetJavaProperties, LazyThreadSafetyMode.ExecutionAndPublication);
            javaVersion    = new Lazy <Version?> (GetJavaVersion, LazyThreadSafetyMode.ExecutionAndPublication);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 Dictionary <string, List <string> > GetJavaProperties()
 {
     return(GetJavaProperties(ProcessUtils.FindExecutablesInDirectory(Path.Combine(HomePath, "bin"), "java").First()));
 }