13,21 → 13,17 |
{ |
public struct DriveEntry |
{ |
/// <summary> |
/// Struct for storing the info on each drive that is inserted |
/// </summary> |
|
public DateTime time; |
public string status; |
//public string status; |
public string drive; |
public string label; |
public string owner; |
//public string owner; |
public string size; |
} |
public partial class MainForm : Form |
{ |
private static List<DriveEntry> driveList = new List<DriveEntry>(); |
|
private static string logLocation = "C:\\DriveLog.txt"; |
public MainForm() |
{ |
// Clears the list of DriveEntry structs |
36,12 → 32,19 |
DriveDetector driveDetector = new DriveDetector(); |
driveDetector.DeviceArrived += new DriveDetectorEventHandler(driveDetector_DeviceArrived); |
driveDetector.DeviceRemoved += new DriveDetectorEventHandler(driveDetector_DeviceRemoved); |
this.listView_Drives.AfterLabelEdit += new LabelEditEventHandler(listView_Drives_AfterLabelEdit); |
|
this.KeyPreview = true; |
this.KeyPress += new KeyPressEventHandler(MainForm_KeyPress); |
|
using (StreamWriter sw = File.AppendText(logLocation)) |
{ |
sw.WriteLine("-- New Session Started --"); |
sw.WriteLine("Initializing form details"); |
} |
// Adds columns to the listview in the form |
//this.listView_Drives.Columns.Add("Event", 60, HorizontalAlignment.Center); |
this.listView_Drives.Columns.Add("Owner", 150, HorizontalAlignment.Left); |
this.listView_Drives.Columns.Add("Time", 125, HorizontalAlignment.Center); |
this.listView_Drives.Columns.Add("Drive", 40, HorizontalAlignment.Center); |
this.listView_Drives.Columns.Add("Label", 109, HorizontalAlignment.Center); |
51,6 → 54,19 |
paintDriveListbox(); |
} |
|
void listView_Drives_AfterLabelEdit(object sender, LabelEditEventArgs e) |
{ |
if (e.Label != null) |
{ |
using (StreamWriter sw = File.AppendText(logLocation)) |
{ |
ListViewItem entry = listView_Drives.Items[e.Item]; |
|
sw.WriteLine("Label \"" + e.Label + "\" added to drive " + entry.SubItems[2].Text); |
} |
} |
} |
|
void MainForm_KeyPress(object sender, KeyPressEventArgs e) |
{ |
switch (e.KeyChar) |
71,11 → 87,11 |
foreach (DriveEntry entry in driveList) |
{ |
ListViewItem item = new ListViewItem(); |
//item.Text = entry.status; |
item.Text = entry.time.ToString(); |
//ListViewItem.ListViewSubItem subTime = new ListViewItem.ListViewSubItem(); |
//subTime.Text = entry.time.ToString(); |
//item.SubItems.Add(subTime); |
item.Text = ""; |
//item.Text = entry.time.ToString(); |
ListViewItem.ListViewSubItem subTime = new ListViewItem.ListViewSubItem(); |
subTime.Text = entry.time.ToString(); |
item.SubItems.Add(subTime); |
ListViewItem.ListViewSubItem subDrive = new ListViewItem.ListViewSubItem(); |
subDrive.Text = entry.drive; |
item.SubItems.Add(subDrive); |
85,9 → 101,9 |
ListViewItem.ListViewSubItem subSize = new ListViewItem.ListViewSubItem(); |
subSize.Text = entry.size; |
item.SubItems.Add(subSize); |
ListViewItem.ListViewSubItem subOwner = new ListViewItem.ListViewSubItem(); |
subOwner.Text = entry.owner; |
item.SubItems.Add(subOwner); |
//ListViewItem.ListViewSubItem subOwner = new ListViewItem.ListViewSubItem(); |
//subOwner.Text = entry.owner; |
//item.SubItems.Add(subOwner); |
|
this.listView_Drives.Items.Add(item); |
} |
99,7 → 115,7 |
e.HookQueryRemove = true; |
|
DriveEntry newEntry = new DriveEntry(); |
newEntry.status = "Inserted"; |
//newEntry.status = "Inserted"; |
newEntry.time = DateTime.Now; |
newEntry.drive = e.Drive; |
|
118,9 → 134,14 |
} |
newEntry.label = tempDrive.VolumeLabel; |
newEntry.size = (tempDrive.TotalSize / 1073741824).ToString() + " GB"; |
newEntry.owner = ""; |
//newEntry.owner = ""; |
driveList.Add(newEntry); |
|
using (StreamWriter sw = File.AppendText(logLocation)) |
{ |
sw.WriteLine("Drive Attached -- [" + newEntry.time.ToString() + "]\t" + newEntry.drive + "\t\"" + newEntry.label + "\"\t" + newEntry.size); |
} |
|
paintDriveListbox(); |
} |
void driveDetector_DeviceRemoved(object sender, DriveDetectorEventArgs e) |
136,6 → 157,11 |
} |
driveList.Remove(entryToRemove); |
|
using (StreamWriter sw = File.AppendText(logLocation)) |
{ |
sw.WriteLine("Drive Removed -- [" + entryToRemove.time.ToString() + "]\t" + entryToRemove.drive + "\t\"" + entryToRemove.label + "\"\t" + entryToRemove.size); |
} |
|
paintDriveListbox(); |
} |
} |