feat: v0.3.12, pretty file info
This commit is contained in:
@@ -72,15 +72,15 @@ public class TinyEncryptMain {
|
||||
log.info("Skip not a file: " + f);
|
||||
continue;
|
||||
}
|
||||
boolean result;
|
||||
boolean decryptSuccess;
|
||||
if (tinyEncryptArgs.encrypt) {
|
||||
result = EncryptedFileUtil.encryptFile(config, tinyEncryptArgs.key, f,
|
||||
decryptSuccess = EncryptedFileUtil.encryptFile(config, tinyEncryptArgs.key, f,
|
||||
tinyEncryptArgs.compress, !tinyEncryptArgs.skipEnvelop, tinyEncryptArgs.requireSign,
|
||||
tinyEncryptArgs.comment);
|
||||
} else {
|
||||
if (tinyEncryptArgs.showInWindow) {
|
||||
EncryptedFileUtil.decryptInWindow(config, f, tinyEncryptArgs.pgp);
|
||||
result = false; // do not delete file
|
||||
decryptSuccess = false; // do not delete file
|
||||
} else if (tinyEncryptArgs.digest) {
|
||||
Bytes sha256 = EncryptedFileUtil.decryptAndDigest(config, f, tinyEncryptArgs.pgp);
|
||||
if (sha256 != null) {
|
||||
@@ -96,12 +96,12 @@ public class TinyEncryptMain {
|
||||
}
|
||||
}
|
||||
}
|
||||
result = false; // do not delete file
|
||||
decryptSuccess = false; // do not delete file
|
||||
} else {
|
||||
result = EncryptedFileUtil.decryptFile(config, f, tinyEncryptArgs.pgp);
|
||||
decryptSuccess = EncryptedFileUtil.decryptFile(config, f, tinyEncryptArgs.pgp);
|
||||
}
|
||||
}
|
||||
if (result && tinyEncryptArgs.removeFile) {
|
||||
if (decryptSuccess && tinyEncryptArgs.removeFile) {
|
||||
log.info("Remove file: " + f);
|
||||
if (!f.delete()) {
|
||||
log.warn("Remove file: " + f + " failed.");
|
||||
|
||||
@@ -118,35 +118,40 @@ public class TinyEncryptMainUtil {
|
||||
Tlv tlv = TlvUtil.readTlv(fis);
|
||||
TinyEncryptMeta meta = tlv.getValueAsBytes().asJSONObject(TinyEncryptMeta.class);
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("File: ").append(f);
|
||||
sb.append("File Info\n").append(header("File")).append(f);
|
||||
if ((meta.getCompress() != null) && meta.getCompress()) {
|
||||
sb.append(" [compressed]");
|
||||
}
|
||||
sb.append("\n");
|
||||
sb.append("File version: ").append(meta.getVersion()).append("\n");
|
||||
sb.append(header("File version")).append(meta.getVersion()).append("\n");
|
||||
if (meta.getFileLength() != null) {
|
||||
sb.append("File size: ").append(meta.getFileLength())
|
||||
sb.append(header("File size")).append(meta.getFileLength())
|
||||
.append(" (").append(ByteUtil.formatBytes(meta.getFileLength())).append(")\n");
|
||||
}
|
||||
if (meta.getFileLastModified() != null) {
|
||||
sb.append("Last modified: ").append(new Date(meta.getFileLastModified())).append("\n");
|
||||
sb.append(header("Last modified")).append(new Date(meta.getFileLastModified())).append("\n");
|
||||
}
|
||||
sb.append("Enc file created: ").append(new Date(meta.getCreated())).append("\n");
|
||||
sb.append("Envelop: ").append(toYesOrNo(StringUtil.isNotBlank(meta.getEnvelop()))).append("\n");
|
||||
sb.append("PGP envelop: ").append(toYesOrNo(StringUtil.isNotBlank(meta.getPgpEnvelop()))).append("\n");
|
||||
sb.append(header("Enc file created")).append(new Date(meta.getCreated())).append("\n");
|
||||
sb.append(header("Envelop")).append(toYesOrNo(StringUtil.isNotBlank(meta.getEnvelop()))).append("\n");
|
||||
sb.append(header("PGP envelop")).append(toYesOrNo(StringUtil.isNotBlank(meta.getPgpEnvelop()))).append("\n");
|
||||
if (StringUtil.isNotBlank(meta.getPgpFingerprint())) {
|
||||
sb.append("PGP fingerprint: ")
|
||||
sb.append(header("PGP fingerprint"))
|
||||
.append(meta.getPgpFingerprint())
|
||||
.append("\n");
|
||||
}
|
||||
sb.append("Agent: ").append(meta.getUserAgent()).append("\n");
|
||||
sb.append(header("Enc agent")).append(meta.getUserAgent()).append("\n");
|
||||
if (StringUtil.isNotBlank(meta.getComment())) {
|
||||
sb.append("Comment: ").append(meta.getComment()).append("\n");
|
||||
sb.append(header("Comment")).append(meta.getComment()).append("\n");
|
||||
}
|
||||
|
||||
log.info(sb.toString());
|
||||
}
|
||||
|
||||
private static String header(String h) {
|
||||
int width = 18;
|
||||
return h + StringUtil.repeat(".", Math.max(width - h.length(), 0)) + ": ";
|
||||
}
|
||||
|
||||
private static String toYesOrNo(boolean b) {
|
||||
return b ? "YES" : "NO";
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.hatter.tools.tinyencrypt.config;
|
||||
|
||||
public class TinyEncryptConstant {
|
||||
public static final String VERSION = "0.3.11";
|
||||
public static final String VERSION = "0.3.12";
|
||||
|
||||
public static final String ENC_FILE_EXT = ".tinyenc";
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ public class MacDockerHelper {
|
||||
try {
|
||||
Class<?> comAppleEawtApplication = ClassLoaderUtil.loadClass(COM_APPLE_EAWT_APPLICATION);
|
||||
Method getApplicationMetohd = ReflectUtil.getDeclaredMethod(comAppleEawtApplication, "getApplication", new Class[0]);
|
||||
//noinspection RedundantArrayCreation
|
||||
Object application = ReflectUtil.invokeMethod(getApplicationMetohd, null, new Object[0]);
|
||||
byte[] iconBytes = RResource.from(SwingWindow.class.getClassLoader()).rStream("icon.png").bytesAndClose();
|
||||
Image image = Toolkit.getDefaultToolkit().createImage(iconBytes);
|
||||
Method setDockIconImageMethod = ReflectUtil.getDeclaredMethod(comAppleEawtApplication, "setDockIconImage", new Class[]{Image.class});
|
||||
//noinspection RedundantArrayCreation
|
||||
ReflectUtil.invokeMethod(setDockIconImageMethod, application, new Object[]{image});
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -8,10 +8,12 @@ public class NilOutputStream extends OutputStream {
|
||||
public void write(int b) throws IOException {
|
||||
}
|
||||
|
||||
@SuppressWarnings("CStyleArrayDeclaration")
|
||||
@Override
|
||||
public void write(byte b[]) throws IOException {
|
||||
}
|
||||
|
||||
@SuppressWarnings("CStyleArrayDeclaration")
|
||||
@Override
|
||||
public void write(byte b[], int off, int len) throws IOException {
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.awt.event.WindowEvent;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class SwingWindow {
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
private String title;
|
||||
private String text;
|
||||
private String message;
|
||||
@@ -49,6 +50,7 @@ public class SwingWindow {
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public String getResult() {
|
||||
try {
|
||||
countDownLatch.await();
|
||||
|
||||
Reference in New Issue
Block a user