public void Update_listview_folders(ListView list_view_files)//обновляет список с папками и файлами { list_view_files.Items.Clear(); foreach (var file in from filepath in Get_all_files() select Path.GetFileName(filepath)) { try { Icon extractedIcon = Files_ico_Win32API.GetIcon(Path.Combine(currentDirName, file), true); list_view_files.Items.Add(new File_ico_and_name { Name = file, Ico = Convert_images.Convert_to_ImageSource(extractedIcon.ToBitmap()) }); } catch (Exception ex) { MessageBox.Show($"Не удалось загрузить папку так как в ней есть системные файлы - {ex}"); break; } } }
private async void Get_all_drives(ListView list_view_disks)//получает список всех доступных дисков и устройств динамически обновляя их { while (true) { var new_drives = DriveInfo.GetDrives(); bool not_all_equal = false;//не все приводы/диски равны if (AllDrives != null && AllDrives.Length == new_drives.Length) { for (int i = 0; i < new_drives.Length; i++) { if (new_drives[i].Name == AllDrives[i].Name && new_drives[i].DriveType == AllDrives[i].DriveType) { //у драйверов совпадает имя и тип значит они равны } else { not_all_equal = true; break; } } } else { not_all_equal = true; } if (not_all_equal) { list_view_disks.Items.Clear(); AllDrives = new_drives; //обновим список приводов на новый Hardware_ico_and_info img_and_info; for (int i = 0; i < AllDrives.Length; i++) //Добавим по картинке к каждому устройству { img_and_info.drive_info = AllDrives[i]; switch (AllDrives[i].DriveType) { case DriveType.Fixed: img_and_info.hardware_ico = Convert_images.Convert_to_ImageSource(Properties.Resources.hp_hdd.ToBitmap()); break; case DriveType.Removable: img_and_info.hardware_ico = Convert_images.Convert_to_ImageSource(Properties.Resources.hp_flash_drive.ToBitmap()); break; case DriveType.Network: img_and_info.hardware_ico = Convert_images.Convert_to_ImageSource(Properties.Resources.network_connection_control_panel.ToBitmap()); break; case DriveType.CDRom: img_and_info.hardware_ico = Convert_images.Convert_to_ImageSource(Properties.Resources.hd_cdrom.ToBitmap()); break; default: img_and_info.hardware_ico = Convert_images.Convert_to_ImageSource(Properties.Resources.question_shield.ToBitmap()); break; } if (img_and_info.drive_info.IsReady) { list_view_disks.Items.Add(new { VolumeLabel = img_and_info.drive_info.VolumeLabel, Name = img_and_info.drive_info.Name, AvailableFreeSpace = img_and_info.drive_info.AvailableFreeSpace >> 30, TotalSize = img_and_info.drive_info.TotalSize >> 30, Img = img_and_info.hardware_ico }); } else { list_view_disks.Items.Add(new { VolumeLabel = "Uknown", Name = img_and_info.drive_info.Name, Img = img_and_info.hardware_ico }); } } } else { ; } if (AllDrives.Length > 0) { //Значит все хорошо, так как в системе есть хоть одно запоминающее устройство await Task.Delay(disks_interrogation_delay); } else { throw new Exception("На данном устройстве нет доступных драйверов!!!"); } } }