From 257f4427b81bd769c2a65fab4ea53e9efa97196e Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 19 Aug 2024 10:27:13 +0200 Subject: [PATCH] catch all methods of adding a vault for #2880 --- .../common/vaults/VaultListManager.java | 21 ++++++++++++++++++- .../CreateNewVaultPasswordController.java | 21 +------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java index 53616c3db..87faff77a 100644 --- a/src/main/java/org/cryptomator/common/vaults/VaultListManager.java +++ b/src/main/java/org/cryptomator/common/vaults/VaultListManager.java @@ -8,11 +8,13 @@ *******************************************************************************/ package org.cryptomator.common.vaults; +import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.cryptofs.CryptoFileSystemProvider; import org.cryptomator.cryptofs.DirStructure; import org.cryptomator.cryptofs.migration.Migrators; +import org.cryptomator.integrations.mount.MountService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +26,7 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.util.Collection; +import java.util.List; import java.util.Optional; import java.util.ResourceBundle; @@ -38,14 +41,21 @@ public class VaultListManager { private static final Logger LOG = LoggerFactory.getLogger(VaultListManager.class); private final AutoLocker autoLocker; + private final List mountServices; private final VaultComponent.Factory vaultComponentFactory; private final ObservableList vaultList; private final String defaultVaultName; @Inject - public VaultListManager(ObservableList vaultList, AutoLocker autoLocker, VaultComponent.Factory vaultComponentFactory, ResourceBundle resourceBundle, Settings settings) { + public VaultListManager(ObservableList vaultList, // + AutoLocker autoLocker, // + List mountServices, + VaultComponent.Factory vaultComponentFactory, + ResourceBundle resourceBundle, + Settings settings) { this.vaultList = vaultList; this.autoLocker = autoLocker; + this.mountServices = mountServices; this.vaultComponentFactory = vaultComponentFactory; this.defaultVaultName = resourceBundle.getString("defaults.vault.vaultName"); @@ -76,6 +86,15 @@ public class VaultListManager { } else { vaultSettings.displayName.set(defaultVaultName); } + + //due to https://github.com/cryptomator/cryptomator/issues/2880#issuecomment-1680313498 + var nameOfWinfspLocalMounter = "org.cryptomator.frontend.fuse.mount.WinFspMountProvider"; + if (SystemUtils.IS_OS_WINDOWS // + && vaultSettings.path.get().toString().contains("Dropbox") // + && mountServices.stream().anyMatch(s -> s.getClass().getName().equals(nameOfWinfspLocalMounter))) { + vaultSettings.mountService.setValue(nameOfWinfspLocalMounter); + } + return vaultSettings; } diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java index 415604dbe..28a73794a 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java @@ -1,8 +1,6 @@ package org.cryptomator.ui.addvaultwizard; import dagger.Lazy; -import org.apache.commons.lang3.SystemUtils; -import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.common.vaults.Vault; import org.cryptomator.common.vaults.VaultListManager; import org.cryptomator.cryptofs.CryptoFileSystemProperties; @@ -12,7 +10,6 @@ import org.cryptomator.cryptolib.api.CryptorProvider; import org.cryptomator.cryptolib.api.Masterkey; import org.cryptomator.cryptolib.api.MasterkeyLoader; import org.cryptomator.cryptolib.common.MasterkeyFileAccess; -import org.cryptomator.integrations.mount.MountService; import org.cryptomator.ui.changepassword.NewPasswordController; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; @@ -46,7 +43,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.security.SecureRandom; -import java.util.List; import java.util.ResourceBundle; import java.util.concurrent.ExecutorService; @@ -65,7 +61,6 @@ public class CreateNewVaultPasswordController implements FxController { private final Lazy successScene; private final FxApplicationWindows appWindows; private final ExecutorService executor; - private final List mountProviders; private final RecoveryKeyFactory recoveryKeyFactory; private final StringProperty vaultNameProperty; private final ObjectProperty vaultPathProperty; @@ -94,7 +89,7 @@ public class CreateNewVaultPasswordController implements FxController { @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, // FxApplicationWindows appWindows, // ExecutorService executor, // - List mountProviders, RecoveryKeyFactory recoveryKeyFactory, // + RecoveryKeyFactory recoveryKeyFactory, // @Named("vaultName") StringProperty vaultName, // ObjectProperty vaultPath, // @AddVaultWizardWindow ObjectProperty vault, // @@ -111,7 +106,6 @@ public class CreateNewVaultPasswordController implements FxController { this.successScene = successScene; this.appWindows = appWindows; this.executor = executor; - this.mountProviders = mountProviders; this.recoveryKeyFactory = recoveryKeyFactory; this.vaultNameProperty = vaultName; this.vaultPathProperty = vaultPath; @@ -229,25 +223,12 @@ public class CreateNewVaultPasswordController implements FxController { private void creationSucceeded(Path pathToVault) { try { Vault newVault = vaultListManager.add(pathToVault); - postProcessVaultSettings(newVault.getVaultSettings()); vaultProperty.set(newVault); } catch (IOException e) { throw new UncheckedIOException(e); } } - //due to https://github.com/cryptomator/cryptomator/issues/2880#issuecomment-1680313498 - @Deprecated() - private void postProcessVaultSettings(VaultSettings vaultSettings) { - var nameOfWinfspLocalMounter = "org.cryptomator.frontend.fuse.mount.WinFspMountProvider"; - if (SystemUtils.IS_OS_WINDOWS // - && vaultSettings.path.get().toString().contains("Dropbox") // - && mountProviders.stream().anyMatch(s -> s.getClass().getName().equals(nameOfWinfspLocalMounter))) { - vaultSettings.mountService.setValue(nameOfWinfspLocalMounter); - } - - } - /* Getter/Setter */ public String getVaultName() {