From efd088e014bf1c113f7b3fdf73fb983087ae3f5e Mon Sep 17 00:00:00 2001 From: Glavo Date: Thu, 20 Mar 2025 10:02:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=97=A5=E5=BF=97=E4=B8=AD=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E7=BC=96=E7=A0=81=E4=BF=A1=E6=81=AF=20(#3747)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 在日志中记录 Code Page * update * update --- .../java/org/jackhuang/hmcl/Launcher.java | 5 +++++ .../hmcl/util/platform/OperatingSystem.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java index 5fb654d02..469823189 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java @@ -229,6 +229,11 @@ public final class Launcher extends Application { LOG.info("Processor Identifier: " + System.getenv("PROCESSOR_IDENTIFIER")); } LOG.info("System Architecture: " + Architecture.SYSTEM_ARCH.getDisplayName()); + LOG.info("Native Encoding: " + OperatingSystem.NATIVE_CHARSET); + LOG.info("JNU Encoding: " + System.getProperty("sun.jnu.encoding")); + if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) { + LOG.info("Code Page: " + OperatingSystem.CODE_PAGE); + } LOG.info("Java Architecture: " + Architecture.CURRENT_ARCH.getDisplayName()); LOG.info("Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor")); LOG.info("Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor")); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java index 70a32512e..334500bd1 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java @@ -124,6 +124,8 @@ public enum OperatingSystem { public static final String OS_RELEASE_NAME; public static final String OS_RELEASE_PRETTY_NAME; + public static final int CODE_PAGE; + public static final Pattern INVALID_RESOURCE_CHARACTERS; private static final String[] INVALID_RESOURCE_BASENAMES; private static final String[] INVALID_RESOURCE_FULLNAMES; @@ -184,13 +186,30 @@ public enum OperatingSystem { osName = "Windows 11"; } + int codePage = -1; + try { + Process process = Runtime.getRuntime().exec(new String[]{"chcp.com"}); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), NATIVE_CHARSET))) { + Matcher matcher = Pattern.compile("(?[0-9]+)$") + .matcher(reader.readLine().trim()); + + if (matcher.find()) { + codePage = Integer.parseInt(matcher.group("cp")); + } + } + process.destroy(); + } catch (Throwable ignored) { + } + SYSTEM_NAME = osName; SYSTEM_VERSION = versionNumber; SYSTEM_BUILD_NUMBER = buildNumber; + CODE_PAGE = codePage; } else { SYSTEM_NAME = System.getProperty("os.name"); SYSTEM_VERSION = System.getProperty("os.version"); SYSTEM_BUILD_NUMBER = -1; + CODE_PAGE = -1; } Map osRelease = Collections.emptyMap();