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