feat: add option to disable additional processors
ci/woodpecker/push/jfmod Pipeline was successful Details
ci/woodpecker/tag/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2024-04-01 15:12:02 +02:00
parent e8d0b38121
commit 88f071d919
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 27 additions and 5 deletions

View File

@ -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));

View File

@ -18,11 +18,13 @@ import java.util.Set;
public class RescloneConfig implements JfCustomConfig {
public static Set<PackMetaUnloaded> 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<Set<PackMetaUnloaded>>(){}.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<PackMetaUnloaded> 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)
.<Set<PackMetaUnloaded>>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();
}

View File

@ -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"
}