1
Fork 0

Changed function definition, optimized code, and added function for ejecting drive

This commit is contained in:
Jake Howard 2014-07-22 21:12:00 +01:00
parent 37eb469c49
commit 011a1c3921

View file

@ -9,7 +9,7 @@ namespace Saviour_Backup_System
{ {
public class USBTools public class USBTools
{ {
public DriveInfo[] getConnectedDrives() public static DriveInfo[] getConnectedDrives()
{ {
List<DriveInfo> drivesList = new List<DriveInfo>(); List<DriveInfo> drivesList = new List<DriveInfo>();
DriveInfo[] drives = DriveInfo.GetDrives(); DriveInfo[] drives = DriveInfo.GetDrives();
@ -17,12 +17,15 @@ namespace Saviour_Backup_System
try { try {
string driveName = drive.VolumeLabel; string driveName = drive.VolumeLabel;
string driveLetter = drive.Name; string driveLetter = drive.Name;
} catch { // If there is a problem getting the drive data, then the program would crash! } catch { continue; }
continue;
}
drivesList.Add(drive); drivesList.Add(drive);
} }
return drivesList.ToArray(); return drivesList.ToArray();
} }
public void safelyEjectDrive(string driveChar)
{
driveChar = driveChar.Remove(driveChar.Length - 1);
RemoveDriveTools.RemoveDrive(driveChar);
}
} }
} }