The new Powershell script can also be used independently on Windows.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/SetWinLocale | 103 +++++++++++++++++++------------- testbot/bin/SetWinLocale.ps1 | 110 +++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+), 42 deletions(-) create mode 100644 testbot/bin/SetWinLocale.ps1
diff --git a/testbot/bin/SetWinLocale b/testbot/bin/SetWinLocale index 42a106b77d..25023bb94f 100755 --- a/testbot/bin/SetWinLocale +++ b/testbot/bin/SetWinLocale @@ -3,7 +3,7 @@ # # Sets the locale of the specified Windows machine. # -# Copyright 2018, 2021 Francois Gouget +# Copyright 2018, 2021-2022 Francois Gouget # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -41,12 +41,7 @@ use WineTestBot::Log; use WineTestBot::TestAgent; use WineTestBot::Utils;
-my $HKCU_INTERNATIONAL = "HKCU\Control Panel\International"; -my $HKCU_GEO = "HKCU\Control Panel\International\Geo"; 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";
@@ -74,11 +69,26 @@ sub Debug(@) print STDERR @_ if ($Debug); }
+my $TA; +sub Cleanup() +{ + return if (!$TA); + if ($Debug) + { + Debug("Not deleting the $name0* files for debugging\n"); + } + else + { + $TA->Rm("$name0.out", "$name0.ps1"); + } +} + my $Start = Time(); sub FatalError(@) { - Error( @_); + Error(@_); Debug(Elapsed($Start), " Aborting\n"); + Cleanup(); exit(1); }
@@ -487,7 +497,7 @@ if (defined $Usage) exit 0; }
-my $TA = TestAgent->new($OptHostName, $AgentPort); +$TA = TestAgent->new($OptHostName, $AgentPort);
# @@ -558,42 +568,44 @@ sub RegSetValue($$$$) # Show the host's locale settings #
-sub GetWinSettings($) +if (open(my $fh, "<", "$0.ps1")) { - my ($All) = @_; - my $Settings; + my $Script = join("", <$fh>); + close($fh);
- if ($OptLocale or $All) - { - my $Values = RegGetValues($HKCU_INTERNATIONAL, "Locale*"); - map { $Settings->{$_} = $Values->{$_} } ("Locale", "LocaleName"); - } - if ($OptCountry or $All) - { - my $Values = RegGetValues($HKCU_GEO, "N*"); - $Settings->{Country} = $Values->{Nation}; - $Settings->{CountryName} = $Values->{Name}; - } - if (($OptKeyboard || $OptDefault) or $All) - { - my $Values = RegGetValues($HKCU_USER_PROFILE, "*"); - $Settings->{InputMethod} = $Values->{InputMethodOverride}; - $Settings->{Languages} = $Values->{Languages}; - } - if ($OptMUI or $All) - { - my $Values = RegGetValues($HKCU_DESKTOP, "*PreferredUILanguages*"); - map { $Settings->{$_} = $Values->{$_} } ("PreferredUILanguages", "PreferredUILanguagesPending", "PreviousPreferredUILanguages"); - } - if ($OptSystem or $All) + $Script =~ s~\n~\r\n~g; + if (!$TA->SendFileFromString($Script, "$name0.ps1", 0)) { - $Settings->{SysLanguage} = RegGetValue($HKLM_LANGUAGE, "Default"); - $Settings->{SysLocale} = RegGetValue($HKLM_LOCALE, "(Default)"); + FatalError("could not send the batch file:", $TA->GetLastError(), "\n"); } - if ($OptUTF8 or $All) +} +else +{ + FatalError("could not open '$0.ps1' for reading: $!\n"); +} + +sub GetWinSettings() +{ + my $Cmd = ["powershell.exe", "-ExecutionPolicy", "ByPass", "-File", + "$name0.ps1", "settings"]; + my $Ret = $TA->RunAndWait($Cmd, 0, 30, undef, "$name0.out", "$name0.out"); + FatalError("failed to run @$Cmd: ", $TA->GetLastError(), "\n") if ($Ret < 0); + my $Out = $TA->GetFileToString("$name0.out") if (!$Ret); + + my ($Settings, $Key); + foreach my $Line (split /\n/, $Out || "") { - my $Values = RegGetValues($HKLM_CODE_PAGE, "*CP"); - map { $Settings->{$_} = $Values->{$_} } ("ACP", "MACCP", "OEMCP"); + $Line =~ s/\r$//; + if ($Line =~ /^([a-zA-Z]+)=[(.*)]$/) + { + my ($Name, $Value) = ($1, $2); + $Settings->{$Name} = [split /, /, $Value]; + } + elsif ($Line =~ /^([a-zA-Z]+)=(.*)$/) + { + my ($Name, $Value) = ($1, $2); + $Settings->{$Name} = $Value eq "<undef>" ? undef : $Value; + } } return $Settings; } @@ -609,6 +621,8 @@ sub Value2Str($) sub ShowWinSettings($) { my ($Settings) = @_; + + print "Current account:\n"; print "Locale (--locale) = ", Value2Str($Settings->{Locale}), "\n"; print "LocaleName (--locale) = ", Value2Str($Settings->{LocaleName}), "\n"; print "Geo:Nation (--country) = ", Value2Str($Settings->{Country}), "\n"; @@ -618,6 +632,9 @@ sub ShowWinSettings($) print "PreferredUILanguages (--mui) = ", Value2Str($Settings->{PreferredUILanguages}), "\n"; print " ...Pending (--mui) = ", Value2Str($Settings->{PreferredUILanguagesPending}), "\n"; print " Previous... (--mui) = ", Value2Str($Settings->{PreviousPreferredUILanguages}), "\n"; + + print "\n"; + print "System settings:\n"; print "Nls:Language (--system) = ", Value2Str($Settings->{SysLanguage}), "\n"; print "Nls:Locale (--system) = ", Value2Str($Settings->{SysLocale}), "\n"; print "ACP (--utf8) = ", Value2Str($Settings->{ACP}), "\n"; @@ -627,7 +644,8 @@ sub ShowWinSettings($)
if ($OptShow) { - ShowWinSettings(GetWinSettings("all")); + ShowWinSettings(GetWinSettings()); + Cleanup(); exit(0); }
@@ -856,7 +874,7 @@ sub CheckSetting($$$$;$) my ($Settings, $VName, $Expected, $For, $IgnoreCase) = @_;
my $Value = $Settings->{$VName}; - if (defined $Value) + if (defined $Value and $Value !~ /^<.+>$/) { if ((!$IgnoreCase and $Value ne $Expected) or ($IgnoreCase and uc($Value) ne uc($Expected))) @@ -868,7 +886,7 @@ sub CheckSetting($$$$;$) }
Debug(Elapsed($Start), " Checking the new locale settings\n"); -my $Settings = GetWinSettings($Debug); +my $Settings = GetWinSettings(); ShowWinSettings($Settings) if ($Debug); if ($OptLocale) { @@ -901,6 +919,7 @@ if ($KeyboardIds) CheckSetting($Settings, "InputMethod", $KeyboardIds->[0], "for --keyboard $OptKeyboard", 1); }
+Cleanup(); exit(1) if (!$Success); Debug(Elapsed($Start), " All done!\n"); exit(0); diff --git a/testbot/bin/SetWinLocale.ps1 b/testbot/bin/SetWinLocale.ps1 new file mode 100644 index 0000000000..8d6b3a94bc --- /dev/null +++ b/testbot/bin/SetWinLocale.ps1 @@ -0,0 +1,110 @@ +# Shows the Windows locale settings +# +# Copyright 2022 Francois Gouget +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +$Name0 = (Get-Item $MyInvocation.InvocationName).Basename + + +# +# Dump the Windows locales settings +# + +$HKCU_INTERNATIONAL = "HKCU:\Control Panel\International" +$HKCU_GEO = "HKCU:\Control Panel\International\Geo" +$HKCU_USER_PROFILE = "HKCU:\Control Panel\International\User Profile" +$HKCU_DESKTOP = "HKCU:\Control Panel\Desktop" +$HKLM_LANGUAGE = "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" +$HKLM_LOCALE = "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Locale" +$HKLM_CODE_PAGE = "HKLM:\System\CurrentControlSet\Control\Nls\CodePage" +$CODE_PAGES = "ACP", "MACCP", "OEMCP" + + +function ShowSetting([string]$Key, [string]$VName, [string]$SName) +{ + if ($SName -eq "") { $SName = $VName } + # Don't use Get-ItemPropertyValue because it ignores -ErrorAction and is + # not available on Windows 7. + $Value = Get-ItemProperty -Path $Key -Name $VName -ErrorAction SilentlyContinue + $Value = if ($Value -eq $null) { "<undef>" } else { $Value.$($VName) } + if ($Value.GetType().Name -eq "Object[]") + { + $Value = "[" + ($Value -join ", ") + "]" + } + Write-Output "$SName=$Value" +} + +function ShowSettings() +{ + Write-Output "Current account:" + ShowSetting $HKCU_INTERNATIONAL "Locale" + ShowSetting $HKCU_INTERNATIONAL "LocaleName" + ShowSetting $HKCU_GEO "Nation" "Country" + ShowSetting $HKCU_GEO "Name" "CountryName" + ShowSetting $HKCU_USER_PROFILE "InputMethodOverride" "InputMethod" + ShowSetting $HKCU_USER_PROFILE "Languages" + ShowSetting $HKCU_DESKTOP "PreferredUILanguages" + ShowSetting $HKCU_DESKTOP "PreferredUILanguagesPending" + ShowSetting $HKCU_DESKTOP "PreviousPreferredUILanguages" + + Write-Output "" + Write-Output "System settings:" + ShowSetting $HKLM_LANGUAGE "Default" "SysLanguage" + try + { + ShowSetting $HKLM_LOCALE "(Default)" "SysLocale" + } + catch + { + # On Windows 7 Get-ItemProperty confuses the key's default value + # with the value called "(Default)"! + Write-Output "SysLocale=<cannot-get-on-windows-7>" + } + foreach ($CodePage in $CODE_PAGES) + { + ShowSetting $HKLM_CODE_PAGE $CodePage + } + + exit 0 +} + + +# +# Main +# + +function ShowUsage() +{ + Write-Output "Usage: $Name0 settings" + Write-Output "or $Name0 -?" + Write-Output "" + Write-Output "Shows the Windows locales." + Write-Output "" + Write-Output "Where:" + Write-Output " settings Show the current Windows locale settings." + Write-Output " -? Shows this help message." +} + +$Action = $args[0] +if ($Action -eq "settings") { ShowSettings } +$Rc = 0 +if ($Action -and $Action -ne "-?" -and $Action -ne "-h" -and $Action -ne "help") +{ + echo "$Name0:error: unknown action $Action" + $Rc = 2 +} +ShowUsage +exit $Rc
In particular show how the system account (System/LocalSystem) settings are affected by SetWinLocale.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/SetWinLocale | 22 ++++++++++++++++++++-- testbot/bin/SetWinLocale.ps1 | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/testbot/bin/SetWinLocale b/testbot/bin/SetWinLocale index 25023bb94f..f1b72176eb 100755 --- a/testbot/bin/SetWinLocale +++ b/testbot/bin/SetWinLocale @@ -627,19 +627,37 @@ sub ShowWinSettings($) print "LocaleName (--locale) = ", Value2Str($Settings->{LocaleName}), "\n"; print "Geo:Nation (--country) = ", Value2Str($Settings->{Country}), "\n"; print "Geo:Name (--country) = ", Value2Str($Settings->{CountryName}), "\n"; - print "InputMethod (--keyboard) = ", Value2Str($Settings->{InputMethod}), "\n"; print "Languages = ", Value2Str($Settings->{Languages}), "\n"; print "PreferredUILanguages (--mui) = ", Value2Str($Settings->{PreferredUILanguages}), "\n"; print " ...Pending (--mui) = ", Value2Str($Settings->{PreferredUILanguagesPending}), "\n"; - print " Previous... (--mui) = ", Value2Str($Settings->{PreviousPreferredUILanguages}), "\n"; + print " Previous... = ", Value2Str($Settings->{PreviousPreferredUILanguages}), "\n"; + print "WindowsOverride (--mui) = ", Value2Str($Settings->{WindowsOverride}), "\n"; + print "InputMethod (--keyboard) = ", Value2Str($Settings->{InputMethod}), "\n";
print "\n"; print "System settings:\n"; print "Nls:Language (--system) = ", Value2Str($Settings->{SysLanguage}), "\n"; + print "Nls:InstallLang (--system) = ", Value2Str($Settings->{SysInstallLang}), "\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"; + + print "\n"; + print ".DEFAULT account:\n"; + # Locale used for the date and time in the logon screen + print "Locale (--locale) = ", Value2Str($Settings->{DefLocale}), "\n"; + print "LocaleName (--locale) = ", Value2Str($Settings->{DefLocaleName}), "\n"; + print "Geo:Nation (--country) = ", Value2Str($Settings->{DefCountry}), "\n"; + print "Geo:Name (--country) = ", Value2Str($Settings->{DefCountryName}), "\n"; + # Language of the 'Welcome' message + print "PreferredUILanguages = ", Value2Str($Settings->{DefPreferredUILanguages}), "\n"; + print " ...Pending = ", Value2Str($Settings->{DefPreferredUILanguagesPending}), "\n"; + print " Previous... = ", Value2Str($Settings->{DefPreviousPreferredUILanguages}), "\n"; + # Language of the 'Password' text in the password field + print "MachinePrefUILanguages(--mui)= ", Value2Str($Settings->{DefMachinePreferredUILanguages}), "\n"; + # Keyboard layout for the password field + print "InputMethod (--keyboard) = ", Value2Str($Settings->{DefInputMethod}), "\n"; }
if ($OptShow) diff --git a/testbot/bin/SetWinLocale.ps1 b/testbot/bin/SetWinLocale.ps1 index 8d6b3a94bc..702b3301dc 100644 --- a/testbot/bin/SetWinLocale.ps1 +++ b/testbot/bin/SetWinLocale.ps1 @@ -32,6 +32,12 @@ $HKLM_LOCALE = "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Locale" $HKLM_CODE_PAGE = "HKLM:\System\CurrentControlSet\Control\Nls\CodePage" $CODE_PAGES = "ACP", "MACCP", "OEMCP"
+$HKDEF_INTERNATIONAL = "Registry::HKEY_USERS.DEFAULT\Control Panel\International" +$HKDEF_GEO = "Registry::HKEY_USERS.DEFAULT\Control Panel\International\Geo" +$HKDEF_USER_PROFILE = "Registry::HKEY_USERS.DEFAULT\Control Panel\International\User Profile" +$HKDEF_DESKTOP = "Registry::HKEY_USERS.DEFAULT\Control Panel\Desktop" +$HKDEF_MUICACHED = "Registry::HKEY_USERS.DEFAULT\Control Panel\Desktop\MuiCached" +
function ShowSetting([string]$Key, [string]$VName, [string]$SName) { @@ -56,6 +62,7 @@ function ShowSettings() ShowSetting $HKCU_GEO "Name" "CountryName" ShowSetting $HKCU_USER_PROFILE "InputMethodOverride" "InputMethod" ShowSetting $HKCU_USER_PROFILE "Languages" + ShowSetting $HKCU_USER_PROFILE "WindowsOverride" ShowSetting $HKCU_DESKTOP "PreferredUILanguages" ShowSetting $HKCU_DESKTOP "PreferredUILanguagesPending" ShowSetting $HKCU_DESKTOP "PreviousPreferredUILanguages" @@ -63,6 +70,7 @@ function ShowSettings() Write-Output "" Write-Output "System settings:" ShowSetting $HKLM_LANGUAGE "Default" "SysLanguage" + ShowSetting $HKLM_LANGUAGE "InstallLanguage" "SysInstallLang" try { ShowSetting $HKLM_LOCALE "(Default)" "SysLocale" @@ -78,6 +86,20 @@ function ShowSettings() ShowSetting $HKLM_CODE_PAGE $CodePage }
+ Write-Output "" + Write-Output ".DEFAULT account:" + ShowSetting $HKDEF_INTERNATIONAL "Locale" "DefLocale" + ShowSetting $HKDEF_INTERNATIONAL "LocaleName" "DefLocaleName" + ShowSetting $HKDEF_GEO "Nation" "DefCountry" + ShowSetting $HKDEF_GEO "Name" "DefCountryName" + ShowSetting $HKDEF_USER_PROFILE "InputMethodOverride" "DefInputMethod" + ShowSetting $HKDEF_USER_PROFILE "Languages" "DefLanguages" + ShowSetting $HKDEF_USER_PROFILE "WindowsOverride" "DefWindowsOverride" + ShowSetting $HKDEF_DESKTOP "PreferredUILanguages" "DefPreferredUILanguages" + ShowSetting $HKDEF_DESKTOP "PreferredUILanguagesPending" "DefPreferredUILanguagesPending" + ShowSetting $HKDEF_DESKTOP "PreviousPreferredUILanguages" "DefPreviousPreferredUILanguages" + ShowSetting $HKDEF_MUICACHED "MachinePreferredUILanguages" "DefMachinePreferredUILanguages" + exit 0 }