Beispiel #1
0
 public DeviceInfo(DeviceEnumerator deviceEnumerator, SP_DEVINFO_DATA devinfoData, string devicePath, string deviceID, string userFriendlyName)
 {
     this.deviceEnumerator = deviceEnumerator;
     this.devinfoData      = devinfoData;
     DevicePath            = devicePath;
     DeviceID         = deviceID;
     UserFriendlyName = userFriendlyName;
 }
 public DeviceInfo(DeviceEnumerator deviceEnumerator, SP_DEVINFO_DATA devinfoData, string devicePath, string deviceID, string userFriendlyName)
 {
     this.deviceEnumerator = deviceEnumerator;
     this.devinfoData = devinfoData;
     DevicePath = devicePath;
     DeviceID = deviceID;
     UserFriendlyName = userFriendlyName;
 }
Beispiel #3
0
        List <DiskRecord> QueryAllDisks()
        {
            List <DiskRecord> disks = new List <DiskRecord>();

            try
            {
                using (var devenum = new DeviceEnumerator(GUID_DEVINTERFACE_DISK))
                    foreach (var info in devenum.GetAllDevices())
                    {
                        long volumeSize = 0;
                        DiskDevice.STORAGE_HOTPLUG_INFO      hotplug = null;
                        DiskDevice.STORAGE_DEVICE_DESCRIPTOR desc    = null;
                        try
                        {
                            using (var dev = new DiskDevice(info.DevicePath))
                            {
                                try
                                {
                                    hotplug = dev.QueryHotplugInfo();
                                }
                                catch (Exception ex)
                                {
                                }

                                try
                                {
                                    desc = dev.QueryDeviceDescriptor();
                                }
                                catch
                                {
                                }

                                byte[] result = new byte[8];
                                try
                                {
                                    if (dev.DeviceIoControl(IOCTL_DISK_GET_LENGTH_INFO, null, result) == 8)
                                    {
                                        volumeSize = BitConverter.ToInt64(result, 0);
                                    }
                                }
                                catch
                                {
                                }
                            }

                            disks.Add(new DiskRecord {
                                Descriptor = desc, Hotplug = hotplug, Info = info, VolumeSize = volumeSize
                            });
                        }
                        catch { }
                    }
            }
            catch
            {
            }
            return(disks);
        }
        public EraseConfirmationForm(DeviceEnumerator.DeviceInfo info, DiskDevice dev, long volumeSize)
        {
            InitializeComponent();
            this.info = info;

            lblDevName.Text = info.UserFriendlyName;
            lblDevSize.Text = StringHelpers.FormatByteCount(volumeSize) + "B";

            var num = dev.QueryDeviceNumber();
            if (num == null)
                lblInternalName.Text = "Unknown";
            else
                lblInternalName.Text = string.Format(@"\\.\PHYSICALDRIVE{0}", num.DeviceNumber);

            Dictionary<int, string> volumesByPartitionNumbers = null;

            try
            {
                if (num != null)
                    volumesByPartitionNumbers = VolumeManager.GetVolumesForPhysicalDisk(num.DeviceNumber);
            }
            catch
            {
            	
            }

            var layout = dev.QueryLayoutInformation();
            if (layout != null)
                for (int i = 0; i < layout.PartitionCount; i++ )
                {
                    if (layout.PartitionEntry[i].PartitionType == 0)
                        continue;

                    ListViewItem lvi = new ListViewItem((i + 1).ToString());
                    lvi.SubItems.Add(StringHelpers.FormatByteCount(layout.PartitionEntry[i].StartingOffset) + "B");
                    lvi.SubItems.Add(StringHelpers.FormatByteCount(layout.PartitionEntry[i].PartitionLength) + "B");
                    lvi.SubItems.Add(MapPartitionType(layout.PartitionEntry[i].PartitionType));

                    string volID;
                    bool found = false;
                    if (volumesByPartitionNumbers != null && volumesByPartitionNumbers.TryGetValue(layout.PartitionEntry[i].PartitionNumber, out volID))
                    {
                        volumesByPartitionNumbers.Remove(layout.PartitionEntry[i].PartitionNumber);
                        string mountPoints = VolumeManager.GetVolumeMountPoints(volID, '|');
                        if (mountPoints != null)
                        {
                            lvi.Tag = mountPoints.Split('|')[0];
                            lvi.SubItems.Add(mountPoints.Replace("|", ";  "));
                            found = mountPoints.Length > 0;
                        }
                    }

                    lvi.ImageIndex = found ? 0 : 1;

                    lvPartitions.Items.Add(lvi);
                }
        }
Beispiel #5
0
        void WriteThreadBody(object obj)
        {
            ThreadContext ctx = (ThreadContext)obj;

            UpdateProgress("Erasing partition table...", 0, 0);
            try
            {
                //Erase
                ctx.dev.SeekAbs(0);
                ctx.dev.Write(new byte[SectorSize]);
                ctx.dev.Dispose();
                ctx.dev = null;

                string devPath = null;

                using (var devenum = new DeviceEnumerator(GUID_DEVINTERFACE_DISK))
                    foreach (var info in devenum.GetAllDevices())
                    {
                        if (info.DeviceID == ctx.devID)
                        {
                            devPath = info.DevicePath;
                            if (!info.ChangeDeviceState(DeviceEnumerator.DICS.DICS_DISABLE))
                                throw new Exception("Cannot reset the card reader. Please remove the card, put it back and retry.");
                            if (!info.ChangeDeviceState(DeviceEnumerator.DICS.DICS_ENABLE))
                                throw new Exception("Cannot re-enable the card reader. Please enable it manually using device manager.");
                        }
                    }

                if (devPath == null)
                    throw new Exception("Cannot reset the card reader. Please remove the card, put it back and retry.");

                for (; ; )
                {
                    if (AttemptWrite(ctx, devPath))
                        break;
                }

                ReportCompletion(null);
            }
            catch (System.Exception ex)
            {
                ReportCompletion(ex);
            }
            finally
            {
                if (ctx.fs != null)
                    ctx.fs.Dispose();
                if (ctx.dev != null)
                    ctx.dev.Dispose();
            }
        }
Beispiel #6
0
        List<DiskRecord> QueryAllDisks()
        {
            List<DiskRecord> disks = new List<DiskRecord>();
            try
            {
                using (var devenum = new DeviceEnumerator(GUID_DEVINTERFACE_DISK))
                    foreach (var info in devenum.GetAllDevices())
                    {
                        long volumeSize = 0;
                        DiskDevice.STORAGE_HOTPLUG_INFO hotplug = null;
                        DiskDevice.STORAGE_DEVICE_DESCRIPTOR desc = null;
                        try
                        {
                            using (var dev = new DiskDevice(info.DevicePath))
                            {
                                try
                                {
                                    hotplug = dev.QueryHotplugInfo();
                                }
                                catch (Exception ex)
                                {

                                }

                                try
                                {
                                    desc = dev.QueryDeviceDescriptor();
                                }
                                catch
                                {

                                }

                                byte[] result = new byte[8];
                                try
                                {
                                    if (dev.DeviceIoControl(IOCTL_DISK_GET_LENGTH_INFO, null, result) == 8)
                                        volumeSize = BitConverter.ToInt64(result, 0);
                                }
                                catch
                                {

                                }
                            }

                            disks.Add(new DiskRecord { Descriptor = desc, Hotplug = hotplug, Info = info, VolumeSize = volumeSize });
                        }
                        catch { }
                    }
            }
            catch
            {
            	
            }
            return disks;
        }
Beispiel #7
0
        void WriteThreadBody(object obj)
        {
            ThreadContext ctx = (ThreadContext)obj;

            UpdateProgress("Erasing partition table...", 0, 0);
            try
            {
                //Erase
                ctx.dev.SeekAbs(0);
                ctx.dev.Write(new byte[SectorSize]);
                ctx.dev.Dispose();
                ctx.dev = null;

                string devPath = null;

                using (var devenum = new DeviceEnumerator(GUID_DEVINTERFACE_DISK))
                    foreach (var info in devenum.GetAllDevices())
                    {
                        if (info.DeviceID == ctx.devID)
                        {
                            devPath = info.DevicePath;
                            if (!info.ChangeDeviceState(DeviceEnumerator.DICS.DICS_DISABLE))
                            {
                                throw new Exception("Cannot reset the card reader. Please remove the card, put it back and retry.");
                            }
                            if (!info.ChangeDeviceState(DeviceEnumerator.DICS.DICS_ENABLE))
                            {
                                throw new Exception("Cannot re-enable the card reader. Please enable it manually using device manager.");
                            }
                        }
                    }

                if (devPath == null)
                {
                    throw new Exception("Cannot reset the card reader. Please remove the card, put it back and retry.");
                }

                for (; ;)
                {
                    if (AttemptWrite(ctx, devPath))
                    {
                        break;
                    }
                }

                ReportCompletion(null);
            }
            catch (System.Exception ex)
            {
                ReportCompletion(ex);
            }
            finally
            {
                if (ctx.fs != null)
                {
                    ctx.fs.Dispose();
                }
                if (ctx.dev != null)
                {
                    ctx.dev.Dispose();
                }
            }
        }