internal static void GetAvailablePackages(
string androidTool, PlayServicesSupport svcSupport,
GetAvailablePackagesComplete complete)
{
CommandLineDialog window = CommandLineDialog.CreateCommandLineDialog(
"Get Installed Android SDK packages.");
window.modal = false;
window.summaryText = "Getting list of installed Android packages.";
window.progressTitle = window.summaryText;
window.autoScrollToBottom = true;
window.RunAsync(
androidTool, "list sdk -u -e -a",
(result) => {
window.Close();
if (result.exitCode != 0)
{
Debug.LogError("Unable to determine which Android packages are " +
"installed. Failed to run " + androidTool + ". " +
result.stderr + " (" + result.exitCode.ToString() + ")");
complete(null);
return;
}
Dictionary<string, bool> packages = new Dictionary<string, bool>();
string[] lines = Regex.Split(result.stdout, "\r\n|\r|\n");
string packageIdentifier = null;
foreach (string line in lines)
{
// Find the start of a package description.
Match match = Regex.Match(line, "^id:\\W+\\d+\\W+or\\W+\"([^\"]+)\"");
if (match.Success)
{
packageIdentifier = match.Groups[1].Value;
packages[packageIdentifier] = false;
continue;
}
if (packageIdentifier == null)
{
continue;
}
// Parse the install path and record whether the package is installed.
match = Regex.Match(line, "^\\W+Install[^:]+:\\W+([^ ]+)");
if (match.Success)
{
packages[packageIdentifier] = File.Exists(
Path.Combine(Path.Combine(svcSupport.SDK, match.Groups[1].Value),
"source.properties"));
packageIdentifier = null;
}
}
complete(packages);
},
maxProgressLines: 50);
window.Show();
}