Пример #1
0
        private async void RefreshPackageButton_Click(object sender, EventArgs e)
        {
            const string prefix = "package:";

            // If the server isn't running and the server start fails, return.
            if (!_serverRunning && !TryStartServer())
            {
                return;
            }

            if (DeviceComboBox.SelectedItem == null)
            {
                MessageBox.Show("A device must be selected before the package list can be retrieved.",
                                "No Device",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);

                return;
            }

            try
            {
                // Get a list of all packages in a single string.
                string response = await _client.ExecuteShellCommandAsync(DeviceComboBox.SelectedItem as Device, "pm list packages");

                // Split the string into several lines.
                var split = response.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                // Remove the package: prefix from each line.
                var packages = split.Select(s => s.Substring(prefix.Length));

                // Pause drawing of the list box while items are added.
                PackageListBox.BeginUpdate();
                PackageListBox.Items.Clear();
                foreach (string package in packages)
                {
                    PackageListBox.Items.Add(package);
                }
                // Resume drawing of the list box.
                PackageListBox.EndUpdate();
            }
            catch (AdbException ex)
            {
                MessageBox.Show(ex.Message,
                                "ADB Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }