mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2024-11-27 06:10:08 +08:00
* Support #2969: 启动前日志列出mods目录的jar文件 * Support #2969: 启动前日志列出mods目录jar文件 * Support #2969: 启动前日志中使用字符画列出mods目录模组文件 * Support #2969: 启动前日志中使用字符画列出mods目录模组文件 * Support #2969: 启动前日志中使用字符画列出mods目录模组文件 * Support #2969: 日志列出mods目录时不再过滤文件后缀 * Support #2969: 启动时日志列出mods目录(代码优化) * Support #2969: 启动时日志列出mods目录(不再列出Zip内容) * Support #2969 * Fix: checkstyle --------- Co-authored-by: YELANDAOKONG <yelandaokong@yldk.xyz>
This commit is contained in:
parent
5591d92e25
commit
9edfe29659
@ -36,10 +36,14 @@ import org.jackhuang.hmcl.mod.ModpackProvider;
|
|||||||
import org.jackhuang.hmcl.setting.*;
|
import org.jackhuang.hmcl.setting.*;
|
||||||
import org.jackhuang.hmcl.task.*;
|
import org.jackhuang.hmcl.task.*;
|
||||||
import org.jackhuang.hmcl.ui.*;
|
import org.jackhuang.hmcl.ui.*;
|
||||||
import org.jackhuang.hmcl.ui.construct.*;
|
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
|
||||||
|
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
|
||||||
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
|
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
|
||||||
|
import org.jackhuang.hmcl.ui.construct.PromptDialogPane;
|
||||||
|
import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
|
||||||
import org.jackhuang.hmcl.util.*;
|
import org.jackhuang.hmcl.util.*;
|
||||||
import org.jackhuang.hmcl.util.i18n.I18n;
|
import org.jackhuang.hmcl.util.i18n.I18n;
|
||||||
|
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||||
import org.jackhuang.hmcl.util.io.ResponseCodeException;
|
import org.jackhuang.hmcl.util.io.ResponseCodeException;
|
||||||
import org.jackhuang.hmcl.util.platform.*;
|
import org.jackhuang.hmcl.util.platform.*;
|
||||||
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
|
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
|
||||||
@ -60,9 +64,10 @@ import static javafx.application.Platform.runLater;
|
|||||||
import static javafx.application.Platform.setImplicitExit;
|
import static javafx.application.Platform.setImplicitExit;
|
||||||
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
|
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
|
||||||
import static org.jackhuang.hmcl.util.Lang.resolveException;
|
import static org.jackhuang.hmcl.util.Lang.resolveException;
|
||||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
|
||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
import static org.jackhuang.hmcl.util.platform.Platform.*;
|
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||||
|
import static org.jackhuang.hmcl.util.platform.Platform.SYSTEM_PLATFORM;
|
||||||
|
import static org.jackhuang.hmcl.util.platform.Platform.isCompatibleWithX86Java;
|
||||||
|
|
||||||
public final class LauncherHelper {
|
public final class LauncherHelper {
|
||||||
|
|
||||||
@ -178,6 +183,9 @@ public final class LauncherHelper {
|
|||||||
.thenComposeAsync(() -> logIn(account).withStage("launch.state.logging_in"))
|
.thenComposeAsync(() -> logIn(account).withStage("launch.state.logging_in"))
|
||||||
.thenComposeAsync(authInfo -> Task.supplyAsync(() -> {
|
.thenComposeAsync(authInfo -> Task.supplyAsync(() -> {
|
||||||
LaunchOptions launchOptions = repository.getLaunchOptions(selectedVersion, javaVersionRef.get(), profile.getGameDir(), javaAgents, scriptFile != null);
|
LaunchOptions launchOptions = repository.getLaunchOptions(selectedVersion, javaVersionRef.get(), profile.getGameDir(), javaAgents, scriptFile != null);
|
||||||
|
|
||||||
|
LOG.info("Here's the structure of game mod directory:\n" + FileUtils.printFileStructure(repository.getModManager(selectedVersion).getModsDirectory(), 10));
|
||||||
|
|
||||||
return new HMCLGameLauncher(
|
return new HMCLGameLauncher(
|
||||||
repository,
|
repository,
|
||||||
version.get(),
|
version.get(),
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
package org.jackhuang.hmcl.util.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
|
import java.nio.file.FileVisitor;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
|
final class DirectoryStructurePrinter {
|
||||||
|
private DirectoryStructurePrinter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String list(Path path, int maxDepth) throws IOException {
|
||||||
|
StringBuilder output = new StringBuilder(128);
|
||||||
|
list(path, maxDepth, output);
|
||||||
|
output.setLength(output.length() - 1);
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void list(Path path, int maxDepth, StringBuilder output) throws IOException {
|
||||||
|
output.append("Filesystem structure of: ").append(path).append('\n');
|
||||||
|
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
pushMessage(output, "nonexistent path", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Files.isRegularFile(path)) {
|
||||||
|
pushMessage(output, "regular file path", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Files.isDirectory(path)) {
|
||||||
|
Files.walkFileTree(path, new FileVisitor<Path>() {
|
||||||
|
private boolean isFolderEmpty;
|
||||||
|
|
||||||
|
private int depth = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||||
|
isFolderEmpty = true;
|
||||||
|
|
||||||
|
pushFile(output, dir, depth);
|
||||||
|
if (depth == maxDepth) {
|
||||||
|
pushMessage(output, "too deep", depth);
|
||||||
|
return FileVisitResult.SKIP_SUBTREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
depth++;
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||||
|
isFolderEmpty = false;
|
||||||
|
|
||||||
|
pushFile(output, file, depth);
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFileFailed(Path file, IOException exc) {
|
||||||
|
visitFile(file, null);
|
||||||
|
|
||||||
|
pushMessage(output, exc.toString(), depth);
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
|
||||||
|
if (isFolderEmpty) {
|
||||||
|
pushMessage(output, "empty directory", depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
depth--;
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pushMessage(output, "unknown file type", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void pushFile(StringBuilder output, Path file, int depth) {
|
||||||
|
output.append("|");
|
||||||
|
for (int i = 1; i < depth; i++) {
|
||||||
|
output.append(" |");
|
||||||
|
}
|
||||||
|
output.append("-> ").append(FileUtils.getName(file)).append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void pushMessage(StringBuilder output, String message, int depth) {
|
||||||
|
output.append("| ");
|
||||||
|
for (int i = 1; i < depth; i++) {
|
||||||
|
output.append(" | ");
|
||||||
|
}
|
||||||
|
output.append('<').append(message).append(">\n");
|
||||||
|
}
|
||||||
|
}
|
@ -30,11 +30,7 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
@ -591,4 +587,8 @@ public final class FileUtils {
|
|||||||
|
|
||||||
Files.move(tmpFile, file, StandardCopyOption.REPLACE_EXISTING);
|
Files.move(tmpFile, file, StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String printFileStructure(Path path, int maxDepth) throws IOException {
|
||||||
|
return DirectoryStructurePrinter.list(path, maxDepth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user