Exemple #1
0
        /// <summary>
        /// Refresh the disk selection by (re-)enumerating the available devices of the system.
        /// </summary>
        private void RefreshPage()
        {
            // store the currently selected device (if any)
            Device selectedDevice = SelectedDevice;

            // clear the devices already enumerated in the list-view
            lsvDevices.Items.Clear();

            // enumerating the devices can take quite a time if a harddisk has to spin up: use progress dialog
            FormProgress dlg = new FormProgress();

            dlg.DoWork += backgroundWorker_DoWork;
            dlg.ShowDialog(this);

            // the devices have been enumerated
            foreach (PhysicalDrive.DriveInfo drive in drives)
            {
                ListViewItem item = new ListViewItem(string.Format("{0} {1}:", PageContext.GetInstance().GetResourceString("Disk"), drive.DriveNumber));
                item.Font = new Font(item.Font, FontStyle.Bold);
                item.Tag  = new Device(drive);
                item.SubItems.Add("");
                item.SubItems.Add(PhysicalDrive.GetAsBestFitSizeUnit(drive.Size));
                item.SubItems.Add("");
                lsvDevices.Items.Add(item);



                foreach (PhysicalDrive.PARTITION_INFORMATION_EX partition in drive.Partitions)
                {
                    PhysicalDrive.VolumeInfo volumeInfo = null;
                    foreach (PhysicalDrive.VolumeInfo volume in volumes)
                    {
                        if ((volume.DeviceInfo.DeviceNumber == drive.DriveNumber) && (volume.DeviceInfo.PartitionNumber == partition.PartitionNumber))
                        {
                            volumeInfo = volume;
                            break;
                        }
                    }
                    item     = new ListViewItem(string.Format(@"\Device\Harddisk{0}\Partition{1}", drive.DriveNumber, partition.PartitionNumber));
                    item.Tag = new Device(drive, partition.PartitionNumber);
                    item.SubItems.Add((volumeInfo != null) ? volumeInfo.RootPath : string.Empty);
                    item.SubItems.Add(PhysicalDrive.GetAsBestFitSizeUnit(partition.PartitionLength));
                    item.SubItems.Add((volumeInfo != null) ? volumeInfo.Label : string.Empty);
                    lsvDevices.Items.Add(item);

                    // re-select the previously selected device if it still exists
                    if ((selectedDevice != null) && selectedDevice.Partition.HasValue &&
                        (drive.DriveNumber == selectedDevice.Drive.DriveNumber) && (partition.PartitionNumber == selectedDevice.Partition.Value))
                    {
                        item.Focused  = true;
                        item.Selected = true;
                    }
                }
            }

            // the ready state of the wizard page might have changed
            lsvPhysicalDrives_SelectedIndexChanged(this, new EventArgs());
        }
Exemple #2
0
        /// <summary>
        /// Refresh the disk selection by (re-)enumerating the available disks of the system.
        /// </summary>
        private void RefreshPage()
        {
            // store the currently selected physical drive (if any)
            Device selectedDisk = SelectedDisk;

            // clear the physical drives already enumerated in the list-view
            lsvPhysicalDrives.Items.Clear();

            // enumerating the physical drives can take quite a time if a harddisk has to spin up: use progress dialog
            FormProgress dlg = new FormProgress();

            dlg.DoWork += backgroundWorker_DoWork;
            dlg.ShowDialog(this);

            // the physical drives have been enumerated
            foreach (PhysicalDrive.DriveInfo drive in drives)
            {
                ListViewItem item = new ListViewItem(string.Format("{0} {1}", PageContext.GetInstance().GetResourceString("Disk"), drive.DriveNumber));
                item.Tag = new Device(drive);

                string type;
                switch (drive.PartitionStyle)
                {
                case PhysicalDrive.PARTITION_STYLE.PARTITION_STYLE_MBR:
                    type = "MBR";
                    break;

                case PhysicalDrive.PARTITION_STYLE.PARTITION_STYLE_GPT:
                    type = "GPT";
                    break;

                default:
                    type = "RAW";
                    break;
                }
                item.SubItems.Add(type);
                item.SubItems.Add(PhysicalDrive.GetAsBestFitSizeUnit(drive.Size));
                item.SubItems.Add((drive.Size / drive.Geometry.BytesPerSector).ToString());
                item.SubItems.Add(string.Format("{0}/{1}/{2}", drive.Geometry.Cylinders, drive.Geometry.TracksPerCylinder, drive.Geometry.SectorsPerTrack));
                lsvPhysicalDrives.Items.Add(item);

                // re-select the previously selected physical drive if it still exists
                if ((selectedDisk != null) && (drive.DriveNumber == selectedDisk.Drive.DriveNumber))
                {
                    item.Focused  = true;
                    item.Selected = true;
                }
            }

            // the ready state of the wizard page might have changed
            lsvPhysicalDrives_SelectedIndexChanged(this, new EventArgs());
        }