diff --git a/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java b/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java index 57cf03b..32f0618 100644 --- a/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java +++ b/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java @@ -18,15 +18,19 @@ import java.util.Set; public class RescloneConfig implements JfCustomConfig { public static Set packs; public static boolean pruneUnused; + public static boolean logProcessing; + private static final String ERR_DUPLICATE = "Unexpected duplicate \"%s\" in Resclone config"; private static final String PACKS = "packs"; private static final String PRUNE_UNUSED = "pruneUnused"; + private static final String LOG_PROCESSING = "logProcessing"; private static final Type META_SET = new TypeToken>(){}.getType(); private static void load(Path path) throws IOException { if (!Files.exists(path)) { packs = new HashSet<>(); pruneUnused = true; + logProcessing = false; write(path); return; } @@ -43,17 +47,22 @@ public class RescloneConfig implements JfCustomConfig { reader.beginObject(); Set packs = null; Boolean pruneUnused = null; + Boolean logProcessing = null; while (reader.peek() != JsonToken.END_OBJECT) { final String name = reader.nextName(); switch (name) { case PACKS -> { - if (packs != null) throw new JsonParseException("Unexpected duplicate \"" + PACKS + "\" in Resclone config"); + if (packs != null) throw new JsonParseException(ERR_DUPLICATE.formatted(PACKS)); packs = GsonHolders.CONFIG.getGson().fromJson(reader, META_SET); } case PRUNE_UNUSED -> { - if (pruneUnused != null) throw new JsonParseException("Unexpected duplicate \"" + PRUNE_UNUSED + "\" in Resclone config"); + if (pruneUnused != null) throw new JsonParseException(ERR_DUPLICATE.formatted(PRUNE_UNUSED)); pruneUnused = reader.nextBoolean(); } + case LOG_PROCESSING -> { + if (logProcessing != null) throw new JsonParseException(ERR_DUPLICATE.formatted(LOG_PROCESSING)); + logProcessing = reader.nextBoolean(); + } default -> throw new JsonParseException("Unexpected element: \"" + name + "\" in Resclone config"); } } @@ -63,8 +72,13 @@ public class RescloneConfig implements JfCustomConfig { pruneUnused = true; updateRequired = true; } + if (logProcessing == null) { + logProcessing = false; + updateRequired = true; + } RescloneConfig.packs = packs; RescloneConfig.pruneUnused = pruneUnused; + RescloneConfig.logProcessing = logProcessing; } else throw new JsonParseException("Expected Resclone config to be an object or array"); } if (updateRequired) write(path); @@ -80,6 +94,9 @@ public class RescloneConfig implements JfCustomConfig { writer.comment("Whether to prune unused packs from the cache") .name(PRUNE_UNUSED) .value(pruneUnused) + .comment("Whether to log processing of packs") + .name(LOG_PROCESSING) + .value(logProcessing) .endObject(); } } @@ -102,6 +119,7 @@ public class RescloneConfig implements JfCustomConfig { }).setPath(path) .>value(PACKS, new HashSet<>(), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, io.gitlab.jfronny.libjf.config.api.v2.type.Type.ofClass(META_SET), 100, () -> packs, p -> packs = p) .value(PRUNE_UNUSED, pruneUnused, () -> pruneUnused, p -> pruneUnused = p) + .value(LOG_PROCESSING, logProcessing, () -> logProcessing, p -> logProcessing = p) ).load(); } diff --git a/src/main/java/io/gitlab/jfronny/resclone/processors/PruneVanillaProcessor.java b/src/main/java/io/gitlab/jfronny/resclone/processors/PruneVanillaProcessor.java index 361619a..6bcff69 100644 --- a/src/main/java/io/gitlab/jfronny/resclone/processors/PruneVanillaProcessor.java +++ b/src/main/java/io/gitlab/jfronny/resclone/processors/PruneVanillaProcessor.java @@ -1,6 +1,7 @@ package io.gitlab.jfronny.resclone.processors; import io.gitlab.jfronny.resclone.Resclone; +import io.gitlab.jfronny.resclone.RescloneConfig; import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor; import net.minecraft.server.MinecraftServer; import org.apache.commons.io.IOUtils; @@ -22,7 +23,10 @@ public class PruneVanillaProcessor implements PackProcessor { InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString()); if (vn != null) { try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) { - return IOUtils.contentEquals(vn, pk); + if (IOUtils.contentEquals(vn, pk)) { + if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Pruning file unchanged from vanilla: {}", s); + return true; + } } } } catch (Throwable e) { diff --git a/src/main/java/io/gitlab/jfronny/resclone/processors/RemoveEmptyProcessor.java b/src/main/java/io/gitlab/jfronny/resclone/processors/RemoveEmptyProcessor.java index 9e36f87..320a0b3 100644 --- a/src/main/java/io/gitlab/jfronny/resclone/processors/RemoveEmptyProcessor.java +++ b/src/main/java/io/gitlab/jfronny/resclone/processors/RemoveEmptyProcessor.java @@ -1,6 +1,7 @@ package io.gitlab.jfronny.resclone.processors; import io.gitlab.jfronny.resclone.Resclone; +import io.gitlab.jfronny.resclone.RescloneConfig; import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor; import java.io.IOException; @@ -14,7 +15,10 @@ public class RemoveEmptyProcessor implements PackProcessor { Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> { if (Files.isDirectory(s)) { try (DirectoryStream paths = Files.newDirectoryStream(s)) { - return !paths.iterator().hasNext(); + if (!paths.iterator().hasNext()) { + if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Pruning empty directory: {}", s); + return true; + } } catch (IOException e) { Resclone.LOGGER.error("Could not check whether directory has entries", e); } diff --git a/src/main/java/io/gitlab/jfronny/resclone/processors/RootPathProcessor.java b/src/main/java/io/gitlab/jfronny/resclone/processors/RootPathProcessor.java index 3e726ae..ee1eaca 100644 --- a/src/main/java/io/gitlab/jfronny/resclone/processors/RootPathProcessor.java +++ b/src/main/java/io/gitlab/jfronny/resclone/processors/RootPathProcessor.java @@ -1,5 +1,7 @@ package io.gitlab.jfronny.resclone.processors; +import io.gitlab.jfronny.resclone.Resclone; +import io.gitlab.jfronny.resclone.RescloneConfig; import io.gitlab.jfronny.resclone.util.io.MoveDirVisitor; import java.io.IOException; @@ -14,6 +16,7 @@ public class RootPathProcessor implements PackProcessor { try (DirectoryStream paths = Files.newDirectoryStream(root)) { for (Path path : paths) { if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) { + if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Moving discovered root out of: {}", path); Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING)); } }