mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 18:51:26 +00:00
increase readability
This commit is contained in:
@@ -5,6 +5,7 @@ import org.cryptomator.integrations.common.OperatingSystem;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
@@ -15,19 +16,14 @@ import static org.cryptomator.integrations.common.OperatingSystem.Value.LINUX;
|
||||
public final class DropboxLinuxLocationPresetsProvider implements LocationPresetsProvider {
|
||||
|
||||
private static final Path USER_HOME = LocationPresetsProvider.resolveLocation("~/.").toAbsolutePath();
|
||||
private static final Pattern PATTERN = Pattern.compile("Dropbox \\(.+\\)");
|
||||
private static final Predicate<String> PATTERN = Pattern.compile("Dropbox \\(.+\\)").asMatchPredicate();
|
||||
|
||||
@Override
|
||||
public Stream<LocationPreset> getLocations() {
|
||||
try (var dirStream = Files.newDirectoryStream(USER_HOME,"Dropbox*")){
|
||||
return StreamSupport.stream(dirStream.spliterator(), false).flatMap(p -> {
|
||||
var matcher = PATTERN.matcher(p.getFileName().toString());
|
||||
if(matcher.matches() && Files.isDirectory(p)) {
|
||||
return Stream.of(new LocationPreset(matcher.group(), p));
|
||||
} else {
|
||||
return Stream.of();
|
||||
}
|
||||
});
|
||||
try (var dirStream = Files.newDirectoryStream(USER_HOME, "Dropbox*")) {
|
||||
return StreamSupport.stream(dirStream.spliterator(), false) //
|
||||
.filter(p -> Files.isDirectory(p) && PATTERN.test(p.getFileName().toString())) //
|
||||
.map(p -> new LocationPreset(p.getFileName().toString(), p));
|
||||
} catch (IOException e) {
|
||||
return Stream.of();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ public final class OneDriveWindowsLocationPresetsProvider implements LocationPre
|
||||
var name = "OneDrive"; //we assume personal oneDrive account by default
|
||||
if (!accountRegKey.endsWith("Personal")) {
|
||||
name = queryRegistry(accountRegKey, List.of("/v", "DisplayName"), l -> l.contains("DisplayName")).map(result -> result.substring(result.indexOf(REGSTR_TOKEN) + REGSTR_TOKEN.length()).trim()) //
|
||||
.map("OneDrive - "::concat).findFirst().orElseThrow();
|
||||
.map("OneDrive - "::concat) //
|
||||
.findFirst().orElseThrow();
|
||||
}
|
||||
cloudLocations.add(new LocationPreset(name, path));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user