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; }
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; }