Exemplo n.º 1
0
        public List<DriveInfo> GetAll(bool readyDrivesOnly)
        {
            List<DriveInfo> drives = new List<DriveInfo> ();
            VolumeMonitor volmon = GLib.VolumeMonitor.Default;

            foreach (Mount m in volmon.Mounts) {
                DriveInfo d = new DriveInfo();

                FillDriveInfoFromMount(d, m,
                    (m.Volume != null) ? m.Volume.GetIdentifier (G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) : string.Empty);

                drives.Add(d);
            }

            if (!readyDrivesOnly) {
                foreach (Volume v in volmon.Volumes) {
                    if (drives.FindIndex(di => (v.GetIdentifier(G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) == di.Device)) == -1) {
                        // Volume is unmounted or else it would have been referenced via volmon.Mounts
                        DriveInfo d = new DriveInfo();

                        d.device = v.GetIdentifier(G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
                        d.driveType = GuessDriveType(null, v.Icon, v.Drive);

                        drives.Add(d);
                    }
                }

                foreach (Drive dr in volmon.ConnectedDrives) {
                    if (dr.IsMediaRemovable && !dr.HasMedia) {
                        DriveInfo d = new DriveInfo();

                        d.device = dr.GetIdentifier(G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
                        d.driveType = GuessDriveType(null, dr.Icon, dr);

                        drives.Add(d);
                    }
                }
            }

            return drives;
        }