just a draft

This commit is contained in:
Armin Schrenk
2025-03-12 18:01:06 +01:00
parent 401b0afe9f
commit 42269a6057
4 changed files with 75 additions and 18 deletions

View File

@@ -412,6 +412,16 @@ public class Vault {
}
}
/**
*/
public String getCleartextName(Path ciphertextPath) throws IOException {
if (!state.getValue().equals(VaultState.Value.UNLOCKED)) {
throw new IllegalStateException("Vault is not unlocked");
}
var fs = cryptoFileSystem.get();
return fs.getCleartextName(ciphertextPath);
}
public VaultConfigCache getVaultConfigCache() {
return configCache;
}

View File

@@ -8,6 +8,8 @@ public enum FontAwesome5Icon {
ARROW_UP("\uF062"), //
BAN("\uF05E"), //
BUG("\uF188"), //
BULLSEYE("\uF140"), //
DOT_CIRCLE("\uF192"), //
CARET_DOWN("\uF0D7"), //
CARET_RIGHT("\uF0Da"), //
CHECK("\uF00C"), //

View File

@@ -26,13 +26,16 @@ import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;
import javafx.scene.input.DragEvent;
import javafx.scene.input.TransferMode;
import javafx.stage.FileChooser;
import javafx.stage.Popup;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
@@ -110,6 +113,7 @@ public class VaultDetailUnlockedController implements FxController {
draggingOver.set(true);
} else if (DragEvent.DRAG_DROPPED.equals(event.getEventType()) && event.getGestureSource() == null && event.getDragboard().hasFiles()) {
List<Path> ciphertextPaths = event.getDragboard().getFiles().stream().map(File::toPath).map(this::getCiphertextPath).flatMap(Optional::stream).toList();
//TODO: differ between encrypted and decrypted files
if (ciphertextPaths.isEmpty()) {
wrongFileAlert.build().showWrongFileAlertWindow();
} else {
@@ -161,6 +165,26 @@ public class VaultDetailUnlockedController implements FxController {
}
}
@FXML
public void chooseEncryptedFileAndGetName() {
var fileChooser = new FileChooser();
fileChooser.setTitle(resourceBundle.getString("main.vaultDetail.filePickerTitle"));
fileChooser.setInitialDirectory(vault.getValue().getPath().toFile());
var ciphertextNode = fileChooser.showOpenDialog(mainWindow);
try {
var nodeName = vault.get().getCleartextName(ciphertextNode.toPath());
var alert = new Alert(Alert.AlertType.INFORMATION, "The answer is: %s".formatted(nodeName), ButtonType.OK);
alert.showAndWait();
//.filter(response -> response == ButtonType.OK)
//.ifPresent(response -> formatSystem());
} catch (Exception e) {
LOG.warn("Failed to decrypt filename for {}", ciphertextNode, e);
var alert = new Alert(Alert.AlertType.ERROR, "The exception is: %s".formatted(e.getClass()), ButtonType.OK);
alert.showAndWait();
}
}
private boolean startsWithVaultAccessPoint(Path path) {
return path.startsWith(Path.of(mountPoint.getValue()));
}