private void loadDriveList() { VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); Object[] row = new Object[2]; foreach (Volume device in volumeDeviceClass.Devices) { if (device.IsUsb) { row[0] = device.LogicalDrive; row[1] = device.Serial; drivesModel.Tables[0].Rows.Add(row); driveListView.Items.Add(row[0].ToString(), 0); } } }
private static int Main(string[] args) { AttachConsole(ATTACH_TO_PARENT_PROCESS); options = new Options(); CommandLineParser parser = new CommandLineParser(options); try { parser.Parse(); } catch (Exception) { return (int) ExitCodes.INVALID_SYNTAX; } if (options.help) { Console.Error.WriteLine(parser.UsageInfo.ToString(78, false)); return (int) ExitCodes.OK; } VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); //options.list_devices = true; if (options.list_devices) { // List known usb devices and their serials foreach (Volume device in volumeDeviceClass.Devices) { if (device.IsUsb) { Console.WriteLine("Drive:" + device.LogicalDrive + ", ID:" + device.Serial); } } return (int) ExitCodes.OK; } //options.eject_device = true; //options.device_id = "{36FC9E60-C465-11CF-8056-444553540000}"; if (options.drive_letter) { try { Volume volume = volumeDeviceClass.FindBySerial(options.device_id); Console.Write(volume.LogicalDrive); return (int) ExitCodes.OK; } catch (DeviceNotFound) { return (int) ExitCodes.DEVICE_NOT_FOUND; } } if (options.eject_device) { try { Volume volume = volumeDeviceClass.FindBySerial(options.device_id); String error = volume.Eject(false); if (error != null) { Console.WriteLine(error); return (int) ExitCodes.EJECT_ERROR; } return (int) ExitCodes.OK; } catch (DeviceNotFound) { return (int) ExitCodes.DEVICE_NOT_FOUND; } } if (options.find_uuid) { try { Volume volume = volumeDeviceClass.FindByLetter(options.device_id); Console.Write(volume.Serial); return (int) ExitCodes.OK; } catch (DeviceNotFound) { return (int) ExitCodes.DEVICE_NOT_FOUND; } } if (options.open_device) { return (int) ExitCodes.OK; } Console.Error.WriteLine(parser.UsageInfo.ToString(78, false)); return (int) ExitCodes.INVALID_SYNTAX; }
void EjectButtonClick(object sender, EventArgs e) { string result; LoggingService.Info("Eject requested"); VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); try { Volume volume = volumeDeviceClass.FindBySerial(Settings.source_id); LoggingService.Info(String.Format("Ejecting {0} {1}", volume.LogicalDrive, volume.Serial)); volumeDeviceClass.Dispose(); result = volume.Eject(false); LoggingService.Info(String.Format("Eject result: {0}", result)); } catch (DeviceNotFound) { return; } if (result == null) // Device ejected properly setConnectedStatus(false); }
private string scanForDevice() { if (!Settings.sourceValid) { status_view.setConnectedStatus(false); return ""; } VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); try { Volume volume = volumeDeviceClass.FindBySerial(Settings.source_id); status_view.setConnectedStatus(true); string drive = volume.LogicalDrive; volumeDeviceClass.Dispose(); return drive; } catch (DeviceNotFound) { status_view.setConnectedStatus(false); volumeDeviceClass.Dispose(); return ""; } }
private void OnDriveArrived(object sender, DriveDetectorEventArgs e) { if (!Settings.sourceValid) return; // e.Drive is the drive letter, e.g. "E:\\" // If you want to be notified when drive is being removed (and be // able to cancel it), set HookQueryRemove to true VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); Volume volume = volumeDeviceClass.FindByLetter(e.Drive); if (Settings.source_id == volume.Serial) { LoggingService.Info(String.Format("Device connected {0} {1}", e.Drive, volume.Serial)); status_view.setConnectedStatus(true); startBackup(e.Drive); } e.HookQueryRemove = false; }