From 7f9cdbddfd9f8bb7e0f48a15057de289292cf1be Mon Sep 17 00:00:00 2001 From: myinon Date: Sun, 1 Jan 2017 15:50:42 -0600 Subject: [PATCH] Update JSFVWriter.java Added some console output and formatting when processing directories. --- src/JSFVWriter.java | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/JSFVWriter.java b/src/JSFVWriter.java index 4126862..964ada4 100644 --- a/src/JSFVWriter.java +++ b/src/JSFVWriter.java @@ -27,12 +27,12 @@ import java.util.zip.CRC32; public class JSFVWriter { - private static CRC32 crc = new CRC32(); + private static final CRC32 crc = new CRC32(); private static int success = 0; private static int failed = 0; - static void calculateCRC(Path file, Path sfvParent, List lines) { + private static void calculateCRC(Path file, Path sfvParent, List lines) { if (Files.exists(file, NOFOLLOW_LINKS)) { StringBuilder builder = new StringBuilder(); crc.reset(); @@ -128,9 +128,9 @@ public static void main(String args[]) { List lines = new ArrayList<>(); if (description.length() > 0) { - lines.add("; SFV File for " + description); + lines.add(String.format("; SFV File for %s", description)); } - lines.add("; Created on " + FileTime.fromMillis(currentTimeMillis())); + lines.add(String.format("; Created on ", FileTime.fromMillis(currentTimeMillis()))); lines.add("; File encoding is UTF-8"); lines.add(""); @@ -178,6 +178,7 @@ public static void main(String args[]) { } Collections.sort(list); final Path[] source = list.toArray(new Path[0]); + boolean lastWasFile = false; // Loop through the files and directories and add them to the file for (int i = 0; i < source.length; i++) { @@ -185,22 +186,38 @@ public static void main(String args[]) { boolean isDir = Files.isDirectory(src); if (isDir) { + if (lastWasFile) { + out.println(); + lastWasFile = false; + } + try { EnumSet opts = EnumSet.noneOf(FileVisitOption.class); Files.walkFileTree(src, opts, Integer.MAX_VALUE, new FileVisitor() { + boolean lastWasFile = false; + @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + if (lastWasFile) { + out.println(); + lastWasFile = false; + } + + out.printf("Traversing folder: %s%n%n", dir); return CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { calculateCRC(file, sfvParent, lines); + lastWasFile = true; return CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + out.println(); + lastWasFile = false; return CONTINUE; } @@ -217,10 +234,10 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce } } else { calculateCRC(src, sfvParent, lines); + lastWasFile = true; } } - out.println(); out.printf("%d file(s) processed successfully%n%d file(s) failed to be processed%n", success, failed); try {