1
Fork 0

removed startup commands ready for redesign, put adding to list view into try, incase 2 drives are removed at once. Changed around devicetab visibility, and juggled around some more code to remove some of the bugs.

This commit is contained in:
Jake Howard 2014-08-01 22:14:26 +01:00
parent fb7e3d993f
commit 26ab54cd63

View file

@ -17,9 +17,11 @@ namespace Saviour_Backup_System
public mainWindow() public mainWindow()
{ {
InitializeComponent(); InitializeComponent();
//setup.initProgram(); ##Add in later!
refreshDriveList(); refreshDriveList();
clearDriveDetails(); connectedDrivesList.Items[0].Selected = true; //Selects the first item in the list of drives
displayDriveDetails(connectedDrivesList.SelectedItems[0].Text.Substring(0, 3)); //displays the info for the drive
//Starts the thread for displaying the capacity of a drive
formatDriveCapacityTimer.Start(); formatDriveCapacityTimer.Start();
//Starts the timer for refreshing drive list //Starts the timer for refreshing drive list
@ -33,6 +35,7 @@ namespace Saviour_Backup_System
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 + " " + tools.Trim(drive.VolumeLabel, 24));
driveItem.SubItems.Add("X"); driveItem.SubItems.Add("X");
connectedDrivesList.Items.Add(driveItem); connectedDrivesList.Items.Add(driveItem);
@ -42,6 +45,8 @@ namespace Saviour_Backup_System
driveItem.Selected = true; driveItem.Selected = true;
} }
} }
catch { continue; }
}
if (!deviceStillConnected) { clearDriveDetails(); } if (!deviceStillConnected) { clearDriveDetails(); }
connectedDrivesList.Sort(); connectedDrivesList.Sort();
} }
@ -50,18 +55,19 @@ namespace Saviour_Backup_System
private void connectedDrivesListRefresh_Click(object sender, EventArgs e) private void connectedDrivesListRefresh_Click(object sender, EventArgs e)
{ {
foreach (ListViewItem i in connectedDrivesList.SelectedItems){ i.Selected = false; } //Deselected all elements in the list first foreach (ListViewItem i in connectedDrivesList.SelectedItems){ i.Selected = false; } //Deselected all elements in the list first
clearDriveDetails();
refreshDriveList(); refreshDriveList();
} }
private void connectedDrivesList_Selection(object sender, ListViewItemSelectionChangedEventArgs e) { private void connectedDrivesList_Selection(object sender, ListViewItemSelectionChangedEventArgs e) {
deviceTab.Visible = e.IsSelected;
if (!e.IsSelected) { if (!e.IsSelected) {
deviceTab.Visible = false;
backupRestoreTab.Select(); backupRestoreTab.Select();
return; return;
} }
ribbonControl.RecalcLayout(); ribbonControl.RecalcLayout();
deviceTab.Select(); populateDeviceTab();
string selectedDevice = connectedDrivesList.SelectedItems[0].Text; string selectedDevice = connectedDrivesList.SelectedItems[0].Text;
displayDriveDetails(selectedDevice.Substring(0,3)); displayDriveDetails(selectedDevice.Substring(0,3));
} }
@ -88,7 +94,7 @@ namespace Saviour_Backup_System
driveIconBox.Image = Properties.Resources.hddIcon; driveIconBox.Image = Properties.Resources.hddIcon;
break; break;
} }
//formatDriveCapacity();
} }
@ -96,6 +102,7 @@ namespace Saviour_Backup_System
{ {
DriveInfo drive = selectedDrive; DriveInfo drive = selectedDrive;
int driveCapacityPerc = USBTools.spacePercentage(drive); int driveCapacityPerc = USBTools.spacePercentage(drive);
driveCapacityDisplay.Text = "Drive Capacity: " + (driveCapacityDisplay.Value / 100).ToString() + "%";
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; }
@ -112,11 +119,13 @@ namespace Saviour_Backup_System
private void clearDriveDetails() { private void clearDriveDetails() {
string blankText = ""; string blankText = "";
selectedDrive = null;
driveNameDisplay.Text = blankText; driveNameDisplay.Text = blankText;
driveLetterDisplay.Text = blankText; driveLetterDisplay.Text = blankText;
driveSystemDisplay.Text = blankText; driveSystemDisplay.Text = blankText;
driveTypeDisplay.Text = blankText; driveTypeDisplay.Text = blankText;
driveCapacityDisplay.Value = 0; driveCapacityDisplay.Value = 0;
driveCapacityDisplay.Text = blankText;
} }
@ -124,6 +133,10 @@ namespace Saviour_Backup_System
private void formatDriveCapacityTimer_Tick(object sender, EventArgs e) { try { formatDriveCapacity(); } catch { } } //Because background workers cant interact with the GUI (very quickly) private void formatDriveCapacityTimer_Tick(object sender, EventArgs e) { try { formatDriveCapacity(); } catch { } } //Because background workers cant interact with the GUI (very quickly)
private void populateDeviceTab() {
deviceTab.Visible = true;
deviceTab.Select();
}
} }
} }