feat: crash report analyzer test.
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
package org.jackhuang.hmcl.ui;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
@@ -30,6 +32,7 @@ import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.jackhuang.hmcl.game.CrashReportAnalyzer;
|
||||
import org.jackhuang.hmcl.game.DefaultGameRepository;
|
||||
import org.jackhuang.hmcl.game.LaunchOptions;
|
||||
import org.jackhuang.hmcl.game.LogExporter;
|
||||
@@ -49,9 +52,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -67,6 +68,8 @@ public class GameCrashWindow extends Stage {
|
||||
private final StringProperty java = new SimpleStringProperty();
|
||||
private final StringProperty os = new SimpleStringProperty(System.getProperty("os.name"));
|
||||
private final StringProperty arch = new SimpleStringProperty(Architecture.SYSTEM_ARCHITECTURE);
|
||||
private final StringProperty reason = new SimpleStringProperty(i18n("game.crash.reason.unknown"));
|
||||
private final BooleanProperty loading = new SimpleBooleanProperty();
|
||||
|
||||
private final ManagedProcess managedProcess;
|
||||
private final DefaultGameRepository repository;
|
||||
@@ -92,6 +95,40 @@ public class GameCrashWindow extends Stage {
|
||||
version.set(launchOptions.getVersionName());
|
||||
memory.set(Optional.ofNullable(launchOptions.getMaxMemory()).map(i -> i + " MB").orElse("-"));
|
||||
java.set(launchOptions.getJava().getVersion());
|
||||
|
||||
analyzeCrashReport();
|
||||
}
|
||||
|
||||
private void analyzeCrashReport() {
|
||||
loading.set(true);
|
||||
CompletableFuture.supplyAsync(() -> {
|
||||
return CrashReportAnalyzer.anaylze(logs);
|
||||
}).whenCompleteAsync((results, exception) -> {
|
||||
loading.set(false);
|
||||
|
||||
if (exception != null) {
|
||||
LOG.log(Level.WARNING, "Failed to analyze crash report", exception);
|
||||
reason.set(i18n("game.crash.reason.unknown"));
|
||||
} else {
|
||||
StringBuilder reasonText = new StringBuilder();
|
||||
for (CrashReportAnalyzer.Result result : results) {
|
||||
switch (result.getRule()) {
|
||||
case TOO_OLD_JAVA:
|
||||
reasonText.append(i18n("game.crash.reason.too_old_java",
|
||||
CrashReportAnalyzer.getJavaVersionFromMajorVersion(Integer.parseInt(result.getMatcher().group("expected")))))
|
||||
.append("\n");
|
||||
break;
|
||||
default:
|
||||
reasonText.append(i18n("game.crash.reason." + result.getRule().name().toLowerCase(Locale.ROOT),
|
||||
Arrays.stream(result.getRule().getGroupNames()).map(groupName -> result.getMatcher().group("groupName"))
|
||||
.toArray()))
|
||||
.append("\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
reason.set(reasonText.toString());
|
||||
}
|
||||
}, Schedulers.javafx());
|
||||
}
|
||||
|
||||
private void showLogWindow() {
|
||||
@@ -202,7 +239,7 @@ public class GameCrashWindow extends Stage {
|
||||
TwoLineListItem reason = new TwoLineListItem();
|
||||
reason.getStyleClass().setAll("two-line-item-second-large");
|
||||
reason.setTitle(i18n("game.crash.reason"));
|
||||
reason.setSubtitle(i18n("game.crash.reason.unknown"));
|
||||
reason.subtitleProperty().bind(GameCrashWindow.this.reason);
|
||||
|
||||
gameDirPane.setPadding(new Insets(8));
|
||||
VBox.setVgrow(gameDirPane, Priority.ALWAYS);
|
||||
|
||||
@@ -311,6 +311,7 @@ folder.screenshots=Screenshots
|
||||
game=Game
|
||||
game.crash.info=Game Status
|
||||
game.crash.reason=Crash Analyzer
|
||||
game.crash.reason.analyzing=Analyzing...
|
||||
game.crash.reason.duplciated_mod=Game cannot run because of duplicate mods: %s.\n%s\nEach Mod can only be installed one, please delete the duplicate mod and try again.
|
||||
game.crash.reason.file_changed=Game cannot run because file verification failed.\nIf you have modified the Minecraft primary jar, you need roll back the changes, or re-download the game.
|
||||
game.crash.reason.gl_operation_failure=Game crashed due to some mods, shader packs, texture packs.\nPlease disable the mods/shader packs/texture packs you are using and try again.
|
||||
|
||||
@@ -311,6 +311,7 @@ folder.screenshots=截圖資料夾
|
||||
game=遊戲
|
||||
game.crash.info=遊戲訊息
|
||||
game.crash.reason=崩潰原因
|
||||
game.crash.reason.analyzing=分析中...
|
||||
game.crash.reason.duplciated_mod=當前遊戲因為 Mod 重複安裝,無法繼續運行。\n%s\n每種 Mod 只能安裝一個,請你刪除多餘的 Mod 再試。
|
||||
game.crash.reason.file_changed=當前遊戲因為檔案校驗失敗,無法繼續運行。\n如果你手動修改了 Minecraft.jar 檔案,你需要回退修改,或者重新下載遊戲。
|
||||
game.crash.reason.gl_operation_failure=當前遊戲因為你使用的某些 Mod、光影包、材質包,無法繼續運行。\n請先嘗試禁用你所使用的Mod/光影包/材質包再試。
|
||||
|
||||
@@ -311,6 +311,7 @@ folder.screenshots=截图文件夹
|
||||
game=游戏
|
||||
game.crash.info=游戏信息
|
||||
game.crash.reason=崩溃原因
|
||||
game.crash.reason.analyzing=分析中...
|
||||
game.crash.reason.duplciated_mod=当前游戏因为 Mod 重复安装,无法继续运行。\n%s\n每种 Mod 只能安装一个,请你删除多余的 Mod 再试。
|
||||
game.crash.reason.file_changed=当前游戏因为文件校验失败,无法继续运行。\n如果你手动修改了 Minecraft.jar 文件,你需要回退修改,或者重新下载游戏。
|
||||
game.crash.reason.gl_operation_failure=当前游戏因为你使用的某些 Mod、光影包、材质包,无法继续运行。\n请先尝试禁用你所使用的Mod/光影包/材质包再试。
|
||||
@@ -326,6 +327,7 @@ game.crash.reason.openj9=当前游戏无法运行在 OpenJ9 虚拟机上,请
|
||||
game.crash.reason.out_of_memory=当前游戏因为内存不足,无法继续运行。\n这可能是内存分配太小,或者 Mod 数量过多导致的。\n你可以在游戏设置中调大游戏内存分配值以允许游戏在更大的内存下运行。\n如果仍然出现该错误,你可能需要换一台更好的电脑。
|
||||
game.crash.reason.too_old_java=当前游戏因为 Java 虚拟机版本过低,无法继续运行。\n你需要在游戏设置中更换更新版本的 Java 虚拟机,并重新启动游戏。如果没有下载安装,你可以在网上自行下载。
|
||||
game.crash.reason.unknown=原因未知,请点击日志按钮查看详细信息。
|
||||
game.crash.reason.unsupported_class_version=当前游戏因为 Java
|
||||
game.crash.title=游戏意外退出
|
||||
game.directory=游戏路径
|
||||
game.version=游戏版本
|
||||
|
||||
Reference in New Issue
Block a user