diff --git a/src/main/java/io/gitlab/jfronny/resclone/Resclone.java b/src/main/java/io/gitlab/jfronny/resclone/Resclone.java index e7ad059..998ffc5 100644 --- a/src/main/java/io/gitlab/jfronny/resclone/Resclone.java +++ b/src/main/java/io/gitlab/jfronny/resclone/Resclone.java @@ -47,13 +47,15 @@ public class Resclone implements ModInitializer { PROCESSORS.clear(); DOWNLOADED_PACKS.clear(); - addProcessor(new RootPathProcessor()); //This should be run before any other processor to make sure the path is valid + addProcessor(new RootPathProcessor()); //This should be run before any other processor to make sure the root is correct addFetcher(new BasicFileFetcher()); addFetcher(new GitHubFetcher()); addFetcher(new CurseforgeFetcher()); addFetcher(new ModrinthFetcher()); - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) addProcessor(new PruneVanillaProcessor()); - addProcessor(new RemoveEmptyProcessor()); + if (RescloneConfig.filterPacks) { + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) addProcessor(new PruneVanillaProcessor()); + addProcessor(new RemoveEmptyProcessor()); + } reload(); LOGGER.info("Installed {} resource pack{}.", packCount, packCount == 1 ? "" : "s"); @@ -86,6 +88,7 @@ public class Resclone implements ModInitializer { } else { try { + //TODO migrate this to try-with-resources once JVM is updated ExecutorService pool = Executors.newFixedThreadPool(RescloneConfig.packs.size()); for (PackMetaUnloaded s : RescloneConfig.packs) { pool.submit(generateTask(s, metas)); diff --git a/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java b/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java index 32f0618..f311385 100644 --- a/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java +++ b/src/main/java/io/gitlab/jfronny/resclone/RescloneConfig.java @@ -18,11 +18,13 @@ import java.util.Set; public class RescloneConfig implements JfCustomConfig { public static Set packs; public static boolean pruneUnused; + public static boolean filterPacks; 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 FILTER_PACKS = "filterPacks"; private static final String LOG_PROCESSING = "logProcessing"; private static final Type META_SET = new TypeToken>(){}.getType(); @@ -30,6 +32,7 @@ public class RescloneConfig implements JfCustomConfig { if (!Files.exists(path)) { packs = new HashSet<>(); pruneUnused = true; + filterPacks = true; logProcessing = false; write(path); return; @@ -47,6 +50,7 @@ public class RescloneConfig implements JfCustomConfig { reader.beginObject(); Set packs = null; Boolean pruneUnused = null; + Boolean filterPacks = null; Boolean logProcessing = null; while (reader.peek() != JsonToken.END_OBJECT) { final String name = reader.nextName(); @@ -59,6 +63,10 @@ public class RescloneConfig implements JfCustomConfig { if (pruneUnused != null) throw new JsonParseException(ERR_DUPLICATE.formatted(PRUNE_UNUSED)); pruneUnused = reader.nextBoolean(); } + case FILTER_PACKS -> { + if (filterPacks != null) throw new JsonParseException(ERR_DUPLICATE.formatted(FILTER_PACKS)); + filterPacks = reader.nextBoolean(); + } case LOG_PROCESSING -> { if (logProcessing != null) throw new JsonParseException(ERR_DUPLICATE.formatted(LOG_PROCESSING)); logProcessing = reader.nextBoolean(); @@ -72,12 +80,17 @@ public class RescloneConfig implements JfCustomConfig { pruneUnused = true; updateRequired = true; } + if (filterPacks == null) { + filterPacks = true; + updateRequired = true; + } if (logProcessing == null) { logProcessing = false; updateRequired = true; } RescloneConfig.packs = packs; RescloneConfig.pruneUnused = pruneUnused; + RescloneConfig.filterPacks = filterPacks; RescloneConfig.logProcessing = logProcessing; } else throw new JsonParseException("Expected Resclone config to be an object or array"); } @@ -91,10 +104,13 @@ public class RescloneConfig implements JfCustomConfig { .comment("The packs to be loaded by resclone") .name(PACKS); GsonHolders.CONFIG.getGson().toJson(packs, META_SET, writer); - writer.comment("Whether to prune unused packs from the cache") + writer.comment("Automatically remove all downloaded packs that are not in the config to free up unneeded space") .name(PRUNE_UNUSED) .value(pruneUnused) - .comment("Whether to log processing of packs") + .comment("Whether to filter packs to remove files unchanged from vanilla and empty directories") + .name(FILTER_PACKS) + .value(filterPacks) + .comment("Log automatic processing steps applied to downloaded packs") .name(LOG_PROCESSING) .value(logProcessing) .endObject(); @@ -119,6 +135,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(FILTER_PACKS, filterPacks, () -> filterPacks, p -> filterPacks = p) .value(LOG_PROCESSING, logProcessing, () -> logProcessing, p -> logProcessing = p) ).load(); } diff --git a/src/main/resources/assets/resclone/lang/en_us.json b/src/main/resources/assets/resclone/lang/en_us.json index 7c3b03e..a3ea22e 100644 --- a/src/main/resources/assets/resclone/lang/en_us.json +++ b/src/main/resources/assets/resclone/lang/en_us.json @@ -4,6 +4,8 @@ "resclone.jfconfig.packs.tooltip": "The packs to download and add", "resclone.jfconfig.pruneUnused": "Prune Unused", "resclone.jfconfig.pruneUnused.tooltip": "Automatically remove all downloaded packs that are not in the config to free up unneeded space", + "resclone.jfconfig.filterPacks": "Filter Packs", + "resclone.jfconfig.filterPacks.tooltip": "Whether to filter packs to remove files unchanged from vanilla and empty directories", "resclone.jfconfig.logProcessing": "Log Processing", "resclone.jfconfig.logProcessing.tooltip": "Log automatic processing steps applied to downloaded packs" } \ No newline at end of file