public DriveErasureTargetConfigurer() { InitializeComponent(); Theming.ApplyTheme(this); //Populate the drives list List <VolumeInfo> volumes = new List <VolumeInfo>(); foreach (PhysicalDriveInfo drive in PhysicalDriveInfo.Drives) { PartitionItem item = new PartitionItem(); item.PhysicalDrive = drive; partitionCmb.Items.Add(item); foreach (VolumeInfo volume in drive.Volumes) { item = new PartitionItem(); item.Volume = volume; if (volume.IsMounted) { DirectoryInfo root = volume.MountPoints[0]; item.Icon = root.GetIcon(); } partitionCmb.Items.Add(item); volumes.Add(volume); } } //And then add volumes which aren't accounted for (notably, Dynamic volumes) foreach (VolumeInfo volume in VolumeInfo.Volumes) { if (volumes.IndexOf(volume) == -1 && volume.VolumeType == DriveType.Fixed) { PartitionItem item = new PartitionItem(); item.Volume = volume; if (volume.IsMounted) { DirectoryInfo root = volume.MountPoints[0]; item.Icon = root.GetIcon(); } partitionCmb.Items.Insert(0, item); volumes.Add(volume); } } if (partitionCmb.Items.Count != 0) { partitionCmb.SelectedIndex = 0; } }
public bool SaveTo(IErasureTarget target) { DriveErasureTarget partition = target as DriveErasureTarget; if (partition == null) { throw new ArgumentException("The provided erasure target type is not " + "supported by this configurer."); } PartitionItem item = (PartitionItem)partitionCmb.SelectedItem; //Make sure we don't set both Volume and PhysicalDrive partition.PhysicalDrive = null; //Then set the proper values. partition.Volume = item.Volume; partition.PhysicalDrive = item.PhysicalDrive; return(true); }
private void OnDrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } Graphics g = e.Graphics; PartitionItem item = (PartitionItem)partitionCmb.Items[e.Index]; Color textColour = e.ForeColor; PointF textPos = e.Bounds.Location; if (item.Icon != null) { textPos.X += item.Icon.Width + 4; } textPos.Y += 1; //Set the text colour and background colour if the control is disabled if ((e.State & DrawItemState.Disabled) == 0) { e.DrawBackground(); } else { g.FillRectangle(new SolidBrush(SystemColors.ButtonFace), e.Bounds); textColour = SystemColors.GrayText; } if (item.Icon != null) { g.DrawIcon(item.Icon, e.Bounds.X + 2, e.Bounds.Y); } g.DrawString(item.ToString(), e.Font, new SolidBrush(textColour), textPos); if ((e.State & DrawItemState.Focus) != 0) { e.DrawFocusRectangle(); } }