private void btnRefresh_Click(object sender, EventArgs e) { try { btnRefresh.Enabled = false; btnRefresh.Cursor = Cursors.WaitCursor; List <Device> device = UsbDevice.GetDevice(); ListView.ListViewItemCollection items = devicelist.Items; foreach (string str in FlashingDevice.flashDeviceList.Where(d => d.IsDone.Value).Select(d => d.Name).ToList()) { foreach (Device flashDevice in FlashingDevice.flashDeviceList) { if (flashDevice.Name == str.ToString()) { FlashingDevice.flashDeviceList.Remove(flashDevice); break; } } foreach (ListViewItem listViewItem in items) { if (listViewItem.SubItems[1].Text == str.ToString()) { items.Remove(listViewItem); break; } } foreach (Control control in (ArrangedElementCollection)devicelist.Controls) { if (control.Name == str.ToString() + "progressbar") { devicelist.Controls.Remove(control); break; } } } using (List <Device> .Enumerator enumerator = device.GetEnumerator()) { while (enumerator.MoveNext()) { Device d = enumerator.Current; if (FlashingDevice.flashDeviceList.Where(fd => fd.Name == d.Name).Select(fd => fd.Name).Count() == 0) { int num1 = devicelist.Items.Count + 1; ListViewItem listViewItem = new ListViewItem(new string[6] { num1.ToString(), d.Name, "", "0s", "", "" }); devicelist.Items.Add(listViewItem); d.ID = num1; d.Progress = 0.0f; d.IsDone = new bool?(); FlashingDevice.flashDeviceList.Add(d); float num2 = 0.0f; Rectangle rectangle = new Rectangle(); ProgressBar progressBar = new ProgressBar(); rectangle = listViewItem.SubItems[2].Bounds; rectangle.Width = devicelist.Columns[2].Width; progressBar.Parent = devicelist; progressBar.SetBounds(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); progressBar.Value = (int)num2; progressBar.Visible = true; progressBar.Name = d.Name + "progressbar"; } } } } catch (Exception ex) { Log.w(ex.Message); int num = (int)MessageBox.Show(ex.Message); } finally { btnRefresh.Enabled = true; btnRefresh.Cursor = Cursors.Default; } }
private void btnRefresh_Click(object sender, EventArgs e) { try { // var command = string.Format("pushd \"{0}\"&&prompt $$&&set PATH=\"{1}\";%PATH%&&\"{2}\" -s {3}&&popd", // "F:\\Dev\\mi\\MiFlash\\bin\\Debug\\images", Script.AndroidPath, "flash.bat", "djhgjhgvjh"); // TODO check if this should be _txtPath var command = string.Format("pushd \"{0}\"&&prompt $$&&set PATH=\"{1}\";%PATH%&&\"{2}\" -s {3}&&popd", _txtPath.Text, Script.AndroidPath, "flash.bat", "djhgjhgvjh"); Log.w("Command:" + command); _btnRefresh.Enabled = false; _btnRefresh.Cursor = Cursors.WaitCursor; var device = UsbDevice.GetDevice(); var items = _devicelist.Items; foreach (var str in FlashingDevice.flashDeviceList.Where(d => d.IsDone.Value).Select(d => d.Name) .ToList()) { foreach (var flashDevice in FlashingDevice.flashDeviceList) { if (flashDevice.Name == str) { FlashingDevice.flashDeviceList.Remove(flashDevice); break; } } foreach (ListViewItem listViewItem in items) { if (listViewItem.SubItems[1].Text == str) { items.Remove(listViewItem); break; } } foreach (Control control in (ArrangedElementCollection)_devicelist.Controls) { if (control.Name == str + "progressbar") { _devicelist.Controls.Remove(control); break; } } } using (var enumerator = device.GetEnumerator()) { while (enumerator.MoveNext()) { var d = enumerator.Current; if (FlashingDevice.flashDeviceList.Where(fd => fd.Name == d.Name).Select(fd => fd.Name) .Count() == 0) { var num1 = _devicelist.Items.Count + 1; var listViewItem = new ListViewItem(new string[6] { num1.ToString(), d.Name, "", "0s", "", "" }); _devicelist.Items.Add(listViewItem); d.ID = num1; d.Progress = 0.0f; d.IsDone = new bool?(); FlashingDevice.flashDeviceList.Add(d); var num2 = 0.0f; var rectangle = new Rectangle(); var progressBar = new ProgressBar(); rectangle = listViewItem.SubItems[2].Bounds; rectangle.Width = _devicelist.Columns[2].Width; progressBar.Parent = _devicelist; progressBar.SetBounds(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); progressBar.Value = (int)num2; progressBar.Visible = true; progressBar.Name = d.Name + "progressbar"; } } } } catch (Exception ex) { Log.w(ex.Message); var num = (int)MessageBox.Show(ex.Message); } finally { _btnRefresh.Enabled = true; _btnRefresh.Cursor = Cursors.Default; } }