Changed function definition, optimized code, and added function for ejecting drive
This commit is contained in:
parent
37eb469c49
commit
011a1c3921
1 changed files with 7 additions and 4 deletions
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue