Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 47 → Rev 48

/SWAT Office App/trunk/SWAT Office App/DriveLogger_Form.cs
30,6 → 30,7
{
// Disable thread safe checking
CheckForIllegalCrossThreadCalls = false;
 
driveEntryList.Clear();
InitializeComponent();
 
60,44 → 61,45
}
void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
// Compares a list of drives detected previously with the a list of current
// drives on the computer. If a change in length is detected, a drive is either
// added or removed so the drive in question is found and operated upon
List<string> drivesPreviouslyDetected = new List<string>();
List<string> drivesPreviouslyDetectedList = new List<string>();
DriveInfo[] newlyDetectedDrives = DriveInfo.GetDrives();
 
// Resets both lists to hold the same drives
drivesPreviouslyDetectedList.Clear();
foreach (DriveInfo drive in newlyDetectedDrives)
drivesPreviouslyDetected.Add(drive.Name);
drivesPreviouslyDetectedList.Add(drive.Name);
 
while (true)
{
// Pulls list of new drives
// Cancels thread if DriveLogger form is closed
if (!instanceAlreadyRunning)
{
//MessageBox.Show("Thread Stopped");
e.Cancel = true;
break;
}
// Pulls new list of current drives on computer
newlyDetectedDrives = DriveInfo.GetDrives();
if (newlyDetectedDrives.Length > drivesPreviouslyDetected.Count)
if (newlyDetectedDrives.Length > drivesPreviouslyDetectedList.Count)
{
// Applies if a drive is attached to the computer
// Goes through each list and finds the drive that was recently attached
bool attachedDriveExisted = false;
bool newDrivesDetected = false;
string driveOwner = "";
string driveDock = "";
foreach (DriveInfo drive in newlyDetectedDrives)
{
attachedDriveExisted = false;
// Loop here checks for non-matching entries in the two lists
foreach (string str in drivesPreviouslyDetected)
// Skips the drive if it is in the list of drives to ignore
if (Settings_Form.driveLoggerDrivesToIgnore.Contains(drive.Name))
continue;
 
// Check for non-matching entries in the two lists
if (!drivesPreviouslyDetectedList.Contains(drive.Name))
{
// If entries match, drive is unchanged
if (str == drive.Name)
{
attachedDriveExisted = true;
break;
}
}
// If list mismatch is detected, adds new entry to driveEntryList
if (attachedDriveExisted == false)
{
// Creates and populates a new DriveEntry
DriveEntry newEntry = new DriveEntry();
if (newDrivesDetected == false)
156,19 → 158,23
}
}
// Clears and refreshes the drivesPreviouslyDetected list
drivesPreviouslyDetected.Clear();
drivesPreviouslyDetectedList.Clear();
foreach (DriveInfo drive in newlyDetectedDrives)
{
drivesPreviouslyDetected.Add(drive.Name);
drivesPreviouslyDetectedList.Add(drive.Name);
}
}
else if (newlyDetectedDrives.Length < drivesPreviouslyDetected.Count)
if (newlyDetectedDrives.Length < drivesPreviouslyDetectedList.Count)
{
// Applies if a drive is removed to the computer
// Goes through each list and finds the drive that was recently removed
bool removedDriveFound = false;
foreach (string str in drivesPreviouslyDetected)
foreach (string str in drivesPreviouslyDetectedList)
{
// Skips the drive if it is in the list of drives to ignore
if (Settings_Form.driveLoggerDrivesToIgnore.Contains(str))
continue;
removedDriveFound = false;
// Loop here checks for non-matching entries in the two lists
foreach (DriveInfo drive in newlyDetectedDrives)
201,22 → 207,13
}
}
// Clears and refreshes the drivesPreviouslyDetected list
drivesPreviouslyDetected.Clear();
drivesPreviouslyDetectedList.Clear();
foreach (DriveInfo drive in newlyDetectedDrives)
{
drivesPreviouslyDetected.Add(drive.Name);
drivesPreviouslyDetectedList.Add(drive.Name);
}
}
else
{
// Sets the two lists to hold the same drives
drivesPreviouslyDetected.Clear();
foreach (DriveInfo drive in newlyDetectedDrives)
{
drivesPreviouslyDetected.Add(drive.Name);
}
}
 
// Sleeps the thread for a specified amount of time
Thread.Sleep(Settings_Form.driveLoggerRefreshInterval);
}