Skip to content

Commit

Permalink
在Windows上自动识别语言
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperIceCN committed Mar 22, 2023
1 parent d7e3e59 commit 1f0a8bd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.powernukkitx</groupId>
<artifactId>PNX-CLI</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/powernukkitx/cli/share/CLIConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public interface CLIConstant {
String version = "0.1.1";
String version = "0.1.2";
List<String> authors = List.of("超神的冰凉");
File userDir = new File(System.getProperty("user.dir"));
File programDir = new File(OSUtils.getProgramDir());
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/cn/powernukkitx/cli/util/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,23 @@ public static boolean setWindowsEnv(EnvEntry... entries) throws IOException, Int

public static Locale getWindowsLocale() {
try {
var cmd = """
reg query "hklm\\system\\controlset001\\control\\nls\\language" /v Installlanguage
""";
var cmdFile = File.createTempFile("pnx-cli-locate", ".cmd");
cmdFile.deleteOnExit();
//noinspection ResultOfMethodCallIgnored
cmdFile.getParentFile().mkdirs();
if (!cmdFile.exists()) {
//noinspection ResultOfMethodCallIgnored
cmdFile.createNewFile();
try (var writer = new FileWriter(cmdFile)) {
writer.write(cmd);
}
}
var process = new ProcessBuilder().command(cmdFile.getAbsolutePath())
var process = new ProcessBuilder().command("C:\\Windows\\System32\\reg.exe", "query",
"\"hklm\\system\\controlset001\\control\\nls\\language\"", "/v", "Installlanguage")
.redirectErrorStream(true).start();
process.waitFor(2500, TimeUnit.MILLISECONDS);
try(var reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
var s = "";
while ((s = reader.readLine()) != null) {
if (s.contains("0804")) {
return Locale.forLanguageTag("zh-cn");
} else if (s.contains("0409 ")) {
} else if (s.contains("0409")) {
return Locale.forLanguageTag("en-us");
}
}
}
} catch (IOException | InterruptedException e) {
//ignore
e.printStackTrace();
}
return null;
}
Expand Down

0 comments on commit 1f0a8bd

Please sign in to comment.