/// <summary> /// to add drivers /// </summary> public void AddDrivers(PacketFileManager_GetDrivers packet) { #region Drivers // a new temp listviewitem to add PacketFileManager_DriverPacket fields List <ListViewItem> driversList = new List <ListViewItem>(); foreach (PacketFileManager_DriverPacket driver in packet.ListDrivers) { ListViewItem item = new ListViewItem { Text = driver.Name, ToolTipText = driver.Name, Group = betterListView1.Groups["Drivers"], }; item.SubItems.AddRange(new string[] { driver.Type, driver.Size }); driversList.Add(item); } #endregion this.Invoke((MethodInvoker) delegate { betterListView1.BeginUpdate(); betterListView1.Items.Clear(); txtError.Text = string.Empty; txtPath.Text = string.Empty; betterListView1.Items.AddRange(driversList.ToArray()); betterListView1.Enabled = true; betterListView1.Focus(); betterListView1.EndUpdate(); }); }
public void GetDrivers(SocketClient client, PacketFileManager_GetDrivers packet) { if (client.CurrentForms.GetFormFileManager != null) { client.CurrentForms.GetFormFileManager.AddDrivers(packet); } }
/// <summary> /// get all ready drivers and send them back to file manager form /// </summary> public void GetDrivers() { // a new list to store all drivers PacketFileManager_GetDrivers packetDrivers = new PacketFileManager_GetDrivers { ListDrivers = new List <PacketFileManager_DriverPacket>() }; foreach (DriveInfo driver in DriveInfo.GetDrives()) { if (driver.IsReady) { packetDrivers.ListDrivers.Add(new PacketFileManager_DriverPacket { Name = driver.Name, Type = driver.DriveType.ToString(), Size = $"{Convertor.IntegerToUnitData(driver.AvailableFreeSpace)} free of {Convertor.IntegerToUnitData(driver.TotalSize)}", }); } } ClientSocket.Send(packetDrivers); }