internal static IEnumerable <JdkInfo> GetVSAndroidJdks(Action <TraceLevel, string> logger) { if (!OS.IsWindows) { yield break; } var root = RegistryEx.LocalMachine; var wows = new[] { RegistryEx.Wow64.Key32, RegistryEx.Wow64.Key64 }; var subKey = @"SOFTWARE\Microsoft\VisualStudio\Android"; var valueName = "JavaHome"; foreach (var wow in wows) { if (!RegistryEx.CheckRegistryKeyForExecutable(root, subKey, valueName, wow, "bin", "java.exe")) { continue; } var path = RegistryEx.GetValueString(root, subKey, valueName, wow) ?? ""; if (string.IsNullOrEmpty(path)) { continue; } var jdk = JdkInfo.TryGetJdkInfo(path, logger, subKey); if (jdk == null) { continue; } yield return(jdk); } }
private static IEnumerable <string> GetOracleJdkPaths() { string subkey = @"SOFTWARE\JavaSoft\Java Development Kit"; 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)) { // 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)); } } } }
protected override IEnumerable <string> GetAllAvailableAndroidSdks() { var roots = new[] { RegistryEx.CurrentUser, RegistryEx.LocalMachine }; var wow = RegistryEx.Wow64.Key32; var regKey = GetMDRegistryKey(); Logger(TraceLevel.Info, "Looking for Android SDK..."); // Check for the key the user gave us in the VS/addin options foreach (var root in roots) { if (CheckRegistryKeyForExecutable(root, regKey, MDREG_ANDROID_SDK, wow, "platform-tools", Adb)) { yield return(RegistryEx.GetValueString(root, regKey, MDREG_ANDROID_SDK, wow) ?? ""); } } // Check for the key written by the Xamarin installer if (CheckRegistryKeyForExecutable(RegistryEx.CurrentUser, XAMARIN_ANDROID_INSTALLER_PATH, XAMARIN_ANDROID_INSTALLER_KEY, wow, "platform-tools", Adb)) { yield return(RegistryEx.GetValueString(RegistryEx.CurrentUser, XAMARIN_ANDROID_INSTALLER_PATH, XAMARIN_ANDROID_INSTALLER_KEY, wow) ?? ""); } // Check for the key written by the Android SDK installer foreach (var root in roots) { if (CheckRegistryKeyForExecutable(root, ANDROID_INSTALLER_PATH, ANDROID_INSTALLER_KEY, wow, "platform-tools", Adb)) { yield return(RegistryEx.GetValueString(root, ANDROID_INSTALLER_PATH, ANDROID_INSTALLER_KEY, wow) ?? ""); } } // Check some hardcoded paths for good measure var paths = new string [] { Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Xamarin", "MonoAndroid", "android-sdk-windows"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Android", "android-sdk"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Android", "android-sdk-windows"), !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ProgramW6432")) ? Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432") ?? "", "Android", "android-sdk") : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Android", "android-sdk"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Android", "android-sdk"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Android", "android-sdk"), @"C:\android-sdk-windows" }; foreach (var basePath in paths) { if (Directory.Exists(basePath)) { if (ValidateAndroidSdkLocation(basePath)) { yield return(basePath); } } } }
protected override IEnumerable <string> GetAllAvailableAndroidNdks() { var roots = new[] { RegistryEx.CurrentUser, RegistryEx.LocalMachine }; var wow = RegistryEx.Wow64.Key32; var regKey = GetMDRegistryKey(); Logger(TraceLevel.Info, "Looking for Android NDK..."); // Check for the key the user gave us in the VS/addin options foreach (var root in roots) { if (CheckRegistryKeyForExecutable(root, regKey, MDREG_ANDROID_NDK, wow, ".", NdkStack)) { yield return(RegistryEx.GetValueString(root, regKey, MDREG_ANDROID_NDK, wow) ?? ""); } } foreach (string dir in GetSdkFromEnvironmentVariables()) { yield return(dir); } /* * // Check for the key written by the Xamarin installer * if (CheckRegistryKeyForExecutable (RegistryEx.CurrentUser, XAMARIN_ANDROID_INSTALLER_PATH, XAMARIN_ANDROID_INSTALLER_KEY, wow, "platform-tools", Adb)) * yield return RegistryEx.GetValueString (RegistryEx.CurrentUser, XAMARIN_ANDROID_INSTALLER_PATH, XAMARIN_ANDROID_INSTALLER_KEY, wow); */ // Check some hardcoded paths for good measure var xamarin_private = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Xamarin", "MonoAndroid"); var vs_default = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "AndroidNDK"); var vs_default32bit = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "AndroidNDK32"); var vs_2017_default = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "AndroidNDK64"); var android_default = Path.Combine(OS.ProgramFilesX86 ?? "", "Android"); var cdrive_default = @"C:\"; foreach (var basePath in new string [] { xamarin_private, android_default, vs_default, vs_default32bit, vs_2017_default, cdrive_default }) { if (Directory.Exists(basePath)) { foreach (var dir in Directory.GetDirectories(basePath, "android-ndk-r*")) { if (ValidateAndroidNdkLocation(dir)) { yield return(dir); } } } } foreach (var dir in base.GetAllAvailableAndroidNdks()) { yield return(dir); } }
internal static string?GetWindowsPreferredJdkPath() { var wow = RegistryEx.Wow64.Key32; var regKey = AndroidSdkWindows.GetMDRegistryKey(); if (RegistryEx.CheckRegistryKeyForExecutable(RegistryEx.CurrentUser, regKey, AndroidSdkWindows.MDREG_JAVA_SDK, wow, "bin", "java.exe")) { return(RegistryEx.GetValueString(RegistryEx.CurrentUser, regKey, AndroidSdkWindows.MDREG_JAVA_SDK, wow)); } return(null); }
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); }
protected override IEnumerable <string> GetAllAvailableAndroidSdks() { var roots = new[] { RegistryEx.CurrentUser, RegistryEx.LocalMachine }; var wow = RegistryEx.Wow64.Key32; AndroidLogger.LogInfo("sdk", "Looking for Android SDK.."); // Check for the key the user gave us in the VS/addin options foreach (var root in roots) { if (CheckRegistryKeyForExecutable(root, MDREG_KEY, MDREG_ANDROID_SDK, wow, "platform-tools", Adb)) { yield return(RegistryEx.GetValueString(root, MDREG_KEY, MDREG_ANDROID_SDK, wow)); } } // Check for the key written by the Xamarin installer if (CheckRegistryKeyForExecutable(RegistryEx.CurrentUser, XAMARIN_ANDROID_INSTALLER_PATH, XAMARIN_ANDROID_INSTALLER_KEY, wow, "platform-tools", Adb)) { yield return(RegistryEx.GetValueString(RegistryEx.CurrentUser, XAMARIN_ANDROID_INSTALLER_PATH, XAMARIN_ANDROID_INSTALLER_KEY, wow)); } // Check for the key written by the Android SDK installer foreach (var root in roots) { if (CheckRegistryKeyForExecutable(root, ANDROID_INSTALLER_PATH, ANDROID_INSTALLER_KEY, wow, "platform-tools", Adb)) { yield return(RegistryEx.GetValueString(root, ANDROID_INSTALLER_PATH, ANDROID_INSTALLER_KEY, wow)); } } // Check some hardcoded paths for good measure var xamarin_private = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Xamarin", "MonoAndroid", "android-sdk-windows"); var android_default = Path.Combine(OS.ProgramFilesX86, "Android", "android-sdk-windows"); var cdrive_default = @"C:\android-sdk-windows"; if (ValidateAndroidSdkLocation(xamarin_private)) { yield return(xamarin_private); } if (ValidateAndroidSdkLocation(android_default)) { yield return(android_default); } if (ValidateAndroidSdkLocation(cdrive_default)) { yield return(cdrive_default); } }
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)); } } }
private static IEnumerable <string> GetOpenJdkPaths() { var root = RegistryEx.LocalMachine; var wows = new[] { RegistryEx.Wow64.Key32, RegistryEx.Wow64.Key64 }; var subKey = @"SOFTWARE\Microsoft\VisualStudio\Android"; var valueName = "JavaHome"; foreach (var wow in wows) { if (CheckRegistryKeyForExecutable(root, subKey, valueName, wow, "bin", _JarSigner)) { yield return(RegistryEx.GetValueString(root, subKey, valueName, wow)); } } }
protected static IEnumerable <JdkInfo> GetWindowsRegistryJdks( Action <TraceLevel, string> logger, string parentKey, string childKeyGlob, string?grandChildKey, string valueName, string?locator = null) { if (!OS.IsWindows) { yield break; } var regex = ToRegex(childKeyGlob); var paths = new List <(Version version, string path)> (); var roots = new[] { RegistryEx.CurrentUser, RegistryEx.LocalMachine }; var wows = new[] { RegistryEx.Wow64.Key32, RegistryEx.Wow64.Key64 }; foreach (var root in roots) { foreach (var wow in wows) { foreach (var subkeyName in RegistryEx.EnumerateSubkeys(root, parentKey, wow)) { if (!regex.Match(subkeyName).Success) { continue; } var key = $@"{parentKey}\{subkeyName}" + (grandChildKey == null ? "" : "\\" + grandChildKey); var path = RegistryEx.GetValueString(root, key, valueName, wow); if (path == null) { continue; } var jdk = JdkInfo.TryGetJdkInfo(path, logger, locator ?? $"Windows Registry @ {parentKey}"); if (jdk == null) { continue; } yield return(jdk); } } } }
static IEnumerable <string> GetOracleJdkPaths() { string subkey = @"SOFTWARE\JavaSoft\Java Development Kit"; 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)) { if (RegistryEx.CheckRegistryKeyForExecutable(RegistryEx.LocalMachine, subkey + "\\" + "1.8", "JavaHome", wow64, "bin", "java.exe")) { yield return(RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey + "\\" + "1.8", "JavaHome", wow64) ?? ""); } } } }
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) { 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); }
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); }
public override void SetPreferredAndroidNdkPath(string path) { RegistryEx.SetValueString(RegistryEx.CurrentUser, MDREG_KEY, MDREG_ANDROID_NDK, path ?? "", RegistryEx.Wow64.Key32); }
public override void SetPreferredAndroidNdkPath(string path) { var regKey = GetMDRegistryKey(); RegistryEx.SetValueString(RegistryEx.CurrentUser, regKey, MDREG_ANDROID_NDK, path ?? "", RegistryEx.Wow64.Key32); }
public override void SetPreferredJavaSdkPath(string path) { var regKey = GetMDRegistryKey(); RegistryEx.SetValueString(RegistryEx.CurrentUser, regKey, MDREG_JAVA_SDK, path ?? "", RegistryEx.Wow64.Key32); }
public override void SetPreferredJavaSdkPath(string path) { RegistryEx.SetValueString(RegistryEx.CurrentUser, MDREG_KEY, MDREG_JAVA_SDK, path ?? "", RegistryEx.Wow64.Key32); }