Support path containing unicode characters on Mac OS (#1661)

This commit is contained in:
Glavo 2022-08-28 16:54:22 +08:00 committed by GitHub
parent c21671e86b
commit a4164a86af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,17 +112,28 @@ public class DefaultLauncher extends Launcher {
res.addAllWithoutParsing(options.getJavaArguments()); res.addAllWithoutParsing(options.getJavaArguments());
Charset encoding = OperatingSystem.NATIVE_CHARSET; Charset encoding = StandardCharsets.UTF_8;
if (options.getJava().getParsedVersion() < JavaVersion.JAVA_8) {
// After Java 17, file.encoding does not affect console encoding
if (options.getJava().getParsedVersion() <= JavaVersion.JAVA_17) {
try { try {
String fileEncoding = res.addDefault("-Dfile.encoding=", encoding.name()); String fileEncoding = res.addDefault("-Dfile.encoding=", encoding.name());
if (fileEncoding != null) if (fileEncoding != null)
encoding = Charset.forName(fileEncoding.substring("-Dfile.encoding=".length())); encoding = Charset.forName(fileEncoding.substring("-Dfile.encoding=".length()));
} catch (Throwable ex) { } catch (Throwable ex) {
encoding = OperatingSystem.NATIVE_CHARSET;
LOG.log(Level.WARNING, "Bad file encoding", ex); LOG.log(Level.WARNING, "Bad file encoding", ex);
} }
} else {
res.addDefault("-Dfile.encoding=", "UTF-8");
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);
}
res.addDefault("-Dsun.stderr.encoding=", encoding.name());
} }
// JVM Args // JVM Args
@ -237,7 +248,7 @@ public class DefaultLauncher extends Launcher {
// Here is a workaround for this issue: https://github.com/huanghongxun/HMCL/issues/1141. // Here is a workaround for this issue: https://github.com/huanghongxun/HMCL/issues/1141.
String nativeFolderPath = nativeFolder.getAbsolutePath(); String nativeFolderPath = nativeFolder.getAbsolutePath();
Path tempNativeFolder = null; Path tempNativeFolder = null;
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX if ((OperatingSystem.CURRENT_OS == OperatingSystem.LINUX || OperatingSystem.CURRENT_OS == OperatingSystem.OSX)
&& !StringUtils.isASCII(nativeFolderPath)) { && !StringUtils.isASCII(nativeFolderPath)) {
tempNativeFolder = Paths.get("/", "tmp", "hmcl-natives-" + UUID.randomUUID()); tempNativeFolder = Paths.get("/", "tmp", "hmcl-natives-" + UUID.randomUUID());
nativeFolderPath = tempNativeFolder + File.pathSeparator + nativeFolderPath; nativeFolderPath = tempNativeFolder + File.pathSeparator + nativeFolderPath;