private DiskCryptor.DriveInfo FindDriveInfo(string attachedPath) { List <UsbEject.Library.Device> list = DriveTools.GetUsbDriveList(); List <UsbEject.Library.Volume> removable_volumes = DriveTools.GetRemovableDriveList(list); const string PHYSICALDRIVE = "PHYSICALDRIVE"; int pos = attachedPath.IndexOf(PHYSICALDRIVE) + PHYSICALDRIVE.Length; int diskNumber = int.Parse(attachedPath.Substring(pos)); UsbEject.Library.Volume vol = null; foreach (UsbEject.Library.Volume device in list) { if (device.Disks[0].DiskNumber == diskNumber) { vol = device; break; } } if (vol == null) { return(null); } foreach (DiskCryptor.DriveInfo drive in _diskCryptor.DriveList) { if (drive != null && !string.IsNullOrWhiteSpace(drive.DriveLetter) && drive.DriveLetter[0] == vol.LogicalDrive[0]) { return(drive); } } return(null); }
private void ReloadDriveList() { m_treeDrives.Nodes.Clear(); m_mnuEject.DropDownItems.Clear(); List <UsbEject.Library.Device> list = DriveTools.GetUsbDriveList(); List <UsbEject.Library.Volume> removable_volumes = new List <UsbEject.Library.Volume>(); foreach (UsbEject.Library.Device drive in list) { if (drive.RemovableDevices.Count == 0) { continue; } UsbEject.Library.Volume vol = drive as UsbEject.Library.Volume; if (vol == null || vol.Disks.Count == 0) { continue; } if (removable_volumes.FirstOrDefault(v => v.Disks[0].FriendlyName == vol.Disks[0].FriendlyName) != null) { continue; } removable_volumes.Add(vol); TreeNode node = m_treeDrives.Nodes.Add(vol.Disks[0].FriendlyName); node.Tag = vol; List <string> driveLetters = DriveTools.GetUsbDriveList(vol); string mnuText = ""; foreach (string dr in driveLetters) { mnuText += (dr) + ", "; TreeNode sub = node.Nodes.Add(GetDriveDescription(dr)); sub.Tag = vol; } mnuText += "[" + vol.Disks[0].FriendlyName + "]"; ToolStripItem mnu = new ToolStripMenuItem(mnuText); mnu.Tag = vol; mnu.Click += mnuEjectDisk_Click;; m_mnuEject.DropDownItems.Add(mnu); } m_mnuEject.Enabled = m_mnuEject.DropDownItems.Count > 0; m_treeDrives.ExpandAll(); if (m_treeDrives.Nodes.Count > 0) { m_treeDrives.SelectedNode = m_treeDrives.Nodes[0]; } }
private void UnmountAndEjectDevice(UsbEject.Library.Device device) { List <string> driveLetters = DriveTools.GetUsbDriveList(device); foreach (string dr in driveLetters) { _diskCryptor.ExecuteUnMount(dr); } Thread.Sleep(800); device.Eject(true); ReloadDriveData(); }