From ce262b691a3b7dbc05f7f71285df5072017474e0 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Tue, 11 Aug 2020 02:44:00 +0200 Subject: [PATCH] Added base classes for MountPointChoosers and added module to component --- .../InvalidMountPointException.java | 16 ++++++ .../common/mountpoint/MountPointChooser.java | 50 +++++++++++++++++++ .../mountpoint/MountPointChooserModule.java | 8 +++ .../common/vaults/VaultComponent.java | 3 +- 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 main/commons/src/main/java/org/cryptomator/common/mountpoint/InvalidMountPointException.java create mode 100644 main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooser.java create mode 100644 main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java diff --git a/main/commons/src/main/java/org/cryptomator/common/mountpoint/InvalidMountPointException.java b/main/commons/src/main/java/org/cryptomator/common/mountpoint/InvalidMountPointException.java new file mode 100644 index 000000000..b0c2fbd7a --- /dev/null +++ b/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); + } +} diff --git a/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooser.java b/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooser.java new file mode 100644 index 000000000..82ec789f0 --- /dev/null +++ b/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 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(); + } +} diff --git a/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java b/main/commons/src/main/java/org/cryptomator/common/mountpoint/MountPointChooserModule.java new file mode 100644 index 000000000..bade9e1bb --- /dev/null +++ b/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 { + +} diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultComponent.java b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultComponent.java index 98a9f951d..8d6baf1a3 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultComponent.java +++ b/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();