From 9217b11e612ee55c0b69f626ab407f21fe533b26 Mon Sep 17 00:00:00 2001 From: infeo Date: Thu, 28 Jun 2018 16:02:11 +0200 Subject: [PATCH] adding automatic drive letter selection to dokany volume --- .../cryptomator/ui/model/DokanyVolume.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java b/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java index 9f7041107..6d4a23163 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java @@ -14,12 +14,14 @@ public class DokanyVolume implements Volume { private final VaultSettings vaultSettings; private final MountFactory mountFactory; + private final WindowsDriveLetters windowsDriveLetters; private Mount mount; @Inject - public DokanyVolume(VaultSettings vaultSettings, ExecutorService executorService) { + public DokanyVolume(VaultSettings vaultSettings, ExecutorService executorService, WindowsDriveLetters windowsDriveLetters) { this.vaultSettings = vaultSettings; this.mountFactory = new MountFactory(executorService); + this.windowsDriveLetters = windowsDriveLetters; } @@ -28,9 +30,21 @@ public class DokanyVolume implements Volume { return MountFactory.isApplicable(); } + //TODO: Drive letter 'A' as mount point is invalid in dokany. maybe we should do already here something against it @Override - public void mount(CryptoFileSystem fs) { - char driveLetter = vaultSettings.winDriveLetter().get().charAt(0); + public void mount(CryptoFileSystem fs) throws VolumeException { + char driveLetter; + if (!vaultSettings.winDriveLetter().getValueSafe().equals("")) { + driveLetter = vaultSettings.winDriveLetter().get().charAt(0); + } else { + //auto assign drive letter + //TODO: can we assume the we have at least one free drive letter? + if (!windowsDriveLetters.getAvailableDriveLetters().isEmpty()) { + driveLetter = windowsDriveLetters.getAvailableDriveLetters().iterator().next(); + } else { + throw new VolumeException("No free drive letter available."); + } + } String mountName = vaultSettings.mountName().get(); this.mount = mountFactory.mount(fs.getPath("/"), driveLetter, mountName, FS_TYPE_NAME); }