Add game log file writing, debug modloader launch
This commit is contained in:
+4
@@ -46,6 +46,8 @@ public class LaunchService {
|
||||
return ApiResponse.error("Сборка не найдена: " + instanceName);
|
||||
}
|
||||
|
||||
JFXLauncher.initGameLog(instance.getPath());
|
||||
|
||||
LaunchCommandBuilder builder = new LaunchCommandBuilder(instance);
|
||||
LaunchOptions options = new LaunchOptions();
|
||||
|
||||
@@ -55,6 +57,8 @@ public class LaunchService {
|
||||
options.setUuid(AuthManager.getUuid());
|
||||
|
||||
List<String> command = builder.build(options);
|
||||
System.out.println("[LAUNCH] Generated command for " + instanceName + ":");
|
||||
command.forEach(arg -> System.out.println(" " + arg));
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
processBuilder.directory(instance.getPath().toFile());
|
||||
|
||||
@@ -19,6 +19,9 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -34,14 +37,33 @@ public class JFXLauncher extends Application {
|
||||
private HttpServer server;
|
||||
private StringBuilder logBuffer = new StringBuilder();
|
||||
private static StringBuilder gameLogBuffer = new StringBuilder();
|
||||
private static Path gameLogFile;
|
||||
private Stage mainStage;
|
||||
|
||||
public static void appendGameLog(String log) {
|
||||
synchronized (gameLogBuffer) {
|
||||
gameLogBuffer.append(log).append("\n");
|
||||
|
||||
if (gameLogFile != null) {
|
||||
try {
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
|
||||
Files.writeString(gameLogFile, "[" + timestamp + "] " + log + "\n",
|
||||
StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initGameLog(Path instanceDir) {
|
||||
try {
|
||||
Path logsDir = instanceDir.resolve("logs");
|
||||
Files.createDirectories(logsDir);
|
||||
gameLogFile = logsDir.resolve("game.log");
|
||||
Files.writeString(gameLogFile, "=== Game Log " + LocalDateTime.now() + " ===\n",
|
||||
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public static String getGameLogs() {
|
||||
synchronized (gameLogBuffer) {
|
||||
return gameLogBuffer.toString();
|
||||
|
||||
Reference in New Issue
Block a user