Skip to content

Commit

Permalink
Version 1.4.0
Browse files Browse the repository at this point in the history
The correct File and ZipEntry hashes are now logged
  • Loading branch information
OpticFusion1 committed Sep 8, 2022
1 parent edcd575 commit 1d1c3e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>optic_fusion1</groupId>
<artifactId>Kitsune</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>

<build>
<resources>
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/optic_fusion1/kitsune/tool/impl/IdFetcherTool.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,7 +47,11 @@ public void run(List<String> 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));
Expand All @@ -53,7 +62,11 @@ public void run(List<String> 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)) {
Expand All @@ -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 {
Expand Down

0 comments on commit 1d1c3e5

Please sign in to comment.