public PreferencesForm() { InitializeComponent(); DeviseAddr addr = new DeviseAddr(); if (addr.IsValid()) { tbIP.Text = addr.IP; tbPort.Text = addr.PORT; } if (!string.IsNullOrEmpty(addr.ADBPath)) { tbADB.Text = addr.ADBPath; } else { tbADB.Text = ADBRunner.FindADB(); } if (!string.IsNullOrEmpty(addr.ConnectionType)) { rbUSB.Checked = addr.ConnectionType.Equals("usb"); } cbDevices.Items.Clear(); ADBCommand commandDev = new ADBCommand(); CommandResult retDev = commandDev.Devices(); if (retDev.IsSuccess) { foreach (var str in retDev.Message.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { if (!string.IsNullOrEmpty(str)) { string[] s = str.Split(' '); if (s.Any()) { cbDevices.Items.Add(s[0]); } } } } if (!string.IsNullOrEmpty(addr.UsbDevice)) { if (cbDevices.Items.Contains(addr.UsbDevice)) { cbDevices.SelectedItem = addr.UsbDevice; } } }
private void btnSave_Click(object sender, EventArgs e) { DeviseAddr addr = new DeviseAddr(tbIP.Text, tbPort.Text); if (addr.IsValid()) { addr.Save(rbIP.Checked, cbDevices.SelectedItem != null ? cbDevices.SelectedItem.ToString() : "", tbADB.Text); } else { DeviseAddr addr1 = new DeviseAddr("192.168.100.1", "5555"); addr1.Save(rbIP.Checked, cbDevices.SelectedItem != null ? cbDevices.SelectedItem.ToString() : "", tbADB.Text); } Close(); }