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 cd9fe39
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions HMCL/src/main/java/org/jackhuang/hmcl/java/JavaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,16 @@ 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())
return Collections.emptyList();
if(fileQueue.isEmpty()) break;
while(!fileQueue.isEmpty()) {
final File dir = fileQueue.poll();
if (dir == directory) {
depth++;
Expand All @@ -218,11 +214,15 @@ 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));
}
if(isCancelled())
return Collections.emptyList();
}
return binaryList;
return Collections.unmodifiableList(binaryList);
}
}

Expand Down

0 comments on commit cd9fe39

Please sign in to comment.