Added base classes for MountPointChoosers and added module to component

This commit is contained in:
JaniruTEC
2020-08-11 02:44:00 +02:00
parent 597899d2bf
commit ce262b691a
4 changed files with 76 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

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

View File

@@ -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();