Beispiel #1
0
        /// <summary>
        ///   Gets a list of Devices that can be selected
        /// </summary>
        /// <param name="onlyRemoveable"> If set to false also Fixed devices will be included in the list (most likely useless) </param>
        /// <returns> List of devices used for the MMC Flasher </returns>
        internal static IList <MMCDevice> GetDevices(bool onlyRemoveable = true)
        {
            var tmp = new Dictionary <int, MMCDevice>();

            foreach (var drive in DriveInfo.GetDrives())
            {
                if (drive.DriveType == DriveType.Fixed && onlyRemoveable)
                {
                    continue;
                }
                if (drive.DriveType != DriveType.Removable && drive.DriveType != DriveType.Fixed)
                {
                    continue;
                }
                try {
                    Main.SendDebug(string.Format("Getting Drive number for Device: {0}", drive.Name));
                    var devnum = NativeWin32.GetDeviceNumber(drive.Name);
                    if (!tmp.ContainsKey(devnum))
                    {
                        Main.SendDebug(string.Format("Getting Drive path for Device: {0}", drive.Name));
                        var path = NativeWin32.GetDevicePath(drive.Name);
                        Main.SendDebug(string.Format("Getting Drive Geometry for Device: {0}", drive.Name));
                        tmp.Add(devnum, new MMCDevice(drive.Name, path, NativeWin32.GetGeometry(path)));
                    }
                    else
                    {
                        tmp[devnum].DisplayName = string.Format("{0}, {1}", tmp[devnum].DisplayName, drive.Name);
                    }
                }
                catch (Exception ex) {
                    var dex = ex as DeviceError;
                    if (dex != null && dex.Win32ErrorNumber == 32)
                    {
                        continue;
                    }
                    throw;
                }
            }
            Main.SendDebug("Copying data to returnable object");
            var ret = new MMCDevice[tmp.Values.Count];

            tmp.Values.CopyTo(ret, 0);
            return(ret);
        }