fix: добавить UTF-8 параметры при запуске процессов и исправить обработку стрелок в ArrowMenu

This commit is contained in:
SashegDev
2026-05-10 23:53:45 +00:00
parent a765d064c4
commit d956bce921
2 changed files with 66 additions and 17 deletions
@@ -3,6 +3,7 @@ package me.sashegdev.zernmc.launcher;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -143,16 +144,38 @@ public class Bootstrap {
log("Java: " + javaBin);
log("JAR: " + jarPath);
ProcessBuilder pb = new ProcessBuilder(
javaBin.toAbsolutePath().toString(),
"-jar",
jarPath.toAbsolutePath().toString(),
"--jfx"
);
List<String> cmd = new ArrayList<>();
cmd.add(javaBin.toAbsolutePath().toString());
cmd.add("-Dfile.encoding=UTF-8");
cmd.add("-Dsun.stdout.encoding=UTF-8");
cmd.add("-Dsun.stderr.encoding=UTF-8");
cmd.add("-jar");
cmd.add(jarPath.toAbsolutePath().toString());
cmd.add("--jfx");
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.directory(baseDir.toFile());
pb.inheritIO();
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
pb.environment().put("JAVA_TOOL_OPTIONS", "-Dfile.encoding=UTF-8");
}
pb.redirectErrorStream(true);
Process p = pb.start();
Thread outputThread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception ignored) {}
});
outputThread.start();
int code = p.waitFor();
try { outputThread.interrupt(); } catch (Exception ignored) {}
log("Завершено с кодом: " + code);
System.exit(code);
}
@@ -165,16 +188,38 @@ public class Bootstrap {
log("Java: " + javaBin);
log("JAR: " + jarPath);
ProcessBuilder pb = new ProcessBuilder(
javaBin.toAbsolutePath().toString(),
"-jar",
jarPath.toAbsolutePath().toString(),
"--cli"
);
List<String> cmd = new ArrayList<>();
cmd.add(javaBin.toAbsolutePath().toString());
cmd.add("-Dfile.encoding=UTF-8");
cmd.add("-Dsun.stdout.encoding=UTF-8");
cmd.add("-Dsun.stderr.encoding=UTF-8");
cmd.add("-jar");
cmd.add(jarPath.toAbsolutePath().toString());
cmd.add("--cli");
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.directory(baseDir.toFile());
pb.inheritIO();
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
pb.environment().put("JAVA_TOOL_OPTIONS", "-Dfile.encoding=UTF-8");
}
pb.redirectErrorStream(true);
Process p = pb.start();
Thread outputThread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception ignored) {}
});
outputThread.start();
int code = p.waitFor();
try { outputThread.interrupt(); } catch (Exception ignored) {}
log("Завершено с кодом: " + code);
System.exit(code);
}
@@ -21,9 +21,11 @@ public class ArrowMenu {
public ArrowMenu(String title, List<String> options) throws IOException {
this.title = title;
this.options = options;
System.setProperty("jline.terminal", "unsupported");
this.terminal = TerminalBuilder.builder()
.system(true)
.jna(true)
.jna(false)
.jansi(true)
.encoding(StandardCharsets.UTF_8)
.build();
}
@@ -78,17 +80,19 @@ public class ArrowMenu {
}
private int nonBlockingRead() throws IOException {
while (true) {
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < 200) {
int available = terminal.reader().available();
if (available > 0) {
return terminal.reader().read();
}
try {
Thread.sleep(10);
Thread.sleep(5);
} catch (InterruptedException e) {
return -1;
}
}
return -1;
}
private void printPagedMenu() {