fix: добавить UTF-8 параметры при запуске процессов и исправить обработку стрелок в ArrowMenu
This commit is contained in:
@@ -3,6 +3,7 @@ package me.sashegdev.zernmc.launcher;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@@ -143,16 +144,38 @@ public class Bootstrap {
|
|||||||
log("Java: " + javaBin);
|
log("Java: " + javaBin);
|
||||||
log("JAR: " + jarPath);
|
log("JAR: " + jarPath);
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(
|
List<String> cmd = new ArrayList<>();
|
||||||
javaBin.toAbsolutePath().toString(),
|
cmd.add(javaBin.toAbsolutePath().toString());
|
||||||
"-jar",
|
cmd.add("-Dfile.encoding=UTF-8");
|
||||||
jarPath.toAbsolutePath().toString(),
|
cmd.add("-Dsun.stdout.encoding=UTF-8");
|
||||||
"--jfx"
|
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.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();
|
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();
|
int code = p.waitFor();
|
||||||
|
try { outputThread.interrupt(); } catch (Exception ignored) {}
|
||||||
log("Завершено с кодом: " + code);
|
log("Завершено с кодом: " + code);
|
||||||
System.exit(code);
|
System.exit(code);
|
||||||
}
|
}
|
||||||
@@ -165,16 +188,38 @@ public class Bootstrap {
|
|||||||
log("Java: " + javaBin);
|
log("Java: " + javaBin);
|
||||||
log("JAR: " + jarPath);
|
log("JAR: " + jarPath);
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(
|
List<String> cmd = new ArrayList<>();
|
||||||
javaBin.toAbsolutePath().toString(),
|
cmd.add(javaBin.toAbsolutePath().toString());
|
||||||
"-jar",
|
cmd.add("-Dfile.encoding=UTF-8");
|
||||||
jarPath.toAbsolutePath().toString(),
|
cmd.add("-Dsun.stdout.encoding=UTF-8");
|
||||||
"--cli"
|
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.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();
|
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();
|
int code = p.waitFor();
|
||||||
|
try { outputThread.interrupt(); } catch (Exception ignored) {}
|
||||||
log("Завершено с кодом: " + code);
|
log("Завершено с кодом: " + code);
|
||||||
System.exit(code);
|
System.exit(code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ public class ArrowMenu {
|
|||||||
public ArrowMenu(String title, List<String> options) throws IOException {
|
public ArrowMenu(String title, List<String> options) throws IOException {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
System.setProperty("jline.terminal", "unsupported");
|
||||||
this.terminal = TerminalBuilder.builder()
|
this.terminal = TerminalBuilder.builder()
|
||||||
.system(true)
|
.system(true)
|
||||||
.jna(true)
|
.jna(false)
|
||||||
|
.jansi(true)
|
||||||
.encoding(StandardCharsets.UTF_8)
|
.encoding(StandardCharsets.UTF_8)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -78,17 +80,19 @@ public class ArrowMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int nonBlockingRead() throws IOException {
|
private int nonBlockingRead() throws IOException {
|
||||||
while (true) {
|
long startTime = System.currentTimeMillis();
|
||||||
|
while (System.currentTimeMillis() - startTime < 200) {
|
||||||
int available = terminal.reader().available();
|
int available = terminal.reader().available();
|
||||||
if (available > 0) {
|
if (available > 0) {
|
||||||
return terminal.reader().read();
|
return terminal.reader().read();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10);
|
Thread.sleep(5);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printPagedMenu() {
|
private void printPagedMenu() {
|
||||||
|
|||||||
Reference in New Issue
Block a user