public AndroidSdkManagerList List(AndroidSdkManagerToolSettings settings) { var result = new AndroidSdkManagerList(); if (settings == null) { settings = new AndroidSdkManagerToolSettings(); } //adb devices -l var builder = new ProcessArgumentBuilder(); builder.Append("--list"); BuildStandardOptions(settings, builder); var p = RunProcess(settings, builder, new ProcessSettings { RedirectStandardOutput = true, }); //var processField = p.GetType().GetField("_process", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance); //var process = (System.Diagnostics.Process)processField.GetValue(p); //process.StartInfo.RedirectStandardInput = true; //process.StandardInput.WriteLine("y"); p.WaitForExit(); int section = 0; foreach (var line in p.GetStandardOutput()) { if (line.ToLowerInvariant().Contains("installed packages:")) { section = 1; continue; } else if (line.ToLowerInvariant().Contains("available packages:")) { section = 2; continue; } else if (line.ToLowerInvariant().Contains("available updates:")) { section = 3; continue; } if (section >= 1 && section <= 3) { var parts = line.Split('|'); // These lines are not actually good data, skip them if (parts == null || parts.Length <= 1 || parts[0].ToLowerInvariant().Contains("path") || parts[0].ToLowerInvariant().Contains("id") || parts[0].ToLowerInvariant().Contains("------")) { continue; } // If we got here, we should have a good line of data if (section == 1) { result.InstalledPackages.Add(new InstalledAndroidSdkPackage { Path = parts[0]?.Trim(), Version = parts[1]?.Trim(), Description = parts[2]?.Trim(), Location = parts[3]?.Trim() }); } else if (section == 2) { result.AvailablePackages.Add(new AndroidSdkPackage { Path = parts[0]?.Trim(), Version = parts[1]?.Trim(), Description = parts[2]?.Trim() }); } else if (section == 3) { result.AvailableUpdates.Add(new AvailableAndroidSdkUpdate { Path = parts[0]?.Trim(), InstalledVersion = parts[1]?.Trim(), AvailableVersion = parts[2]?.Trim() }); } } } return(result); }
public AndroidSdkManagerList List(AndroidSdkManagerToolSettings settings) { var result = new AndroidSdkManagerList(); if (settings == null) { settings = new AndroidSdkManagerToolSettings(); } CheckSdkManagerVersion(settings); //adb devices -l var builder = new ProcessArgumentBuilder(); builder.Append("--list --verbose"); BuildStandardOptions(settings, builder); var p = RunProcess(settings, builder, new ProcessSettings { RedirectStandardOutput = true, }); //var processField = p.GetType().GetField("_process", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance); //var process = (System.Diagnostics.Process)processField.GetValue(p); //process.StartInfo.RedirectStandardInput = true; //process.StandardInput.WriteLine("y"); p.WaitForExit(); int section = 0; var path = string.Empty; var description = string.Empty; var version = string.Empty; var location = string.Empty; foreach (var line in p.GetStandardOutput()) { if (line.StartsWith("------")) { continue; } if (line.ToLowerInvariant().Contains("installed packages:")) { section = 1; continue; } else if (line.ToLowerInvariant().Contains("available packages:")) { section = 2; continue; } else if (line.ToLowerInvariant().Contains("available updates:")) { section = 3; continue; } if (section >= 1 && section <= 2) { if (string.IsNullOrEmpty(path)) { // If we have spaces preceding the line, it's not a new item yet if (line.StartsWith(" ")) { continue; } path = line.Trim(); continue; } if (rxListDesc.IsMatch(line)) { description = rxListDesc.Match(line)?.Groups?["desc"]?.Value; continue; } if (rxListVers.IsMatch(line)) { version = rxListVers.Match(line)?.Groups?["ver"]?.Value; continue; } if (rxListLoc.IsMatch(line)) { location = rxListLoc.Match(line)?.Groups?["loc"]?.Value; continue; } // If we got here, we should have a good line of data if (section == 1) { result.InstalledPackages.Add(new InstalledAndroidSdkPackage { Path = path, Version = version, Description = description, Location = location }); } else if (section == 2) { result.AvailablePackages.Add(new AndroidSdkPackage { Path = path, Version = version, Description = description }); } path = null; description = null; version = null; location = null; } } return(result); }