1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
saviour-backup-system/Saviour Backup System/USBTools.cs

66 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Timers;
using System.Data.SqlClient;
namespace Saviour_Backup_System
{
public class USBTools
{
public static void initDriveScan(){
Timer scanTimer = new Timer();
scanTimer.Elapsed += new ElapsedEventHandler(driveScanTick);
scanTimer.Interval = 1000 * 7; //seconds to check for new drives
scanTimer.Start();
}
private static List<string> connectedDrives = null;
private static void driveScanTick(object sender, ElapsedEventArgs e)
{
List<string> drivesSnapshot = connectedDrives;
DriveInfo[] drives = getConnectedDrives();
foreach (DriveInfo drive in drives)
{
connectedDrives.Add(drive.VolumeLabel);
}
if (connectedDrives.All(item => drivesSnapshot.Contains(item)) &&
drivesSnapshot.All(item => connectedDrives.Contains(item))) {
return;
} else {
//check if record exists in database
}
}
public static DriveInfo[] getConnectedDrives()
{
2014-07-21 12:39:57 +01:00
List<DriveInfo> drivesList = new List<DriveInfo>();
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
try {
string driveName = drive.VolumeLabel;
string driveLetter = drive.Name;
} catch { continue; }
2014-07-21 12:39:57 +01:00
drivesList.Add(drive);
}
return drivesList.ToArray();
}
public void safelyEjectDrive(string driveChar)
{
driveChar = driveChar.Remove(driveChar.Length - 1);
RemoveDriveTools.RemoveDrive(driveChar);
}
public static void displayDriveDetails(string driveName)
{
DriveInfo selectedDrive;
foreach (DriveInfo drive in getConnectedDrives()){ if (drive.Name == driveName){ selectedDrive = drive; break; } }
}
}
}