Beispiel #1
0
        public static List <UsbEject.Library.Volume> GetRemovableDriveList(List <UsbEject.Library.Device> list)
        {
            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 already has this volume
                if (removable_volumes.FirstOrDefault(v => v.Disks[0].FriendlyName == vol.Disks[0].FriendlyName) != null)
                {
                    continue;
                }

                removable_volumes.Add(vol);
            }

            return(removable_volumes);
        }
        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];
            }
        }
Beispiel #4
0
        private void m_btnEject_Click(object sender, EventArgs e)
        {
            ExecuteClickAction(() =>
            {
                UsbEject.Library.Volume device = m_treeDrives.SelectedNode.Tag as UsbEject.Library.Volume;
                if (device == null || device.Disks.Count == 0)
                {
                    return;
                }

                UnmountAndEjectDevice(device);
            }, sender);
        }
Beispiel #5
0
        private void UnmountAndEjectDevice(UsbEject.Library.Volume device)
        {
            List <UsbEject.Library.Device> list = DriveTools.GetUsbDriveList();
            List <string> driveLetters          = DriveTools.GetAllDriveLettersForDevice(list, device.Disks[0].FriendlyName);

            foreach (string dr in driveLetters)
            {
                _diskCryptor.ExecuteUnMount(dr);
            }

            Thread.Sleep(800);
            device.Eject(true);

            ReloadDriveData();
        }
        private void mnuEjectDisk_Click(object sender, EventArgs e)
        {
            ToolStripItem mnu = sender as ToolStripItem;

            if (mnu == null)
            {
                return;
            }
            UsbEject.Library.Volume vol = mnu.Tag as UsbEject.Library.Volume;
            if (vol == null)
            {
                return;
            }

            ExecuteClickAction(() => UnmountAndEjectDevice(vol), sender);
        }
Beispiel #7
0
        public static List <string> GetAllDriveLettersForDevice(List <UsbEject.Library.Device> drives, string deviceFriendlyName)
        {
            List <string> driveLetters = new List <string>();

            foreach (UsbEject.Library.Device device in drives)
            {
                UsbEject.Library.Volume volume = device as UsbEject.Library.Volume;
                if (volume == null || volume.Disks.Count == 0)
                {
                    continue;
                }

                if (volume.Disks[0].FriendlyName != deviceFriendlyName)
                {
                    continue;
                }

                driveLetters.Add(volume.LogicalDrive);
            }
            return(driveLetters);
        }