Browse Source

Added base classes for MountPointChoosers and added module to component

JaniruTEC 4 years ago
parent
commit
ce262b691a

+ 16 - 0
main/commons/src/main/java/org/cryptomator/common/mountpoint/InvalidMountPointException.java

@@ -0,0 +1,16 @@
+package org.cryptomator.common.mountpoint;
+
+public class InvalidMountPointException extends Exception {
+
+	public InvalidMountPointException(String message) {
+		super(message);
+	}
+
+	public InvalidMountPointException(Throwable cause) {
+		super(cause);
+	}
+
+	public InvalidMountPointException(String message, Throwable cause) {
+		super(message, cause);
+	}
+}

+ 50 - 0
main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooser.java

@@ -0,0 +1,50 @@
+package org.cryptomator.common.mountpoint;
+
+import dagger.MapKey;
+
+import java.nio.file.Path;
+import java.util.Optional;
+
+public interface MountPointChooser {
+
+	default boolean isApplicable() {
+		return true; //Usually most of the choosers should be applicable
+	}
+
+	Optional<Path> chooseMountPoint();
+
+	default boolean prepare(Path mountPoint) throws InvalidMountPointException {
+		return false; //NO-OP
+	}
+
+	default void cleanup(Path mountPoint) {
+		//NO-OP
+	}
+
+	enum Phase {
+
+		CUSTOM_MOUNTPOINT(0),
+
+		CUSTOM_DRIVELETTER(1),
+
+		AVAILABLE_DRIVELETTER(2),
+
+		TEMPORARY_MOUNTPOINT(3);
+
+		private final int timing;
+
+		Phase(int timing) {
+			this.timing = timing;
+		}
+
+		public int getTiming() {
+			return timing;
+		}
+	}
+
+	@MapKey
+	@interface PhaseKey {
+
+		Phase value();
+	}
+}

+ 8 - 0
main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java

@@ -0,0 +1,8 @@
+package org.cryptomator.common.mountpoint;
+
+import dagger.Module;
+
+@Module
+public abstract class MountPointChooserModule {
+
+}

+ 2 - 1
main/commons/src/main/java/org/cryptomator/common/vaults/VaultComponent.java

@@ -6,6 +6,7 @@
 package org.cryptomator.common.vaults;
 
 import dagger.BindsInstance;
+import org.cryptomator.common.mountpoint.MountPointChooserModule;
 import org.cryptomator.common.settings.VaultSettings;
 
 import dagger.Subcomponent;
@@ -14,7 +15,7 @@ import javax.annotation.Nullable;
 import javax.inject.Named;
 
 @PerVault
-@Subcomponent(modules = {VaultModule.class})
+@Subcomponent(modules = {VaultModule.class, MountPointChooserModule.class})
 public interface VaultComponent {
 
 	Vault vault();