diff --git a/src/main/java/org/cryptomator/common/settings/Settings.java b/src/main/java/org/cryptomator/common/settings/Settings.java index b382cd1ac..a711e6536 100644 --- a/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/src/main/java/org/cryptomator/common/settings/Settings.java @@ -25,6 +25,8 @@ import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.NodeOrientation; + +import java.nio.file.Path; import java.time.Instant; import java.util.function.Consumer; @@ -75,6 +77,7 @@ public class Settings { public final BooleanProperty checkForUpdates; public final ObjectProperty lastUpdateCheckReminder; public final ObjectProperty lastSuccessfulUpdateCheck; + public final ObjectProperty previouslyUsedVaultDirectory; private Consumer saveCmd; @@ -114,6 +117,7 @@ public class Settings { this.checkForUpdates = new SimpleBooleanProperty(this, "checkForUpdates", json.checkForUpdatesEnabled); this.lastUpdateCheckReminder = new SimpleObjectProperty<>(this, "lastUpdateCheckReminder", json.lastReminderForUpdateCheck); this.lastSuccessfulUpdateCheck = new SimpleObjectProperty<>(this, "lastSuccessfulUpdateCheck", json.lastSuccessfulUpdateCheck); + this.previouslyUsedVaultDirectory = new SimpleObjectProperty<>(this, "previouslyUsedVaultDirectory", json.previouslyUsedVaultDirectory); this.directories.addAll(json.directories.stream().map(VaultSettings::new).toList()); @@ -143,6 +147,7 @@ public class Settings { checkForUpdates.addListener(this::somethingChanged); lastUpdateCheckReminder.addListener(this::somethingChanged); lastSuccessfulUpdateCheck.addListener(this::somethingChanged); + previouslyUsedVaultDirectory.addListener(this::somethingChanged); } @SuppressWarnings("deprecation") @@ -204,6 +209,7 @@ public class Settings { json.checkForUpdatesEnabled = checkForUpdates.get(); json.lastReminderForUpdateCheck = lastUpdateCheckReminder.get(); json.lastSuccessfulUpdateCheck = lastSuccessfulUpdateCheck.get(); + json.previouslyUsedVaultDirectory = previouslyUsedVaultDirectory.get(); return json; } diff --git a/src/main/java/org/cryptomator/common/settings/SettingsJson.java b/src/main/java/org/cryptomator/common/settings/SettingsJson.java index 15f5f2790..feb8a0bf2 100644 --- a/src/main/java/org/cryptomator/common/settings/SettingsJson.java +++ b/src/main/java/org/cryptomator/common/settings/SettingsJson.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import java.nio.file.Path; import java.time.Instant; import java.util.List; @@ -92,4 +93,7 @@ class SettingsJson { @JsonProperty("quickAccessService") String quickAccessService = Settings.DEFAULT_QUICKACCESS_SERVICE; + + @JsonProperty("previouslyUsedVaultDirectory") + Path previouslyUsedVaultDirectory; } diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java index c8b7bee22..78a2771df 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java @@ -4,6 +4,7 @@ import dagger.Lazy; import org.cryptomator.common.ObservableUtil; import org.cryptomator.common.locationpresets.LocationPreset; import org.cryptomator.common.locationpresets.LocationPresetsProvider; +import org.cryptomator.common.settings.Settings; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; @@ -38,6 +39,7 @@ import javafx.stage.WindowEvent; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; @@ -64,6 +66,7 @@ public class CreateNewVaultLocationController implements FxController { private final BooleanProperty loadingPresetLocations = new SimpleBooleanProperty(false); private final ObservableList radioButtons; private final ObservableList sortedRadioButtons; + private final Settings settings; private Path customVaultPath = DEFAULT_CUSTOM_VAULT_PATH; @@ -82,6 +85,7 @@ public class CreateNewVaultLocationController implements FxController { @FxmlScene(FxmlFile.ADDVAULT_NEW_EXPERT_SETTINGS) Lazy chooseExpertSettingsScene, // ObjectProperty vaultPath, // @Named("vaultName") StringProperty vaultName, // + Settings settings, // ExecutorService backgroundExecutor, ResourceBundle resourceBundle) { this.window = window; this.chooseNameScene = chooseNameScene; @@ -96,6 +100,18 @@ public class CreateNewVaultLocationController implements FxController { this.usePresetPath = new SimpleBooleanProperty(); this.radioButtons = FXCollections.observableArrayList(); this.sortedRadioButtons = radioButtons.sorted(this::compareLocationPresets); + this.settings = settings; + + Path previouslyUsedDirectory = settings.previouslyUsedVaultDirectory.get(); + if (previouslyUsedDirectory != null) { + try { + if (Files.exists(previouslyUsedDirectory) && Files.isDirectory(previouslyUsedDirectory) && isActuallyWritable(previouslyUsedDirectory)) { + this.customVaultPath = previouslyUsedDirectory; + } + } catch (InvalidPathException | NullPointerException e) { + LOG.warn("Invalid previously used vault directory path: {}", previouslyUsedDirectory, e); + } + } } private VaultPathStatus validatePath(Path p) throws NullPointerException { @@ -196,6 +212,12 @@ public class CreateNewVaultLocationController implements FxController { @FXML public void next() { if (validVaultPath.getValue()) { + if (this.getVaultPath() != null) { + Path parentPath = this.getVaultPath().getParent(); + if (parentPath != null) { + this.settings.previouslyUsedVaultDirectory.setValue(parentPath); + } + } window.setScene(chooseExpertSettingsScene.get()); } }