bool CorrettoExistsAndIsValid(string installDir, out string installedVersion) { installedVersion = String.Empty; if (!Directory.Exists(installDir)) { Log.DebugLine($"Corretto directory {installDir} does not exist"); return(false); } string corettoVersionFile = Path.Combine(installDir, "version.txt"); if (!File.Exists(corettoVersionFile)) { Log.DebugLine($"Corretto version file {corettoVersionFile} does not exist"); return(false); } string[] lines = File.ReadAllLines(corettoVersionFile); if (lines == null || lines.Length == 0) { Log.DebugLine($"Corretto version file {corettoVersionFile} is empty, cannot determine version"); return(false); } string cv = lines [0].Trim(); if (String.IsNullOrEmpty(cv)) { Log.DebugLine($"Corretto version is empty"); return(false); } installedVersion = cv; if (!Version.TryParse(cv, out Version cversion)) { Log.DebugLine($"Unable to parse Corretto version from: {cv}"); return(false); } if (cversion != Configurables.Defaults.CorrettoVersion) { Log.DebugLine($"Invalid Corretto version. Need {Configurables.Defaults.CorrettoVersion}, found {cversion}"); return(false); } foreach (string f in jdkFiles) { string file = Path.Combine(installDir, f); if (!File.Exists(file)) { bool foundExe = false; foreach (string exe in Utilities.FindExecutable(f)) { file = Path.Combine(installDir, exe); if (File.Exists(file)) { foundExe = true; break; } } if (!foundExe) { Log.DebugLine($"JDK file {file} missing from Corretto"); return(false); } } } return(true); }
bool OpenJDKExistsAndIsValid(string installDir, out string installedVersion) { installedVersion = null; if (!Directory.Exists(installDir)) { Log.DebugLine($"{ProductName} directory {installDir} does not exist"); return(false); } string corettoVersionFile = Path.Combine(installDir, "version.txt"); if (File.Exists(corettoVersionFile)) { Log.DebugLine($"Corretto version file {corettoVersionFile} found, will replace Corretto with {ProductName}"); return(false); } string openJDKReleaseFile = Path.Combine(installDir, "release"); if (!File.Exists(openJDKReleaseFile)) { Log.DebugLine($"{ProductName} release file {openJDKReleaseFile} does not exist, cannot determine version"); return(false); } string[] lines = File.ReadAllLines(openJDKReleaseFile); if (lines == null || lines.Length == 0) { Log.DebugLine($"{ProductName} release file {openJDKReleaseFile} is empty, cannot determine version"); return(false); } string cv = null; foreach (string l in lines) { string line = l.Trim(); if (!line.StartsWith("JAVA_VERSION=", StringComparison.Ordinal)) { continue; } cv = line.Substring(line.IndexOf('=') + 1).Trim('"'); cv = cv.Replace("_", "."); break; } if (String.IsNullOrEmpty(cv)) { Log.DebugLine($"Unable to find version of {ProductName} in release file {openJDKReleaseFile}"); return(false); } string xaVersionFile = Path.Combine(installDir, XAVersionInfoFile); if (!File.Exists(xaVersionFile)) { installedVersion = cv; Log.DebugLine($"Unable to find Xamarin.Android version file {xaVersionFile}"); return(false); } lines = File.ReadAllLines(xaVersionFile); if (lines == null || lines.Length == 0) { Log.DebugLine($"Xamarin.Android version file {xaVersionFile} is empty, cannot determine release version"); return(false); } string rv = lines[0].Trim(); if (String.IsNullOrEmpty(rv)) { Log.DebugLine($"Xamarin.Android version file {xaVersionFile} does not contain release version information"); return(false); } installedVersion = $"{cv} r{rv}"; if (!Version.TryParse(cv, out Version cversion)) { Log.DebugLine($"Unable to parse {ProductName} version from: {cv}"); return(false); } if (cversion != JdkVersion) { Log.DebugLine($"Invalid {ProductName} version. Need {JdkVersion}, found {cversion}"); return(false); } if (!Version.TryParse(rv, out cversion)) { Log.DebugLine($"Unable to parse {ProductName} release version from: {rv}"); return(false); } if (cversion != JdkRelease) { Log.DebugLine($"Invalid {ProductName} version. Need {JdkRelease}, found {cversion}"); return(false); } foreach (string f in jdkFiles) { string file = Path.Combine(installDir, f); if (!File.Exists(file)) { bool foundExe = false; foreach (string exe in Utilities.FindExecutable(f)) { file = Path.Combine(installDir, exe); if (File.Exists(file)) { foundExe = true; break; } } if (!foundExe) { Log.DebugLine($"JDK file {file} missing from {ProductName}"); return(false); } } } return(true); }