Skip to content

Commit

Permalink
Fix cannot limit recursion level & some optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
ri-fumo committed Dec 15, 2024
1 parent bbcf928 commit cea4e8b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions HMCL/src/main/java/org/jackhuang/hmcl/java/JavaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,14 @@ public void execute() throws Exception {
}

private List<JavaRuntime> searchJava() throws IOException, InterruptedException {
final int maxDepth = 2;
final int maxDepth = 3;

Queue<File> fileQueue = new ArrayDeque<>(64);
ArrayList<JavaRuntime> binaryList = new ArrayList<>();
final String relative = "bin" + File.separator + OperatingSystem.CURRENT_OS.getJavaExecutable();
File[] subDirs = directory.listFiles(File::isDirectory);
if(subDirs == null) return binaryList;
fileQueue.addAll(Arrays.asList(subDirs));
if(subDirs == null) return Collections.emptyList();
List<JavaRuntime> binaryList = new ArrayList<>();
Queue<File> fileQueue = new LinkedList<>(Arrays.asList(subDirs));
fileQueue.add(directory);
final String relative = "bin" + File.separator + OperatingSystem.CURRENT_OS.getJavaExecutable();
int depth = 0;
while (depth < maxDepth) {
if(isCancelled())
Expand All @@ -218,11 +217,13 @@ private List<JavaRuntime> searchJava() throws IOException, InterruptedException
binaryList.add(JavaManager.getJava(binary.toPath()));
continue;
}
subDirs = dir.listFiles(File::isDirectory);
if (subDirs != null)
fileQueue.addAll(Arrays.asList(subDirs));
if(depth < maxDepth - 1) {
subDirs = dir.listFiles(File::isDirectory);
if (subDirs != null)
fileQueue.addAll(Arrays.asList(subDirs));
}
}
return binaryList;
return Collections.unmodifiableList(binaryList);
}
}

Expand Down

0 comments on commit cea4e8b

Please sign in to comment.