1
Fork 0

Removed try blocks, added length check to drive label display, added percentage to capacity bar, and changed access modifiers

This commit is contained in:
Jake Howard 2014-07-31 15:34:00 +01:00
parent c726c09d76
commit 281fdd87f0

View file

@ -12,7 +12,7 @@ namespace Saviour_Backup_System
{ {
public partial class mainWindow : Form public partial class mainWindow : Form
{ {
private DriveInfo selectedDrive = null; private DriveInfo selectedDrive;
public mainWindow() public mainWindow()
{ {
@ -22,27 +22,25 @@ namespace Saviour_Backup_System
clearDriveDetails(); clearDriveDetails();
formatDriveCapacityTimer.Start(); formatDriveCapacityTimer.Start();
//Starts the timer for refreshing drive list //Starts the timer for refreshing drive list
driveRefreshTimer.Start(); driveRefreshTimer.Start();
} }
public void refreshDriveList(){ internal void refreshDriveList(){
DriveInfo[] drives = USBTools.getConnectedDrives(); DriveInfo[] drives = USBTools.getConnectedDrives();
if (connectedDrivesList.Items.Count == USBTools.countDrives()) { return; } if (connectedDrivesList.Items.Count == USBTools.countDrives()) { return; }
connectedDrivesList.Items.Clear(); connectedDrivesList.Items.Clear();
bool deviceStillConnected = false; bool deviceStillConnected = false;
foreach (DriveInfo drive in drives){ foreach (DriveInfo drive in drives){
try { ListViewItem driveItem = new ListViewItem(drive.Name + " " + tools.Trim(drive.VolumeLabel, 24));
ListViewItem driveItem = new ListViewItem(drive.Name + " " + drive.VolumeLabel); driveItem.SubItems.Add("X");
driveItem.SubItems.Add("X"); connectedDrivesList.Items.Add(driveItem);
connectedDrivesList.Items.Add(driveItem); if (drive.VolumeLabel == driveNameDisplay.Text)
if (drive.VolumeLabel == driveNameDisplay.Text){ {
deviceStillConnected = true; deviceStillConnected = true;
driveItem.Selected = true; driveItem.Selected = true;
} }
} catch { continue; }
} }
if (!deviceStillConnected) { clearDriveDetails(); } if (!deviceStillConnected) { clearDriveDetails(); }
connectedDrivesList.Sort(); connectedDrivesList.Sort();
@ -74,7 +72,7 @@ namespace Saviour_Backup_System
foreach (DriveInfo drive in USBTools.getConnectedDrives()) { foreach (DriveInfo drive in USBTools.getConnectedDrives()) {
if (drive.Name == driveName) { selectedDrive = drive; break; } if (drive.Name == driveName) { selectedDrive = drive; break; }
} }
driveNameDisplay.Text = tools.Trim(selectedDrive.VolumeLabel, 15); driveNameDisplay.Text = tools.Trim(selectedDrive.VolumeLabel, 16);
driveLetterDisplay.Text = selectedDrive.Name; driveLetterDisplay.Text = selectedDrive.Name;
driveSystemDisplay.Text = selectedDrive.DriveFormat; driveSystemDisplay.Text = selectedDrive.DriveFormat;
driveTypeDisplay.Text = USBTools.getDriveType(selectedDrive); driveTypeDisplay.Text = USBTools.getDriveType(selectedDrive);
@ -101,6 +99,7 @@ namespace Saviour_Backup_System
while (driveCapacityPerc != driveCapacityDisplay.Value) { while (driveCapacityPerc != driveCapacityDisplay.Value) {
if (driveCapacityPerc < driveCapacityDisplay.Value) { driveCapacityDisplay.Value -= 1; } if (driveCapacityPerc < driveCapacityDisplay.Value) { driveCapacityDisplay.Value -= 1; }
if (driveCapacityPerc > driveCapacityDisplay.Value) { driveCapacityDisplay.Value += 1; } if (driveCapacityPerc > driveCapacityDisplay.Value) { driveCapacityDisplay.Value += 1; }
driveCapacityDisplay.Text = "Drive Capacity: " + (driveCapacityDisplay.Value / 100).ToString() + "%";
//adjust the colour of the progressbar depending on capacity of the drive //adjust the colour of the progressbar depending on capacity of the drive
if (driveCapacityDisplay.Value <= 6800) { driveCapacityDisplay.ColorTable = DevComponents.DotNetBar.eProgressBarItemColor.Normal; } if (driveCapacityDisplay.Value <= 6800) { driveCapacityDisplay.ColorTable = DevComponents.DotNetBar.eProgressBarItemColor.Normal; }