moved open braces, and add function for getting drive object from letter.
This commit is contained in:
parent
e3ee1d3e39
commit
35ad2d72bd
1 changed files with 19 additions and 15 deletions
|
@ -9,17 +9,16 @@ using System.Data.SqlClient;
|
||||||
|
|
||||||
namespace Saviour_Backup_System
|
namespace Saviour_Backup_System
|
||||||
{
|
{
|
||||||
class USBTools
|
class USBTools {
|
||||||
{
|
public static void initDriveScan() {
|
||||||
public static void initDriveScan(){
|
|
||||||
Timer scanTimer = new Timer();
|
Timer scanTimer = new Timer();
|
||||||
scanTimer.Elapsed += new ElapsedEventHandler(driveScanTick);
|
scanTimer.Elapsed += new ElapsedEventHandler(driveScanTick);
|
||||||
scanTimer.Interval = 1000 * 7; //seconds to check for new drives
|
scanTimer.Interval = 1000 * 7; //seconds to check for new drives
|
||||||
scanTimer.Start();
|
scanTimer.Start();
|
||||||
}
|
}
|
||||||
private static List<string> connectedDrives = null;
|
private static List<string> connectedDrives = null;
|
||||||
private static void driveScanTick(object sender, ElapsedEventArgs e)
|
|
||||||
{
|
private static void driveScanTick(object sender, ElapsedEventArgs e) {
|
||||||
List<string> drivesSnapshot = connectedDrives;
|
List<string> drivesSnapshot = connectedDrives;
|
||||||
DriveInfo[] drives = getConnectedDrives();
|
DriveInfo[] drives = getConnectedDrives();
|
||||||
foreach (DriveInfo drive in drives)
|
foreach (DriveInfo drive in drives)
|
||||||
|
@ -48,18 +47,25 @@ namespace Saviour_Backup_System
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void safelyEjectDrive(string driveChar)
|
public static DriveInfo getDriveObject(string driveChar) {
|
||||||
{
|
DriveInfo foundDrive = null;
|
||||||
|
foreach (DriveInfo drive in getConnectedDrives()){
|
||||||
|
if (drive.Name[0].ToString() == driveChar) {
|
||||||
|
foundDrive = drive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return foundDrive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void safelyEjectDrive(string driveChar) {
|
||||||
driveChar = driveChar.Remove(driveChar.Length - 1);
|
driveChar = driveChar.Remove(driveChar.Length - 1);
|
||||||
RemoveDriveTools.RemoveDrive(driveChar);
|
RemoveDriveTools.RemoveDrive(driveChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static string getDriveType(DriveInfo selectedDrive)
|
public static string getDriveType(DriveInfo selectedDrive) {
|
||||||
{
|
|
||||||
string driveTypeDecoded = "Error decoding drive details!";
|
string driveTypeDecoded = "Error decoding drive details!";
|
||||||
switch (selectedDrive.DriveType)
|
switch (selectedDrive.DriveType) {
|
||||||
{
|
|
||||||
case DriveType.CDRom:
|
case DriveType.CDRom:
|
||||||
driveTypeDecoded = "Optical Disk Drive";
|
driveTypeDecoded = "Optical Disk Drive";
|
||||||
break;
|
break;
|
||||||
|
@ -86,16 +92,14 @@ namespace Saviour_Backup_System
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int countDrives()
|
public static int countDrives() {
|
||||||
{
|
|
||||||
int numberofDrives = 0;
|
int numberofDrives = 0;
|
||||||
foreach (DriveInfo drive in getConnectedDrives()) { numberofDrives++; }
|
foreach (DriveInfo drive in getConnectedDrives()) { numberofDrives++; }
|
||||||
return numberofDrives;
|
return numberofDrives;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int spacePercentage(DriveInfo drive)
|
public static int spacePercentage(DriveInfo drive) {
|
||||||
{
|
|
||||||
double capacity = (double)(drive.TotalSize / (1024 * 1024));
|
double capacity = (double)(drive.TotalSize / (1024 * 1024));
|
||||||
double free = (double)(drive.AvailableFreeSpace / (1024 * 1024));
|
double free = (double)(drive.AvailableFreeSpace / (1024 * 1024));
|
||||||
double answer = (10000 - ((free / capacity) * 10000));
|
double answer = (10000 - ((free / capacity) * 10000));
|
||||||
|
|
Reference in a new issue