Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ModpackFileSelectionPage(WizardController controller, Profile profile, St
this.adviser = adviser;

JFXTreeView<String> treeView = new JFXTreeView<>();
rootNode = getTreeItem(profile.getRepository().getRunDirectory(version), "minecraft");
rootNode = getTreeItem(profile.getRepository().getRunDirectory(version), "minecraft", 0);
treeView.setRoot(rootNode);
treeView.setSelectionModel(new NoneMultipleSelectionModel<>());
onEscPressed(treeView, () -> controller.onPrev(true));
Expand All @@ -86,7 +86,7 @@ public ModpackFileSelectionPage(WizardController controller, Profile profile, St
this.setBottom(nextPane);
}

private CheckBoxTreeItem<String> getTreeItem(Path file, String basePath) {
private CheckBoxTreeItem<String> getTreeItem(Path file, String basePath, int level) {
if (Files.notExists(file))
return null;

Expand All @@ -110,20 +110,26 @@ private CheckBoxTreeItem<String> getTreeItem(Path file, String basePath) {
state = ModAdviser.ModSuggestion.HIDDEN;
}

if (isDirectory && fileName.equals(version + "-natives")) // Ignore <version>-natives
state = ModAdviser.ModSuggestion.HIDDEN;
if (isDirectory) {
if (fileName.equals(version + "-natives")) { // Ignore <version>-natives
state = ModAdviser.ModSuggestion.HIDDEN;
}
if (level == 1 && fileName.startsWith("natives-")) { // Ignore natives-os-arch
state = ModAdviser.ModSuggestion.HIDDEN;
}
}
if (state == ModAdviser.ModSuggestion.HIDDEN)
return null;
}

CheckBoxTreeItem<String> node = new CheckBoxTreeItem<>(StringUtils.substringAfterLast(basePath, "/"));
CheckBoxTreeItem<String> node = new CheckBoxTreeItem<>("");
Comment thread
ToobLac marked this conversation as resolved.
Outdated
if (state == ModAdviser.ModSuggestion.SUGGESTED)
node.setSelected(true);

if (isDirectory) {
try (var stream = Files.list(file)) {
stream.forEach(it -> {
CheckBoxTreeItem<String> subNode = getTreeItem(it, basePath + "/" + FileUtils.getName(it));
stream.sorted(FileUtils.dirFirstComparator).forEach(it -> {
CheckBoxTreeItem<String> subNode = getTreeItem(it, basePath + "/" + FileUtils.getName(it), level + 1);
if (subNode != null) {
node.setSelected(subNode.isSelected() || node.isSelected());
if (!subNode.isSelected()) {
Expand All @@ -150,6 +156,11 @@ private CheckBoxTreeItem<String> getTreeItem(Path file, String basePath) {
checkBox.indeterminateProperty().bindBidirectional(node.indeterminateProperty());
graphic.getChildren().add(checkBox);

{
Label text = new Label(level == 0 ? version : StringUtils.substringAfter(basePath, '/'));
Comment thread
ToobLac marked this conversation as resolved.
Outdated
text.setMouseTransparent(true);
graphic.getChildren().add(text);
}
if (TRANSLATION.containsKey(basePath)) {
Label comment = new Label(TRANSLATION.get(basePath));
comment.setStyle("-fx-text-fill: -monet-on-surface-variant;");
Expand Down
6 changes: 3 additions & 3 deletions HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModAdviser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.jackhuang.hmcl.util.Lang;

import java.io.File;
import java.util.List;

/**
Expand Down Expand Up @@ -74,7 +73,7 @@ enum ModSuggestion {
"optionsof.txt" /* OptiFine */,
"journeymap" /* JourneyMap */,
"optionsshaders.txt",
"mods" + File.separator + "VoxelMods");
"mods/VoxelMods");

static ModAdviser.ModSuggestion suggestMod(String fileName, boolean isDirectory) {
if (match(MODPACK_BLACK_LIST, fileName, isDirectory))
Expand All @@ -85,10 +84,11 @@ static ModAdviser.ModSuggestion suggestMod(String fileName, boolean isDirectory)
return ModAdviser.ModSuggestion.SUGGESTED;
}

/// @param fileName "fileName/" for directories and "fileName" for files, regardless of the operating system
static boolean match(List<String> l, String fileName, boolean isDirectory) {
for (String s : l)
if (isDirectory) {
if (fileName.startsWith(s + File.separator))
if (fileName.startsWith(s + '/'))
return true;
} else {
if (s.startsWith("regex:")) {
Expand Down
15 changes: 14 additions & 1 deletion HMCLCore/src/main/java/org/jackhuang/hmcl/mod/Modpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,23 @@ public Modpack setManifest(ModpackManifest manifest) {

public abstract Task<?> getInstallTask(DefaultDependencyManager dependencyManager, Path zipFile, String name, String iconUrl);

private static boolean match(List<String> l, String fileName) {
for (String s : l) {
if (s.startsWith("regex:")) {
if (fileName.matches(s.substring("regex:".length())))
return true;
} else {
if (fileName.equals(s))
return true;
}
}
return false;
}
Comment thread
ToobLac marked this conversation as resolved.
Outdated
Comment thread
ToobLac marked this conversation as resolved.
Outdated

public static boolean acceptFile(String path, List<String> blackList, List<String> whiteList) {
if (path.isEmpty())
return true;
if (ModAdviser.match(blackList, path, false))
if (match(blackList, path))
return false;
if (whiteList == null || whiteList.isEmpty())
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public final class FileUtils {
private FileUtils() {
}

public static final Comparator<Path> dirFirstComparator = (p1, p2) -> {
if (p1 == null) return p2 == null ? 0 : -1;
if (p2 == null) return 1;
if (!p1.getParent().equals(p2.getParent())) return p1.compareTo(p2);
if (Files.isDirectory(p1) == Files.isDirectory(p2)) return p1.compareTo(p2);
return Files.isDirectory(p1) ? -1 : 1;
Comment thread
ToobLac marked this conversation as resolved.
Outdated
};

public static @Nullable Path toPath(@Nullable File file) {
try {
return file != null ? file.toPath() : null;
Expand Down