From 3a658e10f1add6dbb4d669abb69354760a9ba67a Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Fri, 23 Jul 2021 08:36:42 -0400 Subject: [PATCH] Fix possible load keys loading all data folders --- .../engine/data/loader/ResourceLoader.java | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/data/loader/ResourceLoader.java b/src/main/java/com/volmit/iris/engine/data/loader/ResourceLoader.java index ac01a2c3b..ab1c74355 100644 --- a/src/main/java/com/volmit/iris/engine/data/loader/ResourceLoader.java +++ b/src/main/java/com/volmit/iris/engine/data/loader/ResourceLoader.java @@ -37,6 +37,7 @@ import lombok.Data; import java.io.File; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; @Data public class ResourceLoader { @@ -91,6 +92,32 @@ public class ResourceLoader { J.a(() -> Iris.warn("Couldn't Load " + resourceTypeName + " file: " + path.getPath() + ": " + e.getMessage())); } + private KList matchAllFiles(File root, Predicate f) + { + KList fx = new KList<>(); + matchFiles(root, fx, f); + return fx; + } + + private void matchFiles(File at, KList files, Predicate f) + { + if(at.isDirectory()) + { + for(File i : at.listFiles()) + { + matchFiles(i, files, f); + } + } + + else + { + if(f.test(at)) + { + files.add(at); + } + } + } + public String[] getPossibleKeys() { if (possibleKeys != null) { return possibleKeys; @@ -99,17 +126,11 @@ public class ResourceLoader { Iris.info("Building " + resourceTypeName + " Registry Lists"); KSet m = new KSet<>(); - for (File i : getFolders()) { - for (File j : i.listFiles()) { - if (j.isFile() && j.getName().endsWith(".json")) { - m.add(j.getName().replaceAll("\\Q.json\\E", "")); - } else if (j.isDirectory()) { - for (File k : j.listFiles()) { - if (k.isFile() && k.getName().endsWith(".json")) { - m.add(j.getName() + "/" + k.getName().replaceAll("\\Q.json\\E", "")); - } - } - } + for(File i : getFolders()) + { + for(File j : matchAllFiles(i, (f) -> f.getName().endsWith(".json"))) + { + m.add(i.toURI().relativize(j.toURI()).getPath().replaceAll("\\Q.json\\E", "")); } }