[tools] testbot/SetWinLocale: Add support for setting the code pages to UTF-8.
Francois Gouget
fgouget at codeweavers.com
Thu Jan 6 11:02:25 CST 2022
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
testbot/bin/SetWinLocale | 67 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 64 insertions(+), 3 deletions(-)
diff --git a/testbot/bin/SetWinLocale b/testbot/bin/SetWinLocale
index 3a74406a49..c62d663335 100755
--- a/testbot/bin/SetWinLocale
+++ b/testbot/bin/SetWinLocale
@@ -47,6 +47,7 @@ my $HKCU_USER_PROFILE = "HKCU\\Control Panel\\International\\User Profile";
my $HKCU_DESKTOP = "HKCU\\Control Panel\\Desktop";
my $HKLM_LANGUAGE = "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\Language";
my $HKLM_LOCALE = "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\Locale";
+my $HKLM_CODE_PAGE = "HKLM\\System\\CurrentControlSet\\Control\\Nls\\CodePage";
#
@@ -297,7 +298,7 @@ sub CheckLocale($$)
}
my ($OptHostName, $OptShow, $OptReboot);
-my ($OptDefault, $OptLocale, $OptSystem, $OptMUI, $OptCountry, $OptKeyboard);
+my ($OptDefault, $OptLocale, $OptSystem, $OptMUI, $OptCountry, $OptKeyboard, $OptUTF8);
while (@ARGV)
{
my $Arg = shift @ARGV;
@@ -351,6 +352,10 @@ while (@ARGV)
{
$OptCountry = CheckValue($Arg, $OptCountry);
}
+ elsif ($Arg eq "--utf8")
+ {
+ $OptUTF8 = 1;
+ }
elsif ($Arg eq "--debug")
{
$Debug = 1;
@@ -413,7 +418,7 @@ if (!defined $Usage)
}
if (!$OptLocale and !$OptSystem and !$OptMUI and !$OptKeyboard and
- !$OptCountry and !$OptShow)
+ !$OptCountry and !$OptUTF8 and !$OptShow)
{
Error("you must specify at least one locale to change\n");
$Usage = 2;
@@ -433,7 +438,7 @@ if (defined $Usage)
exit $Usage;
}
print "Usage: $name0 [options] --show HOSTNAME\n";
- print "or $name0 [options] [--default DEF] [--locale LOC] [--system SYS] [--mui MUI] [--keyboard KBD] [--country CTY] HOSTNAME\n";
+ print "or $name0 [options] [--default DEF] [--locale LOC] [--system SYS] [--utf8] [--mui MUI] [--keyboard KBD] [--country CTY] HOSTNAME\n";
print "\n";
print "Sets the locale of the specified Windows machine.\n";
print "\n";
@@ -456,6 +461,13 @@ if (defined $Usage)
print " Administrative Language Settings -> Change system locale.\n";
print " . APIs: GetSystemDefaultLCID().\n";
print " . Powershell: Set-WinSystemLocale -SystemLocale SYS\n";
+ print " --utf8 Set the code pages (ACP, MACCP and OEMCP) to UTF-8.\n";
+ print " . Windows 10 GUI: Time & language -> Language ->\n";
+ print " Administrative Language Settings -> Change system locale ->\n";
+ print " Beta: Use Unicode UTF-8 for worldwide language support.\n";
+ print " . APIs: GetACP(), GetOEMCP().\n";
+ print " . Powershell: Automatically and unconditionally set by\n";
+ print " Set-WinSystemLocale for the relevant locales.\n";
print " --mui MUI Specifies the display language (see --defaults).\n";
print " . Only takes effect after a log out + log in.\n";
print " . Windows 10 GUI: Time & language -> Language -> Windows\n";
@@ -533,6 +545,26 @@ sub RegGetValue($;$)
return $Values->{defined $VName ? $VName : "(Default)"};
}
+sub RegSetValue($$$$)
+{
+ my ($Key, $VName, $Type, $Value) = @_;
+
+ my $Cmd = ["reg.exe", "add", $Key, "/f"];
+ push @$Cmd, (defined $VName ? ("/v", $VName) : ("/ve"));
+ $Value = join("\\0", @$Value) if (ref($Value) eq "ARRAY");
+ push @$Cmd, "/t" , $Type, "/d", $Value;
+
+ my $Pid = $TA->Run($Cmd, 0);
+ if (!$Pid)
+ {
+ FatalError("failed to run @$Cmd\n");
+ }
+ if (!defined $TA->Wait($Pid, 10))
+ {
+ FatalError("@$Cmd timed out: ", $TA->GetLastError(), "\n");
+ }
+}
+
#
# Show the host's locale settings
@@ -570,6 +602,11 @@ sub GetWinSettings($)
$Settings->{SysLanguage} = RegGetValue($HKLM_LANGUAGE, "Default");
$Settings->{SysLocale} = RegGetValue($HKLM_LOCALE, "(Default)");
}
+ if ($OptUTF8 or $All)
+ {
+ my $Values = RegGetValues($HKLM_CODE_PAGE, "*CP");
+ map { $Settings->{$_} = $Values->{$_} } ("ACP", "MACCP", "OEMCP");
+ }
return $Settings;
}
@@ -595,6 +632,9 @@ sub ShowWinSettings($)
print " Previous... (--mui) = ", Value2Str($Settings->{PreviousPreferredUILanguages}), "\n";
print "Nls:Language (--system) = ", Value2Str($Settings->{SysLanguage}), "\n";
print "Nls:Locale (--system) = ", Value2Str($Settings->{SysLocale}), "\n";
+ print "ACP (--utf8) = ", Value2Str($Settings->{ACP}), "\n";
+ print "MACCP (--utf8) = ", Value2Str($Settings->{MACCP}), "\n";
+ print "OEMCP (--utf8) = ", Value2Str($Settings->{OEMCP}), "\n";
}
if ($OptShow)
@@ -784,6 +824,20 @@ if (!$DryRun)
}
+#
+# Change the code pages manually
+#
+
+if ($OptUTF8)
+{
+ # intl.cpl does not support setting a specific code page
+ foreach my $VName ("ACP", "MACCP", "OEMCP")
+ {
+ RegSetValue($HKLM_CODE_PAGE, $VName, "REG_SZ", "65001");
+ }
+}
+
+
#
# Reboot to finalize the changes
#
@@ -861,6 +915,13 @@ if ($OptSystem)
CheckSetting($Settings, "SysLanguage", $LCIDSystem, "for --system $OptSystem", 1);
CheckSetting($Settings, "SysLocale", "0000$LCIDSystem", "for --system $OptSystem", 1);
}
+if ($OptUTF8)
+{
+ foreach my $VName ("ACP", "MACCP", "OEMCP")
+ {
+ CheckSetting($Settings, $VName, "65001", "for --utf8");
+ }
+}
exit(1) if (!$Success);
--
2.30.2
More information about the wine-devel
mailing list