samuelcampos / usbdrivedetector

A Java library to get a list of all usb storage devices connected to the computer.
MIT License
128 stars 46 forks source link

Windows DriveType 3 not picked up #46

Open Avec112 opened 1 year ago

Avec112 commented 1 year ago

I am running Windows 7 (yea I know...its a bummer but I have to wait a bit longer). My NTFS hard disk DriveType 3 is not picked up. We use USB external hard disk to transfer stuff to this Windows machine. However while doing some testing the api picks up USB memory sticks DriveType 2 just fine. Our NTFS formatted USB hard disk DriveType 3 however is not picked up at all.

Running Linux, DriveType 3 is found. Is Windows (7 and maybe also newer?) DriveType 3 just not supported?

I have mentioned this problem here also. Originally posted by @Avec112 in https://github.com/samuelcampos/usbdrivedetector/issues/37#issuecomment-1443154270

samuelcampos commented 1 year ago

We use diferent strategies to find drives on different systems. That might explain the different behaviour between Windows and Linux.

On Windows, it is not detecting DriveType 3 because I was not able to distinguish between an external disk DriveType 3 and the computer's default hard disk.

I think that Windoes detects USB sticks as DriveType 2 regardless of the filesystem. However, it does not behave the same for external hard drives.

At this point, my only idea is to expose some config or input parameter for the developer to choose if he wants to detect changes (connections/removals) of normal hard drives (all devices with DriveType 3).

What do you think?

Avec112 commented 1 year ago

Apologies for not answering earlier. I think an option to configure any fixed/stationary HDD of DriveType 3 would be a valid solution. Maybe a blacklist and whitelist configuration option could solve what to monitor and not. I almost implemented a sort of "whitelist" myself. Inside the monitor I only want to trigger my application when the usb stick is named "x". All other usb findings are being ignored.

detector.addDriveListener(e -> {
  var device = e.getStorageDevice();
  if(isCorrectDevice(device) && e.getEventType().equals(DeviceEventType.CONNECTED)) {
    // get/put files from/to device  
  }
});