armin 7 years ago
parent
commit
296848b41e

+ 3 - 1
main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java

@@ -16,6 +16,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -41,6 +42,7 @@ import org.cryptomator.ui.model.VaultFactory;
 import org.cryptomator.ui.model.VaultList;
 import org.cryptomator.ui.util.DialogBuilderUtil;
 import org.cryptomator.ui.util.EawtApplicationWrapper;
+import org.cryptomator.ui.util.ProcessFilePath;
 import org.fxmisc.easybind.EasyBind;
 import org.fxmisc.easybind.Subscription;
 import org.fxmisc.easybind.monadic.MonadicBinding;
@@ -263,7 +265,7 @@ public class MainController implements ViewController {
 			return;
 		}
 		try {
-			final Path vaultDir = file.toPath();
+			final Path vaultDir = Paths.get(ProcessFilePath.processFilePath(file.getPath()));
 			if (Files.exists(vaultDir)) {
 				try (Stream<Path> stream = Files.list(vaultDir)) {
 					if (stream.filter(this::isNotHidden).findAny().isPresent()) {

+ 27 - 0
main/ui/src/main/java/org/cryptomator/ui/util/ProcessFilePath.java

@@ -0,0 +1,27 @@
+package org.cryptomator.ui.util;
+
+import java.io.File;
+
+/**
+ * Class for processing a file path.
+ * If the filepath is a UNC file path (syntax: \\server[@SSL][@port][\path]), the "@SSL" and "@port" part is ripped off.
+ */
+public class ProcessFilePath {
+
+	public static String processFilePath(String path) {
+		int uncIndex = path.indexOf('@');
+		int resourceIndex = path.indexOf('\\', 2);
+		if (System.getProperty("os.name").contains("Windows") && path.startsWith("\\\\") && uncIndex >= 0 && (resourceIndex == -1 || uncIndex < resourceIndex)) {
+			//the returned file has a UNC-Path, which needs further processing
+			if (resourceIndex >= 0) {
+				//the optional path part exists, therefore we cut everything else out
+				return path.substring(0, uncIndex).concat(path.substring(resourceIndex));
+			} else {
+				return path.substring(0, uncIndex);
+			}
+		} else {
+			return path;
+		}
+	}
+
+}

+ 37 - 0
main/ui/src/test/java/org/cryptomator/ui/util/ProcessFilePathsTest.java

@@ -0,0 +1,37 @@
+package org.cryptomator.ui.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ProcessFilePathsTest {
+
+	@Test
+	public void testSavedFilePathAtVaultCreation() {
+		String uncBase = "\\\\server";
+		String uncSSL = "@SSL";
+		String port = "@1234";
+		String path = "\\@test@Dir\\test@File.test";
+		String driveLetter = "C:";
+		String uncWithSSL = uncBase.concat(uncSSL);
+		String uncWithPort = uncBase.concat(port);
+		String uncWithPath = uncBase.concat(path);
+		String uncWithSSLAndPath = uncWithSSL.concat(path);
+		String uncWithPortAndPath = uncWithPort.concat(path);
+		String uncWithSSLAndPort = uncWithSSL.concat(port);
+		String uncWithSSLAndPortAndPath = uncWithSSLAndPort.concat(path);
+		String pathWithDriveLetter = driveLetter.concat(path);
+		String uriWithUserinfo = "file:\\\\userinfo@server\\test@dir";
+
+		Assert.assertEquals(uncBase, ProcessFilePath.processFilePath(uncBase));
+		Assert.assertEquals(path, ProcessFilePath.processFilePath(path));
+		Assert.assertEquals(uncBase, ProcessFilePath.processFilePath(uncWithSSL));
+		Assert.assertEquals(uncBase, ProcessFilePath.processFilePath(uncWithPort));
+		Assert.assertEquals(uncBase, ProcessFilePath.processFilePath(uncWithSSLAndPort));
+		Assert.assertEquals(uncWithPath, ProcessFilePath.processFilePath(uncWithPath));
+		Assert.assertEquals(uncWithPath, ProcessFilePath.processFilePath(uncWithSSLAndPath));
+		Assert.assertEquals(uncWithPath, ProcessFilePath.processFilePath(uncWithPortAndPath));
+		Assert.assertEquals(uncWithPath, ProcessFilePath.processFilePath(uncWithSSLAndPortAndPath));
+		Assert.assertEquals(pathWithDriveLetter, ProcessFilePath.processFilePath(pathWithDriveLetter));
+		Assert.assertEquals(uriWithUserinfo, ProcessFilePath.processFilePath(uriWithUserinfo));
+	}
+}