修复中文路径下启动 <= 1.12.2 的版本没有声音的问题 (#1754)

* Use native encoding by default

* Fix the problem that LWJGL fails to load OpenAL under Java 18
This commit is contained in:
Glavo 2022-10-08 17:10:27 +08:00 committed by GitHub
parent 2649e79d47
commit 43986676d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,24 +108,26 @@ public class DefaultLauncher extends Launcher {
res.addAllWithoutParsing(options.getJavaArguments());
Charset encoding = StandardCharsets.UTF_8;
Charset encoding = OperatingSystem.NATIVE_CHARSET;
if (options.getJava().getParsedVersion() < JavaVersion.JAVA_8) {
try {
String fileEncoding = res.addDefault("-Dfile.encoding=", encoding.name());
if (fileEncoding != null)
encoding = Charset.forName(fileEncoding.substring("-Dfile.encoding=".length()));
} catch (Throwable ex) {
encoding = OperatingSystem.NATIVE_CHARSET;
LOG.log(Level.WARNING, "Bad file encoding", ex);
}
} else {
res.addDefault("-Dfile.encoding=", "UTF-8");
if (options.getJava().getParsedVersion() > JavaVersion.JAVA_17
&& VersionNumber.VERSION_COMPARATOR.compare(repository.getGameVersion(version).orElse("1.13"), "1.13") < 0) {
res.addDefault("-Dfile.encoding=", "COMPAT");
}
try {
String stdoutEncoding = res.addDefault("-Dsun.stdout.encoding=", encoding.name());
if (stdoutEncoding != null)
encoding = Charset.forName(stdoutEncoding.substring("-Dsun.stdout.encoding=".length()));
} catch (Throwable ex) {
encoding = OperatingSystem.NATIVE_CHARSET;
LOG.log(Level.WARNING, "Bad stdout encoding", ex);
}