mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-17 08:06:52 -04:00
new class VaultPreparator in recovery package
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package org.cryptomator.common.recovery;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.common.vaults.VaultComponent;
|
||||
import org.cryptomator.common.vaults.VaultConfigCache;
|
||||
import org.cryptomator.common.vaults.VaultListManager;
|
||||
import org.cryptomator.integrations.mount.MountService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.cryptomator.common.vaults.VaultState.Value.LOCKED;
|
||||
|
||||
public final class VaultPreparator {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(VaultPreparator.class);
|
||||
|
||||
private VaultPreparator() {}
|
||||
|
||||
public static Vault prepareVault(File selectedDirectory, VaultComponent.Factory vaultComponentFactory, List<MountService> mountServices) {
|
||||
Path selectedPath = selectedDirectory.toPath();
|
||||
VaultSettings vaultSettings = VaultSettings.withRandomId();
|
||||
vaultSettings.path.set(selectedPath);
|
||||
if (selectedPath.getFileName() != null) {
|
||||
vaultSettings.displayName.set(selectedPath.getFileName().toString());
|
||||
} else {
|
||||
vaultSettings.displayName.set("defaultVaultName");
|
||||
}
|
||||
|
||||
var wrapper = new VaultConfigCache(vaultSettings);
|
||||
Vault vault = vaultComponentFactory.create(vaultSettings, wrapper, LOCKED, null).vault();
|
||||
try {
|
||||
VaultListManager.determineVaultState(vault.getPath());
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Failed to determine vault state for {}", vaultSettings.path.get(), e);
|
||||
}
|
||||
|
||||
//due to https://github.com/cryptomator/cryptomator/issues/2880#issuecomment-1680313498
|
||||
var nameOfWinfspLocalMounter = "org.cryptomator.frontend.fuse.mount.WinFspMountProvider";
|
||||
if (SystemUtils.IS_OS_WINDOWS && vaultSettings.path.get().toString().contains("Dropbox") && mountServices.stream().anyMatch(s -> s.getClass().getName().equals(nameOfWinfspLocalMounter))) {
|
||||
vaultSettings.mountService.setValue(nameOfWinfspLocalMounter);
|
||||
}
|
||||
|
||||
return vault;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,10 @@ package org.cryptomator.ui.mainwindow;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.recovery.RecoveryActionType;
|
||||
import org.cryptomator.common.recovery.VaultPreparator;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.common.vaults.VaultComponent;
|
||||
import org.cryptomator.common.vaults.VaultConfigCache;
|
||||
import org.cryptomator.common.vaults.VaultListManager;
|
||||
import org.cryptomator.cryptofs.CryptoFileSystemProvider;
|
||||
import org.cryptomator.cryptofs.DirStructure;
|
||||
@@ -255,7 +254,7 @@ public class VaultListController implements FxController {
|
||||
}
|
||||
} while (selectedDirectory == null);
|
||||
|
||||
Vault preparedVault = prepareVault(selectedDirectory, vaultComponentFactory, mountServices);
|
||||
Vault preparedVault = VaultPreparator.prepareVault(selectedDirectory, vaultComponentFactory, mountServices);
|
||||
|
||||
Optional<Vault> matchingVaultListEntry = vaultListManager.get(preparedVault.getPath());
|
||||
if (matchingVaultListEntry.isPresent()) {
|
||||
@@ -278,33 +277,6 @@ public class VaultListController implements FxController {
|
||||
|
||||
}
|
||||
|
||||
public static Vault prepareVault(File selectedDirectory, VaultComponent.Factory vaultComponentFactory, List<MountService> mountServices) {
|
||||
Path selectedPath = selectedDirectory.toPath();
|
||||
VaultSettings vaultSettings = VaultSettings.withRandomId();
|
||||
vaultSettings.path.set(selectedPath);
|
||||
if (selectedPath.getFileName() != null) {
|
||||
vaultSettings.displayName.set(selectedPath.getFileName().toString());
|
||||
} else {
|
||||
vaultSettings.displayName.set("defaultVaultName");
|
||||
}
|
||||
|
||||
var wrapper = new VaultConfigCache(vaultSettings);
|
||||
Vault vault = vaultComponentFactory.create(vaultSettings, wrapper, LOCKED, null).vault();
|
||||
try {
|
||||
VaultListManager.determineVaultState(vault.getPath());
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Failed to determine vault state for {}", vaultSettings.path.get(), e);
|
||||
}
|
||||
|
||||
//due to https://github.com/cryptomator/cryptomator/issues/2880#issuecomment-1680313498
|
||||
var nameOfWinfspLocalMounter = "org.cryptomator.frontend.fuse.mount.WinFspMountProvider";
|
||||
if (SystemUtils.IS_OS_WINDOWS && vaultSettings.path.get().toString().contains("Dropbox") && mountServices.stream().anyMatch(s -> s.getClass().getName().equals(nameOfWinfspLocalMounter))) {
|
||||
vaultSettings.mountService.setValue(nameOfWinfspLocalMounter);
|
||||
}
|
||||
|
||||
return vault;
|
||||
}
|
||||
|
||||
private void pressedShortcutToRemoveVault() {
|
||||
final var vault = selectedVault.get();
|
||||
if (vault != null && EnumSet.of(LOCKED, MISSING, ERROR, NEEDS_MIGRATION, ALL_MISSING, VAULT_CONFIG_MISSING).contains(vault.getState())) {
|
||||
|
||||
Reference in New Issue
Block a user