Skip to content
Closed
Changes from all 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
15 changes: 15 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public static void main(String[] args) {
System.getProperties().putIfAbsent("javafx.autoproxy.disable", "true");
System.getProperties().putIfAbsent("http.agent", "HMCL/" + Metadata.VERSION);

// Fucking Windows may force working directory to system32 for unknown reasons.
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
String workingDirectory = System.getProperty("user.dir");
String windowsSystem = "C:\\WINDOWS\\system32";
if (workingDirectory == null || (workingDirectory.length() >= windowsSystem.length() && workingDirectory.substring(0, windowsSystem.length()).equalsIgnoreCase(windowsSystem))) {
Path path = JarUtils.thisJarPath();
if (path != null) {
Path parent = path.getParent();
if (parent != null) {
System.setProperty("user.dir", parent.toAbsolutePath().toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样做真的没问题吗?我觉得会导致大量奇怪的问题。

Copy link
Member Author

@burningtnt burningtnt Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

现版本的 HMCL 会因为无法创建 .hmcl 文件夹而直接拒绝启动

Copy link
Member

@Glavo Glavo Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现版本的 HMCL 会因为无法创建 .hmcl 文件夹而直接拒绝启动

直接拒绝启动也比出现一大堆微妙的问题更好。

这个 PR 非常明显的不能正常工作。比如 Metadata 比你这段代码更早初始化,你设置 user.dir 的时候 Metadata.CURRENT_DIRECTORY 早就初始化完了,很多地方都不会遵循你这里新设置的路径。而且我怀疑有更多位置的代码可能无法遵循这里设置的路径。

}
}
}
}

createHMCLDirectories();
LOG.start(Metadata.HMCL_CURRENT_DIRECTORY.resolve("logs"));

Expand Down