Преглед на файлове

Add OneDrive Mac location provider

Armin Schrenk преди 1 година
родител
ревизия
32a65bddce

+ 8 - 5
src/main/java/module-info.java

@@ -1,4 +1,5 @@
 import ch.qos.logback.classic.spi.Configurator;
+import org.cryptomator.common.locationpresets.DropboxLinuxLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.DropboxMacLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.DropboxWindowsLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.GoogleDriveLocationPresetsProvider;
@@ -6,7 +7,8 @@ import org.cryptomator.common.locationpresets.ICloudMacLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.ICloudWindowsLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.LocationPresetsProvider;
 import org.cryptomator.common.locationpresets.MegaLocationPresetsProvider;
-import org.cryptomator.common.locationpresets.OneDriveLocationPresetsProvider;
+import org.cryptomator.common.locationpresets.OneDriveLinuxLocationPresetsProvider;
+import org.cryptomator.common.locationpresets.OneDriveMacLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.OneDriveWindowsLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.PCloudLocationPresetsProvider;
 import org.cryptomator.integrations.tray.TrayMenuController;
@@ -52,8 +54,9 @@ open module org.cryptomator.desktop {
 	provides TrayMenuController with AwtTrayMenuController;
 	provides Configurator with LogbackConfiguratorFactory;
 	provides LocationPresetsProvider with DropboxMacLocationPresetsProvider, //
-			DropboxWindowsLocationPresetsProvider, ICloudMacLocationPresetsProvider, //
-			ICloudWindowsLocationPresetsProvider, GoogleDriveLocationPresetsProvider, //
-			PCloudLocationPresetsProvider, MegaLocationPresetsProvider, //
-			OneDriveLocationPresetsProvider, OneDriveWindowsLocationPresetsProvider;
+			DropboxWindowsLocationPresetsProvider, DropboxLinuxLocationPresetsProvider, //
+			ICloudMacLocationPresetsProvider, ICloudWindowsLocationPresetsProvider, //
+			GoogleDriveLocationPresetsProvider, PCloudLocationPresetsProvider, MegaLocationPresetsProvider, //
+			OneDriveLinuxLocationPresetsProvider, OneDriveWindowsLocationPresetsProvider, //
+			OneDriveMacLocationPresetsProvider;
 }

+ 7 - 7
src/main/java/org/cryptomator/common/locationpresets/DropboxMacLocationPresetsProvider.java

@@ -13,21 +13,21 @@ import static org.cryptomator.integrations.common.OperatingSystem.Value.MAC;
 @CheckAvailability
 public final class DropboxMacLocationPresetsProvider implements LocationPresetsProvider {
 
-	private static final Path LOCATION1 = LocationPresetsProvider.resolveLocation("~/Library/CloudStorage/Dropbox");
-	private static final Path LOCATION2 = LocationPresetsProvider.resolveLocation("~/Dropbox");
+	private static final Path LOCATION = LocationPresetsProvider.resolveLocation("~/Library/CloudStorage/Dropbox");
+	private static final Path FALLBACK_LOCATION = LocationPresetsProvider.resolveLocation("~/Dropbox");
 
 
 	@CheckAvailability
 	public static boolean isPresent() {
-		return Files.isDirectory(LOCATION1) || Files.isDirectory(LOCATION2);
+		return Files.isDirectory(LOCATION) || Files.isDirectory(FALLBACK_LOCATION);
 	}
 
 	@Override
 	public Stream<LocationPreset> getLocations() {
-		if(Files.isDirectory(LOCATION1)) {
-			return Stream.of(new LocationPreset("Dropbox", LOCATION1));
-		} else if(Files.isDirectory(LOCATION2)) {
-			return Stream.of(new LocationPreset("Dropbox", LOCATION2));
+		if(Files.isDirectory(LOCATION)) {
+			return Stream.of(new LocationPreset("Dropbox", LOCATION));
+		} else if(Files.isDirectory(FALLBACK_LOCATION)) {
+			return Stream.of(new LocationPreset("Dropbox", FALLBACK_LOCATION));
 		} else {
 			return Stream.of();
 		}

+ 4 - 0
src/main/java/org/cryptomator/common/locationpresets/LocationPresetsProvider.java

@@ -19,6 +19,10 @@ public interface LocationPresetsProvider {
 	Logger LOG = LoggerFactory.getLogger(LocationPresetsProvider.class);
 	String USER_HOME = System.getProperty("user.home");
 
+	/**
+	 * Streams account-separated location presets found by this provider
+	 * @return Stream of LocationPresets
+	 */
 	Stream<LocationPreset> getLocations();
 
 	static Path resolveLocation(String p) {

+ 1 - 3
src/main/java/org/cryptomator/common/locationpresets/OneDriveLocationPresetsProvider.java

@@ -8,12 +8,10 @@ import java.nio.file.Path;
 import java.util.stream.Stream;
 
 import static org.cryptomator.integrations.common.OperatingSystem.Value.LINUX;
-import static org.cryptomator.integrations.common.OperatingSystem.Value.MAC;
 
-@OperatingSystem(MAC)
 @OperatingSystem(LINUX)
 @CheckAvailability
-public final class OneDriveLocationPresetsProvider implements LocationPresetsProvider {
+public final class OneDriveLinuxLocationPresetsProvider implements LocationPresetsProvider {
 
 
 	private static final Path LOCATION = LocationPresetsProvider.resolveLocation("~/OneDrive");

+ 44 - 0
src/main/java/org/cryptomator/common/locationpresets/OneDriveMacLocationPresetsProvider.java

@@ -0,0 +1,44 @@
+package org.cryptomator.common.locationpresets;
+
+import org.cryptomator.integrations.common.OperatingSystem;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import static org.cryptomator.integrations.common.OperatingSystem.Value.MAC;
+
+@OperatingSystem(MAC)
+public final class OneDriveMacLocationPresetsProvider implements LocationPresetsProvider {
+
+	private static final Path FALLBACK_LOCATION = LocationPresetsProvider.resolveLocation("~/OneDrive");
+	private static final Path PARENT_LOCATION = LocationPresetsProvider.resolveLocation("~/Library/CloudStorage");
+
+	@Override
+	public Stream<LocationPreset> getLocations() {
+		var newLocations = getNewLocations().toList();
+		if (newLocations.size() >= 1) {
+			return newLocations.stream();
+		} else {
+			return getOldLocation();
+		}
+	}
+
+	private Stream<LocationPreset> getNewLocations() {
+		try (var dirStream = Files.newDirectoryStream(PARENT_LOCATION, "OneDrive*")) {
+			return StreamSupport.stream(dirStream.spliterator(), false) //
+					.filter(Files::isDirectory) //
+					.map(p -> new LocationPreset(String.join(" - ", p.getFileName().toString().split("-")), p));
+		} catch (IOException e) {
+			return Stream.of();
+		}
+	}
+
+	private Stream<LocationPreset> getOldLocation() {
+		return Stream.of(new LocationPreset("OneDrive", FALLBACK_LOCATION)).filter(preset -> Files.isDirectory(preset.path()));
+	}
+
+
+}