From 1d1c3e56f06d9d4d3724e8f58ecf3a19c393d5d7 Mon Sep 17 00:00:00 2001
From: OpticFusion1 <37254722+OpticFusion1@users.noreply.github.com>
Date: Thu, 8 Sep 2022 01:37:53 -0400
Subject: [PATCH] Version 1.4.0 The correct File and ZipEntry hashes are now
logged
---
pom.xml | 2 +-
.../kitsune/tool/impl/IdFetcherTool.java | 32 +++++++++++++++++--
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 80997fa..13bc8be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
optic_fusion1
Kitsune
- 1.3.0
+ 1.4.0
diff --git a/src/main/java/optic_fusion1/kitsune/tool/impl/IdFetcherTool.java b/src/main/java/optic_fusion1/kitsune/tool/impl/IdFetcherTool.java
index f2839d0..f63522f 100644
--- a/src/main/java/optic_fusion1/kitsune/tool/impl/IdFetcherTool.java
+++ b/src/main/java/optic_fusion1/kitsune/tool/impl/IdFetcherTool.java
@@ -1,10 +1,15 @@
package optic_fusion1.kitsune.tool.impl;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import static optic_fusion1.kitsune.Kitsune.LOGGER;
@@ -42,7 +47,11 @@ public void run(List args) {
if (!file.exists()) {
LOGGER.info(tl("file_does_not_exist", file.getName()));
}
- LOGGER.info(DigestUtils.sha1Hex(file.getName()));
+ try {
+ LOGGER.info(getSha1(new FileInputStream(file)));
+ } catch (FileNotFoundException ex) {
+ LOGGER.exception(ex);
+ }
return;
}
File directory = new File(args.get(1));
@@ -53,7 +62,11 @@ public void run(List args) {
for (File file : directory.listFiles()) {
LOGGER.info("\n\n\n\n");
LOGGER.info(tl("processing", file.getName()));
- LOGGER.info(DigestUtils.sha1Hex(file.getName()));
+ try {
+ LOGGER.info(getSha1(new FileInputStream(file)));
+ } catch (FileNotFoundException ex) {
+ LOGGER.exception(ex);
+ }
if (logInnerFiles) {
String extension = FilenameUtils.getExtension(file.getName());
if (!VALID_FILE_EXTENSIONS.contains(extension)) {
@@ -75,13 +88,26 @@ private void handleFile(File file) {
// TODO: Handle nested entries
LOGGER.info(entry.getName() + " is actually a ZipFile.");
}
- LOGGER.info(entry.getName() + ": " + DigestUtils.sha1Hex(entry.getName()));
+ if (entry.isDirectory()) {
+ LOGGER.info(entry.getName() + ": " + DigestUtils.sha1Hex(entry.getName()));
+ continue;
+ }
+ LOGGER.info(entry.getName() + ": " + getSha1(zipFile.getInputStream(entry)));
}
} catch (IOException ex) {
LOGGER.exception(ex);
}
}
+ private String getSha1(InputStream inputStream) {
+ try {
+ return DigestUtils.sha1Hex(inputStream);
+ } catch (IOException ex) {
+ Logger.getLogger(IdFetcherTool.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return "COULD NOT GET SHA-1";
+ }
+
private boolean isActuallyZipFile(ZipFile zipFile, ZipEntry entry) throws IOException {
String zipEntryExtension;
try {