Ver Fonte

just a draft

Armin Schrenk há 1 mês atrás
pai
commit
42269a6057

+ 10 - 0
src/main/java/org/cryptomator/common/vaults/Vault.java

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

+ 2 - 0
src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java

@@ -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"), //

+ 24 - 0
src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java

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

+ 39 - 18
src/main/resources/fxml/vault_detail_unlocked.fxml

@@ -7,6 +7,7 @@
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.control.Tooltip?>
 <?import javafx.geometry.Insets?>
+<?import javafx.scene.layout.StackPane?>
 <VBox xmlns:fx="http://javafx.com/fxml"
 	  xmlns="http://javafx.com/javafx"
 	  fx:controller="org.cryptomator.ui.mainwindow.VaultDetailUnlockedController"
@@ -44,24 +45,44 @@
 	<Region VBox.vgrow="ALWAYS"/>
 
 	<HBox alignment="BOTTOM_CENTER">
-		<HBox visible="${controller.accessibleViaPath}" managed="${controller.accessibleViaPath}">
-			<padding>
-				<Insets topRightBottomLeft="0"/>
-			</padding>
-			<Button fx:id="dropZone" styleClass="drag-n-drop" text="%main.vaultDetail.locateEncryptedFileBtn" minWidth="120" maxWidth="180" wrapText="true" textAlignment="CENTER" onAction="#chooseFileAndReveal" contentDisplay="TOP" visible="${!controller.ciphertextPathsCopied}" managed="${!controller.ciphertextPathsCopied}">
-				<graphic>
-					<FontAwesome5IconView glyph="FILE_DOWNLOAD" glyphSize="15"/>
-				</graphic>
-				<tooltip>
-					<Tooltip text="%main.vaultDetail.locateEncryptedFileBtn.tooltip"/>
-				</tooltip>
-			</Button>
-			<Button styleClass="drag-n-drop" text="%main.vaultDetail.encryptedPathsCopied" minWidth="120" maxWidth="180" wrapText="true" textAlignment="CENTER" onAction="#chooseFileAndReveal" contentDisplay="TOP" visible="${controller.ciphertextPathsCopied}" managed="${controller.ciphertextPathsCopied}">
-				<graphic>
-					<FontAwesome5IconView glyph="CHECK" glyphSize="15"/>
-				</graphic>
-			</Button>
-		</HBox>
+		<VBox>
+			<StackPane visible="${controller.accessibleViaPath}" managed="${controller.accessibleViaPath}">
+				<padding>
+					<Insets topRightBottomLeft="0"/>
+				</padding>
+				<Button fx:id="dropZone" styleClass="drag-n-drop" text="%main.vaultDetail.locateEncryptedFileBtn" minWidth="120" maxWidth="180" wrapText="true" textAlignment="CENTER" onAction="#chooseFileAndReveal" contentDisplay="LEFT" visible="${!controller.ciphertextPathsCopied}" managed="${!controller.ciphertextPathsCopied}">
+					<graphic>
+						<FontAwesome5IconView glyph="BULLSEYE" glyphSize="15"/>
+					</graphic>
+					<tooltip>
+						<Tooltip text="%main.vaultDetail.locateEncryptedFileBtn.tooltip"/>
+					</tooltip>
+				</Button>
+				<Button styleClass="drag-n-drop" text="%main.vaultDetail.encryptedPathsCopied" minWidth="120" maxWidth="180" wrapText="true" textAlignment="CENTER" onAction="#chooseFileAndReveal" contentDisplay="TOP" visible="${controller.ciphertextPathsCopied}" managed="${controller.ciphertextPathsCopied}">
+					<graphic>
+						<FontAwesome5IconView glyph="CHECK" glyphSize="15"/>
+					</graphic>
+				</Button>
+			</StackPane>
+			<StackPane visible="${controller.accessibleViaPath}" managed="${controller.accessibleViaPath}">
+				<padding>
+					<Insets topRightBottomLeft="0"/>
+				</padding>
+				<Button fx:id="dropZone2" styleClass="drag-n-drop" text="Decrypt file name" minWidth="120" maxWidth="180" wrapText="true" textAlignment="CENTER" onAction="#chooseEncryptedFileAndGetName" contentDisplay="RIGHT" visible="${!controller.ciphertextPathsCopied}" managed="${!controller.ciphertextPathsCopied}">
+					<graphic>
+						<FontAwesome5IconView glyph="DOT_CIRCLE" glyphSize="15"/>
+					</graphic>
+					<tooltip>
+						<Tooltip text="%main.vaultDetail.locateEncryptedFileBtn.tooltip"/>
+					</tooltip>
+				</Button>
+				<Button styleClass="drag-n-drop" text="%main.vaultDetail.encryptedPathsCopied" minWidth="120" maxWidth="180" wrapText="true" textAlignment="CENTER" onAction="#chooseEncryptedFileAndGetName" contentDisplay="TOP" visible="${controller.ciphertextPathsCopied}" managed="${controller.ciphertextPathsCopied}">
+					<graphic>
+						<FontAwesome5IconView glyph="CHECK" glyphSize="15"/>
+					</graphic>
+				</Button>
+			</StackPane>
+		</VBox>
 
 		<Region HBox.hgrow="ALWAYS"/>