|
@@ -20,6 +20,7 @@ import java.nio.file.Path;
|
|
import java.nio.file.StandardOpenOption;
|
|
import java.nio.file.StandardOpenOption;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
import java.util.ResourceBundle;
|
|
import java.util.ResourceBundle;
|
|
|
|
+import java.util.concurrent.Future;
|
|
|
|
|
|
import javafx.beans.value.ObservableValue;
|
|
import javafx.beans.value.ObservableValue;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.event.ActionEvent;
|
|
@@ -30,6 +31,7 @@ import javafx.scene.control.Alert.AlertType;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.ButtonType;
|
|
import javafx.scene.control.ButtonType;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.control.Label;
|
|
|
|
+import javafx.scene.control.ProgressIndicator;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.scene.input.KeyEvent;
|
|
import javafx.scene.input.KeyEvent;
|
|
|
|
|
|
@@ -41,6 +43,7 @@ import org.cryptomator.files.EncryptingFileVisitor;
|
|
import org.cryptomator.ui.controls.ClearOnDisableListener;
|
|
import org.cryptomator.ui.controls.ClearOnDisableListener;
|
|
import org.cryptomator.ui.controls.SecPasswordField;
|
|
import org.cryptomator.ui.controls.SecPasswordField;
|
|
import org.cryptomator.ui.model.Directory;
|
|
import org.cryptomator.ui.model.Directory;
|
|
|
|
+import org.cryptomator.ui.util.FXThreads;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@@ -65,6 +68,9 @@ public class InitializeController implements Initializable {
|
|
@FXML
|
|
@FXML
|
|
private Button okButton;
|
|
private Button okButton;
|
|
|
|
|
|
|
|
+ @FXML
|
|
|
|
+ private ProgressIndicator progressIndicator;
|
|
|
|
+
|
|
@FXML
|
|
@FXML
|
|
private Label messageLabel;
|
|
private Label messageLabel;
|
|
|
|
|
|
@@ -123,6 +129,7 @@ public class InitializeController implements Initializable {
|
|
|
|
|
|
@FXML
|
|
@FXML
|
|
protected void initializeVault(ActionEvent event) {
|
|
protected void initializeVault(ActionEvent event) {
|
|
|
|
+ setControlsDisabled(true);
|
|
if (!isDirectoryEmpty() && !shouldEncryptExistingFiles()) {
|
|
if (!isDirectoryEmpty() && !shouldEncryptExistingFiles()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -131,18 +138,29 @@ public class InitializeController implements Initializable {
|
|
final CharSequence password = passwordField.getCharacters();
|
|
final CharSequence password = passwordField.getCharacters();
|
|
OutputStream masterKeyOutputStream = null;
|
|
OutputStream masterKeyOutputStream = null;
|
|
try {
|
|
try {
|
|
|
|
+ progressIndicator.setVisible(true);
|
|
masterKeyOutputStream = Files.newOutputStream(masterKeyPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW);
|
|
masterKeyOutputStream = Files.newOutputStream(masterKeyPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW);
|
|
directory.getCryptor().encryptMasterKey(masterKeyOutputStream, password);
|
|
directory.getCryptor().encryptMasterKey(masterKeyOutputStream, password);
|
|
- encryptExistingContents();
|
|
|
|
- directory.getCryptor().swipeSensitiveData();
|
|
|
|
- if (listener != null) {
|
|
|
|
- listener.didInitialize(this);
|
|
|
|
- }
|
|
|
|
|
|
+ final Future<?> futureDone = FXThreads.runOnBackgroundThread(this::encryptExistingContents);
|
|
|
|
+ FXThreads.runOnMainThreadWhenFinished(futureDone, (result) -> {
|
|
|
|
+ progressIndicator.setVisible(false);
|
|
|
|
+ progressIndicator.setVisible(false);
|
|
|
|
+ directory.getCryptor().swipeSensitiveData();
|
|
|
|
+ if (listener != null) {
|
|
|
|
+ listener.didInitialize(this);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
} catch (FileAlreadyExistsException ex) {
|
|
} catch (FileAlreadyExistsException ex) {
|
|
|
|
+ setControlsDisabled(false);
|
|
|
|
+ progressIndicator.setVisible(false);
|
|
messageLabel.setText(localization.getString("initialize.messageLabel.alreadyInitialized"));
|
|
messageLabel.setText(localization.getString("initialize.messageLabel.alreadyInitialized"));
|
|
} catch (InvalidPathException ex) {
|
|
} catch (InvalidPathException ex) {
|
|
|
|
+ setControlsDisabled(false);
|
|
|
|
+ progressIndicator.setVisible(false);
|
|
messageLabel.setText(localization.getString("initialize.messageLabel.invalidPath"));
|
|
messageLabel.setText(localization.getString("initialize.messageLabel.invalidPath"));
|
|
} catch (IOException ex) {
|
|
} catch (IOException ex) {
|
|
|
|
+ setControlsDisabled(false);
|
|
|
|
+ progressIndicator.setVisible(false);
|
|
LOG.error("I/O Exception", ex);
|
|
LOG.error("I/O Exception", ex);
|
|
} finally {
|
|
} finally {
|
|
usernameField.setText(null);
|
|
usernameField.setText(null);
|
|
@@ -152,6 +170,13 @@ public class InitializeController implements Initializable {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void setControlsDisabled(boolean disable) {
|
|
|
|
+ usernameField.setDisable(disable);
|
|
|
|
+ passwordField.setDisable(disable);
|
|
|
|
+ retypePasswordField.setDisable(disable);
|
|
|
|
+ okButton.setDisable(disable);
|
|
|
|
+ }
|
|
|
|
+
|
|
private boolean isDirectoryEmpty() {
|
|
private boolean isDirectoryEmpty() {
|
|
try {
|
|
try {
|
|
final DirectoryStream<Path> dirContents = Files.newDirectoryStream(directory.getPath());
|
|
final DirectoryStream<Path> dirContents = Files.newDirectoryStream(directory.getPath());
|
|
@@ -172,9 +197,13 @@ public class InitializeController implements Initializable {
|
|
return ButtonType.OK.equals(result.get());
|
|
return ButtonType.OK.equals(result.get());
|
|
}
|
|
}
|
|
|
|
|
|
- private void encryptExistingContents() throws IOException {
|
|
|
|
- final FileVisitor<Path> visitor = new EncryptingFileVisitor(directory.getPath(), directory.getCryptor(), this::shouldEncryptExistingFile);
|
|
|
|
- Files.walkFileTree(directory.getPath(), visitor);
|
|
|
|
|
|
+ private void encryptExistingContents() {
|
|
|
|
+ try {
|
|
|
|
+ final FileVisitor<Path> visitor = new EncryptingFileVisitor(directory.getPath(), directory.getCryptor(), this::shouldEncryptExistingFile);
|
|
|
|
+ Files.walkFileTree(directory.getPath(), visitor);
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ LOG.error("I/O Exception", ex);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private boolean shouldEncryptExistingFile(Path path) {
|
|
private boolean shouldEncryptExistingFile(Path path) {
|