catch all methods of adding a vault for #2880

This commit is contained in:
Armin Schrenk 2024-08-19 10:27:13 +02:00
parent 4778ba0770
commit 257f4427b8
No known key found for this signature in database
2 changed files with 21 additions and 21 deletions

View File

@ -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<MountService> mountServices;
private final VaultComponent.Factory vaultComponentFactory;
private final ObservableList<Vault> vaultList;
private final String defaultVaultName;
@Inject
public VaultListManager(ObservableList<Vault> vaultList, AutoLocker autoLocker, VaultComponent.Factory vaultComponentFactory, ResourceBundle resourceBundle, Settings settings) {
public VaultListManager(ObservableList<Vault> vaultList, //
AutoLocker autoLocker, //
List<MountService> 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;
}

View File

@ -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<Scene> successScene;
private final FxApplicationWindows appWindows;
private final ExecutorService executor;
private final List<MountService> mountProviders;
private final RecoveryKeyFactory recoveryKeyFactory;
private final StringProperty vaultNameProperty;
private final ObjectProperty<Path> vaultPathProperty;
@ -94,7 +89,7 @@ public class CreateNewVaultPasswordController implements FxController {
@FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy<Scene> successScene, //
FxApplicationWindows appWindows, //
ExecutorService executor, //
List<MountService> mountProviders, RecoveryKeyFactory recoveryKeyFactory, //
RecoveryKeyFactory recoveryKeyFactory, //
@Named("vaultName") StringProperty vaultName, //
ObjectProperty<Path> vaultPath, //
@AddVaultWizardWindow ObjectProperty<Vault> 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() {