diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java index 3905064f4..889cc623a 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java @@ -30,8 +30,7 @@ public class Settings { public static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3; public static final String DEFAULT_GVFS_SCHEME = "dav"; public static final boolean DEFAULT_DEBUG_MODE = false; - public static final String DEFAULT_DEFAULT_MOUNT_DIR = System.getProperty("user.home"); - public static final String DEFAULT_NIO_ADAPTER = "webdav"; + public static final String DEFAULT_NIO_ADAPTER = "WEBDAV"; private final ObservableList directories = FXCollections.observableArrayList(VaultSettings::observables); private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UDPATES); @@ -40,7 +39,6 @@ public class Settings { private final StringProperty preferredGvfsScheme = new SimpleStringProperty(DEFAULT_GVFS_SCHEME); private final BooleanProperty debugMode = new SimpleBooleanProperty(DEFAULT_DEBUG_MODE); private final StringProperty nioAdapterImpl = new SimpleStringProperty(DEFAULT_NIO_ADAPTER); - private final StringProperty defaultMountDir = new SimpleStringProperty(DEFAULT_DEFAULT_MOUNT_DIR); private Consumer saveCmd; @@ -55,7 +53,6 @@ public class Settings { preferredGvfsScheme.addListener(this::somethingChanged); debugMode.addListener(this::somethingChanged); nioAdapterImpl.addListener(this::somethingChanged); - defaultMountDir.addListener(this::somethingChanged); } void setSaveCmd(Consumer saveCmd) { @@ -102,7 +99,4 @@ public class Settings { return nioAdapterImpl; } - public StringProperty defaultMountDir() { - return defaultMountDir; - } } diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java index 0a2a13c3f..5f601cd28 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java @@ -34,7 +34,6 @@ public class SettingsJsonAdapter extends TypeAdapter { out.name("preferredGvfsScheme").value(value.preferredGvfsScheme().get()); out.name("debugMode").value(value.debugMode().get()); out.name("nioAdapterImpl").value(value.usedNioAdapterImpl().get()); - out.name("defaultMountDir").value(value.defaultMountDir().get()); out.endObject(); } @@ -54,33 +53,30 @@ public class SettingsJsonAdapter extends TypeAdapter { while (in.hasNext()) { String name = in.nextName(); switch (name) { - case "directories": - settings.getDirectories().addAll(readVaultSettingsArray(in)); - break; - case "checkForUpdatesEnabled": - settings.checkForUpdates().set(in.nextBoolean()); - break; - case "port": - settings.port().set(in.nextInt()); - break; - case "numTrayNotifications": - settings.numTrayNotifications().set(in.nextInt()); - break; - case "preferredGvfsScheme": - settings.preferredGvfsScheme().set(in.nextString()); - break; - case "debugMode": - settings.debugMode().set(in.nextBoolean()); - break; - case "nioAdapterImpl": - settings.usedNioAdapterImpl().set(in.nextString()); - break; - case "defaultMountDir": - settings.defaultMountDir().set(in.nextString()); - break; - default: - LOG.warn("Unsupported vault setting found in JSON: " + name); - in.skipValue(); + case "directories": + settings.getDirectories().addAll(readVaultSettingsArray(in)); + break; + case "checkForUpdatesEnabled": + settings.checkForUpdates().set(in.nextBoolean()); + break; + case "port": + settings.port().set(in.nextInt()); + break; + case "numTrayNotifications": + settings.numTrayNotifications().set(in.nextInt()); + break; + case "preferredGvfsScheme": + settings.preferredGvfsScheme().set(in.nextString()); + break; + case "debugMode": + settings.debugMode().set(in.nextBoolean()); + break; + case "nioAdapterImpl": + settings.usedNioAdapterImpl().set(in.nextString()); + break; + default: + LOG.warn("Unsupported vault setting found in JSON: " + name); + in.skipValue(); } } in.endObject(); diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java index bcaae5587..53f1056a3 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java @@ -36,7 +36,7 @@ public class VaultSettings { private final BooleanProperty unlockAfterStartup = new SimpleBooleanProperty(DEFAULT_UNLOCK_AFTER_STARTUP); private final BooleanProperty mountAfterUnlock = new SimpleBooleanProperty(DEFAULT_MOUNT_AFTER_UNLOCK); private final BooleanProperty revealAfterMount = new SimpleBooleanProperty(DEFAULT_REAVEAL_AFTER_MOUNT); - private final StringProperty mountPath = new SimpleStringProperty(Settings.DEFAULT_DEFAULT_MOUNT_DIR); + private final StringProperty mountPath = new SimpleStringProperty(); public VaultSettings(String id) { this.id = Objects.requireNonNull(id); @@ -45,7 +45,7 @@ public class VaultSettings { } Observable[] observables() { - return new Observable[] {path, mountName, winDriveLetter, unlockAfterStartup, mountAfterUnlock, revealAfterMount}; + return new Observable[]{path, mountName, winDriveLetter, unlockAfterStartup, mountAfterUnlock, revealAfterMount}; } private void deriveMountNameFromPath(Path path) { diff --git a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java index 5c757c013..95bebf3bb 100644 --- a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java @@ -35,7 +35,6 @@ public class SettingsJsonAdapterTest { Assert.assertEquals(42, settings.numTrayNotifications().get()); Assert.assertEquals("dav", settings.preferredGvfsScheme().get()); Assert.assertEquals("webdav", settings.usedNioAdapterImpl().get()); - Assert.assertEquals("/home/test/crypto", settings.defaultMountDir().get()); } } diff --git a/main/pom.xml b/main/pom.xml index e5738b56c..a3961971a 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -28,7 +28,7 @@ 1.4.5 1.0.3 1.0.2 - 0.1.1-SNAPSHOT + 0.1.0-SNAPSHOT 2.5 3.6 diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java index 544c2fb2a..1b28cfe2a 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java @@ -2,22 +2,18 @@ * Copyright (c) 2014, 2017 Sebastian Stenzel * All rights reserved. * This program and the accompanying materials are made available under the terms of the accompanying LICENSE file. - * + * * Contributors: * Sebastian Stenzel - initial API and implementation ******************************************************************************/ package org.cryptomator.ui.controllers; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import javafx.beans.Observable; import javafx.beans.value.ObservableValue; import javafx.scene.layout.GridPane; import org.apache.commons.lang3.SystemUtils; @@ -80,15 +76,6 @@ public class SettingsController implements ViewController { @FXML private Label prefGvfsSchemeLabel; - @FXML - private Label defaultMountDirLabel; - - @FXML - private TextField defaultMountDir; - - @FXML - private Button changeDefaultMountDirButton; - @FXML private ChoiceBox prefGvfsScheme; @@ -114,7 +101,7 @@ public class SettingsController implements ViewController { nioAdapter.getItems().addAll(getSupportedAdapters()); nioAdapter.setValue(settings.usedNioAdapterImpl().get()); nioAdapter.setVisible(true); - nioAdapter.getSelectionModel().selectedItemProperty().addListener( (ObservableValue observable, String oldVal, String newVal) -> changeNioView(newVal) ); + nioAdapter.getSelectionModel().selectedItemProperty().addListener((ObservableValue observable, String oldVal, String newVal) -> changeNioView(newVal)); //WEBDAV @@ -136,20 +123,6 @@ public class SettingsController implements ViewController { //FUSE fuseNioAdapter.managedProperty().bind(fuseNioAdapter.visibleProperty()); - defaultMountDirLabel.managedProperty().bind(fuseNioAdapter.visibleProperty()); - defaultMountDir.managedProperty().bind(fuseNioAdapter.visibleProperty()); - defaultMountDirLabel.setVisible(!SystemUtils.IS_OS_WINDOWS); - defaultMountDir.setVisible(!SystemUtils.IS_OS_WINDOWS); - defaultMountDir.setText(String.valueOf(settings.defaultMountDir().get())); - changeDefaultMountDirButton.setVisible(false); - changeDefaultMountDirButton.visibleProperty().bind( - Bindings.createBooleanBinding( - () -> fuseNioAdapter.visibleProperty().get() && settings.defaultMountDir().isNotEqualTo(Strings.nullToEmpty(defaultMountDir.getText())).get() , - fuseNioAdapter.visibleProperty(), - settings.defaultMountDir().isNotEqualTo(defaultMountDir.textProperty()) - ) - ); - changeDefaultMountDirButton.disableProperty().bind(Bindings.createBooleanBinding(this::isDirValid, defaultMountDir.textProperty()).not()); debugModeCheckbox.setSelected(settings.debugMode().get()); @@ -160,7 +133,7 @@ public class SettingsController implements ViewController { } //TODO: how to implement this? - private String [] getSupportedAdapters() { + private String[] getSupportedAdapters() { return new String[]{NioAdapterImpl.FUSE.name(), NioAdapterImpl.WEBDAV.name()}; } @@ -185,23 +158,6 @@ public class SettingsController implements ViewController { } } - @FXML - private void changeDefaultMountDir(ActionEvent event){ - assert isDirValid() : "Error. Not a valid Directory. Does and exist and do you have the needed Rights?"; - settings.defaultMountDir().set(defaultMountDir.getText()); - } - - private boolean isDirValid(){ - if(SystemUtils.IS_OS_WINDOWS){ - //this should never ever happen! - return false; - } - else{ - Path path = Paths.get(defaultMountDir.getText()); - return Files.isDirectory(path) && Files.isReadable(path) && Files.isWritable(path) && Files.isExecutable(path); - } - } - private boolean isPortValid() { try { int port = Integer.parseInt(portField.getText()); diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java index c1b2aac68..12dee4c33 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java @@ -2,13 +2,12 @@ * Copyright (c) 2014, 2017 Sebastian Stenzel * All rights reserved. * This program and the accompanying materials are made available under the terms of the accompanying LICENSE file. - * + * * Contributors: * Sebastian Stenzel - initial API and implementation ******************************************************************************/ package org.cryptomator.ui.controllers; -import java.io.File; import java.io.IOException; import java.nio.file.*; import java.util.Arrays; @@ -18,8 +17,8 @@ import java.util.Optional; import javax.inject.Inject; -import javafx.beans.Observable; import javafx.beans.binding.Bindings; +import javafx.scene.layout.HBox; import org.apache.commons.lang3.CharUtils; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.settings.VaultSettings; @@ -116,6 +115,9 @@ public class UnlockController implements ViewController { @FXML private ChoiceBox winDriveLetter; + @FXML + private HBox mountPathBox; + @FXML private Label mountPathLabel; @@ -155,6 +157,7 @@ public class UnlockController implements ViewController { unlockAfterStartup.disableProperty().bind(savePassword.disabledProperty().or(savePassword.selectedProperty().not())); if (SystemUtils.IS_OS_WINDOWS) { winDriveLetter.setConverter(new WinDriveLetterLabelConverter()); + mountPathBox.setMouseTransparent(true); mountPathLabel.setVisible(false); mountPathLabel.setManaged(false); mountPath.setVisible(false); @@ -170,7 +173,7 @@ public class UnlockController implements ViewController { changeMountPathButton.disableProperty().bind(Bindings.createBooleanBinding(this::isDirVaild, mountPath.textProperty()).not()); changeMountPathButton.visibleProperty().bind( Bindings.createBooleanBinding( - ()-> mountPathLabel.isVisible() && mountPath.textProperty().isEmpty().not().get(), + () -> mountPathLabel.isVisible() && mountPath.textProperty().isEmpty().not().get(), mountPathLabel.visibleProperty(), mountPath.textProperty().isEmpty().not() ) @@ -262,31 +265,28 @@ public class UnlockController implements ViewController { } @FXML - private void didClickchangeMountPathButton(ActionEvent event){ + private void didClickchangeMountPathButton(ActionEvent event) { assert isDirVaild(); vault.setMountPath(mountPath.getText()); } - private boolean isDirVaild(){ - try{ - if(!mountPath.textProperty().isEmpty().get()){ + private boolean isDirVaild() { + try { + if (!mountPath.textProperty().isEmpty().get()) { Path p = Paths.get(mountPath.textProperty().get()); return Files.isDirectory(p) && Files.isReadable(p) && Files.isWritable(p) && Files.isExecutable(p); - } - else{ + } else { //default path will be taken return true; } - } - catch (InvalidPathException e){ + } catch (InvalidPathException e) { LOG.info("Invalid path"); return false; } } - private void filterAlphanumericKeyEvents(KeyEvent t) { if (!Strings.isNullOrEmpty(t.getCharacter()) && !ALPHA_NUMERIC_MATCHER.matchesAllOf(t.getCharacter())) { t.consume(); @@ -451,6 +451,7 @@ public class UnlockController implements ViewController { @FunctionalInterface interface UnlockListener { + void didUnlock(Vault vault); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/FuseNioAdapter.java b/main/ui/src/main/java/org/cryptomator/ui/model/FuseNioAdapter.java index 7a8053535..0a4c7d198 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/FuseNioAdapter.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/FuseNioAdapter.java @@ -23,35 +23,30 @@ public class FuseNioAdapter implements NioAdapter { } @Override - public void unlock(CryptoFileSystem fs) { + public void prepare(CryptoFileSystem fs) { this.cfs = fs; ffs = AdapterFactory.createReadWriteAdapter(fs.getPath("/")); } - /** - * TODO: should createTempDirectory() be used instead of createDirectory()? - * - * @throws CommandFailedException - */ @Override public void mount() throws CommandFailedException { - try { - fuseEnv.prepare(); - ffs.mount(fuseEnv.getFsRootPath(), false, false, fuseEnv.getMountParameters()); - } catch (Exception e) { + try { + fuseEnv.prepare(); + ffs.mount(fuseEnv.getFsRootPath(), false, false, fuseEnv.getMountParameters()); + } catch (Exception e) { throw new CommandFailedException("Unable to mount Filesystem", e); } } @Override - public void reveal() throws CommandFailedException{ + public void reveal() throws CommandFailedException { fuseEnv.revealFsRootInFilesystemManager(); } @Override public synchronized void unmount() throws CommandFailedException { if (cfs.getStats().pollBytesRead() == 0 && cfs.getStats().pollBytesWritten() == 0) { - unmountForced(); + unmountRaw(); } else { throw new CommandFailedException("Pending read or write operations."); } @@ -59,6 +54,10 @@ public class FuseNioAdapter implements NioAdapter { @Override public synchronized void unmountForced() throws CommandFailedException { + this.unmountRaw(); + } + + private synchronized void unmountRaw() { ffs.umount(); } @@ -68,7 +67,7 @@ public class FuseNioAdapter implements NioAdapter { } @Override - public String getFsRootUrlString() { + public String getMountUrl() { return fuseEnv.getFsRootPath().toUri().toString(); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/NioAdapter.java b/main/ui/src/main/java/org/cryptomator/ui/model/NioAdapter.java index df4238cc7..1643011e4 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/NioAdapter.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/NioAdapter.java @@ -4,7 +4,7 @@ import org.cryptomator.cryptofs.CryptoFileSystem; public interface NioAdapter { - void unlock(CryptoFileSystem fs); + void prepare(CryptoFileSystem fs); void mount() throws CommandFailedException; @@ -20,7 +20,7 @@ public interface NioAdapter { void stop(); - String getFsRootUrlString(); + String getMountUrl(); default boolean isSupported() { return false; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java index ec60abd11..96570f5a6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java @@ -30,7 +30,6 @@ import org.cryptomator.cryptolib.api.CryptoException; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.ui.model.VaultModule.PerVault; -import com.google.common.base.Strings; import javafx.application.Platform; import javafx.beans.Observable; import javafx.beans.binding.Binding; @@ -68,10 +67,6 @@ public class Vault { this.settings = settings; this.vaultSettings = vaultSettings; this.nioAdapter = nioAdapter; - - if (Strings.isNullOrEmpty(vaultSettings.mountPath().get())) { - vaultSettings.mountPath().set(settings.defaultMountDir().get() + "/" + vaultSettings.mountName().get()); - } } // ****************************************************************************** @@ -105,7 +100,7 @@ public class Vault { public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException { CryptoFileSystem fs = getCryptoFileSystem(passphrase); - nioAdapter.unlock(fs); + nioAdapter.prepare(fs); Platform.runLater(() -> { state.set(State.UNLOCKED); }); @@ -267,11 +262,7 @@ public class Vault { } public void setMountPath(String mountPath) { - if (mountPath.isEmpty()) { - vaultSettings.mountPath().set(settings.defaultMountDir().get()); - } else { - vaultSettings.mountPath().set(mountPath); - } + vaultSettings.mountPath().set(mountPath); } public void setMountName(String mountName) throws IllegalArgumentException { @@ -299,7 +290,7 @@ public class Vault { } public String getFilesystemRootUrl() { - return nioAdapter.getFsRootUrlString(); + return nioAdapter.getMountUrl(); } public String getId() { diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/WebDavNioAdapter.java b/main/ui/src/main/java/org/cryptomator/ui/model/WebDavNioAdapter.java index 0f1e9b7cd..8be972dc6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/WebDavNioAdapter.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/WebDavNioAdapter.java @@ -33,7 +33,7 @@ public class WebDavNioAdapter implements NioAdapter { } @Override - public void unlock(CryptoFileSystem fs) { + public void prepare(CryptoFileSystem fs) { if (!server.isRunning()) { server.start(); } @@ -104,7 +104,7 @@ public class WebDavNioAdapter implements NioAdapter { } - public synchronized String getFsRootUrlString() { + public synchronized String getMountUrl() { return servlet.getServletRootUri().toString(); } diff --git a/main/ui/src/main/resources/fxml/settings.fxml b/main/ui/src/main/resources/fxml/settings.fxml index f778ba090..708650fb6 100644 --- a/main/ui/src/main/resources/fxml/settings.fxml +++ b/main/ui/src/main/resources/fxml/settings.fxml @@ -59,11 +59,6 @@ -