mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
Improve the vault/mount name system:
* fix bug where the default name is not replaced by the actual folder name * introduce new field in settings "mountName" as binding on displayName * change volumes to use mountName instead of displayName
This commit is contained in:
@@ -8,6 +8,8 @@ package org.cryptomator.common.settings;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.StringBinding;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
@@ -53,8 +55,11 @@ public class VaultSettings {
|
||||
private final IntegerProperty filenameLengthLimit = new SimpleIntegerProperty(DEFAULT_FILENAME_LENGTH_LIMIT);
|
||||
private final ObjectProperty<WhenUnlocked> actionAfterUnlock = new SimpleObjectProperty<>(DEFAULT_ACTION_AFTER_UNLOCK);
|
||||
|
||||
private final StringBinding mountName;
|
||||
|
||||
public VaultSettings(String id) {
|
||||
this.id = Objects.requireNonNull(id);
|
||||
this.mountName = Bindings.createStringBinding(this::normalizeDisplayName, displayName);
|
||||
|
||||
EasyBind.subscribe(path, this::deriveDisplayNameFromPathOrUseDefault);
|
||||
}
|
||||
@@ -66,13 +71,14 @@ public class VaultSettings {
|
||||
private void deriveDisplayNameFromPathOrUseDefault(Path newPath) {
|
||||
final boolean mountNameSet = !StringUtils.isBlank(displayName.get());
|
||||
final boolean dirnameExists = (newPath != null) && (newPath.getFileName() != null);
|
||||
final String defaultPattern = DEFAULT_MOUNT_NAME + " " + id;
|
||||
|
||||
if (!mountNameSet && dirnameExists) {
|
||||
displayName.set(normalizeMountName(newPath.getFileName().toString()));
|
||||
displayName.set(newPath.getFileName().toString());
|
||||
} else if (!mountNameSet && !dirnameExists) {
|
||||
displayName.set(DEFAULT_MOUNT_NAME + " " + id);
|
||||
displayName.set(defaultPattern);
|
||||
} else if (mountNameSet && dirnameExists) {
|
||||
if (displayName.get().equals(DEFAULT_MOUNT_NAME + id)) {
|
||||
if (displayName.get().equals(defaultPattern)) {
|
||||
//this is okay, since this function is only executed if the path changes (aka, the vault is created or added)
|
||||
displayName.set(newPath.getFileName().toString());
|
||||
}
|
||||
@@ -89,8 +95,9 @@ public class VaultSettings {
|
||||
return BaseEncoding.base64Url().encode(randomBytes);
|
||||
}
|
||||
|
||||
public static String normalizeMountName(String mountName) {
|
||||
String normalizedMountName = StringUtils.stripAccents(mountName);
|
||||
//visible for testing
|
||||
String normalizeDisplayName() {
|
||||
String normalizedMountName = StringUtils.stripAccents(displayName.get());
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (char c : normalizedMountName.toCharArray()) {
|
||||
if (Character.isWhitespace(c)) {
|
||||
@@ -122,6 +129,10 @@ public class VaultSettings {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public StringBinding mountName() {
|
||||
return mountName;
|
||||
}
|
||||
|
||||
public StringProperty winDriveLetter() {
|
||||
return winDriveLetter;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DokanyVolume implements Volume {
|
||||
this.mountPoint = determineMountPoint();
|
||||
String mountName = vaultSettings.displayName().get();
|
||||
try {
|
||||
this.mount = mountFactory.mount(fs.getPath("/"), mountPoint, mountName, FS_TYPE_NAME, mountFlags.strip());
|
||||
this.mount = mountFactory.mount(fs.getPath("/"), mountPoint, vaultSettings.mountName().get(), FS_TYPE_NAME, mountFlags.strip());
|
||||
} catch (MountFailedException e) {
|
||||
if (vaultSettings.getCustomMountPath().isPresent()) {
|
||||
LOG.warn("Failed to mount vault into {}. Is this directory currently accessed by another process (e.g. Windows Explorer)?", mountPoint);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class WebDavVolume implements Volume {
|
||||
if (!server.isRunning()) {
|
||||
server.start();
|
||||
}
|
||||
servlet = server.createWebDavServlet(fs.getPath("/"), vaultSettings.getId() + "/" + vaultSettings.displayName().get());
|
||||
servlet = server.createWebDavServlet(fs.getPath("/"), vaultSettings.getId() + "/" + vaultSettings.mountName().get());
|
||||
servlet.start();
|
||||
mount();
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class WebDavVolume implements Volume {
|
||||
|
||||
@Override
|
||||
public Optional<Path> getMountPoint() {
|
||||
return Optional.ofNullable(mountPoint);
|
||||
return Optional.ofNullable(mountPoint); //TODO
|
||||
}
|
||||
|
||||
private String getLocalhostAliasOrNull() {
|
||||
|
||||
@@ -15,12 +15,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
public class VaultSettingsTest {
|
||||
|
||||
@Test
|
||||
public void testNormalize() throws Exception {
|
||||
assertEquals("_", VaultSettings.normalizeMountName(" "));
|
||||
assertEquals("a", VaultSettings.normalizeMountName("ä"));
|
||||
assertEquals("C", VaultSettings.normalizeMountName("Ĉ"));
|
||||
assertEquals("_", VaultSettings.normalizeMountName(":"));
|
||||
assertEquals("_", VaultSettings.normalizeMountName("汉语"));
|
||||
public void testNormalize() {
|
||||
VaultSettings settings = new VaultSettings("id");
|
||||
settings.displayName().setValue(" ");
|
||||
assertEquals("_", settings.normalizeDisplayName());
|
||||
|
||||
settings.displayName().setValue("ä");
|
||||
assertEquals("a", settings.normalizeDisplayName());
|
||||
settings.displayName().setValue("Ĉ");
|
||||
assertEquals("C", settings.normalizeDisplayName());
|
||||
settings.displayName().setValue(":");
|
||||
assertEquals("_", settings.normalizeDisplayName());
|
||||
settings.displayName().setValue("汉语");
|
||||
assertEquals("_", settings.normalizeDisplayName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user