Also use RunAndWait() to simplify the code.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/SetWinLocale | 42 +++++++----------------------------- testbot/bin/SetWinLocale.ps1 | 29 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 36 deletions(-)
diff --git a/testbot/bin/SetWinLocale b/testbot/bin/SetWinLocale index e544a580d3..b8908e6a0a 100755 --- a/testbot/bin/SetWinLocale +++ b/testbot/bin/SetWinLocale @@ -79,7 +79,7 @@ sub Cleanup() } else { - $TA->Rm("$name0.out", "$name0.ps1"); + $TA->Rm("$name0.out", "$name0.ps1", "$name0.xml"); } }
@@ -876,44 +876,18 @@ push @Config, "</gs:GlobalizationServices>"; # Change the Windows locale using intl.cpl #
-Debug(Elapsed($Start), join("\n", " Sending the configuration file\nlocales.xml:", @Config, "")); +Debug(Elapsed($Start), join("\n", " Sending the configuration file\n$name0.xml:", @Config, ""));
-if (!$TA->SendFileFromString(join("\r\n", @Config, ""), "locales.xml", 0)) +if (!$TA->SendFileFromString(join("\r\n", @Config, ""), "$name0.xml", 0)) { FatalError("could not send the configuration file:", $TA->GetLastError(), "\n"); }
-# For some reason this only works when run from a batch script! -Debug(Elapsed($Start), " Sending the batch file\n"); -my $Cmd = 'control.exe intl.cpl,,/f:"locales.xml"'; -if (!$TA->SendFileFromString($Cmd, "script.bat", $TestAgent::SENDFILE_EXE)) -{ - FatalError("could not send the batch file:", $TA->GetLastError(), "\n"); -} - -Debug(Elapsed($Start), " Running intl.cpl\n"); -my $Pid = $TA->Run(["./script.bat"], 0); -if (!$Pid) -{ - FatalError("failed to run intl.cpl\n"); -} - -# Unfortunately the control.exe and/or intl.cpl exit code is unusable so -# there is no way to check for errors -Debug(Elapsed($Start), " Waiting for intl.cpl\n"); -if (!defined $TA->Wait($Pid, 120)) -{ - FatalError("could not run intl.cpl: ", $TA->GetLastError(), "\n"); -} - -if ($Debug) -{ - print STDERR "Not deleting script.bat and locales.xml\n"; -} -else -{ - $TA->Rm("script.bat", "locales.xml"); -} +my $Cmd = ["powershell.exe", "-ExecutionPolicy", "ByPass", "-File", + "$name0.ps1", "locales", "$name0.xml"]; +Debug(Elapsed($Start), " Running ", join(" ", @$Cmd), "\n"); +my $Ret = $TA->RunAndWait($Cmd, 0, 120); +FatalError("$name0.ps1 locales failed: ", $TA->GetLastError(), "\n") if ($Ret < 0);
# diff --git a/testbot/bin/SetWinLocale.ps1 b/testbot/bin/SetWinLocale.ps1 index 702b3301dc..b893755ccb 100644 --- a/testbot/bin/SetWinLocale.ps1 +++ b/testbot/bin/SetWinLocale.ps1 @@ -1,4 +1,4 @@ -# Shows the Windows locale settings +# Shows or sets the Windows locale settings # # Copyright 2022 Francois Gouget # @@ -104,6 +104,27 @@ function ShowSettings() }
+# +# Modify the Windows locales settings +# + +function SetLocales($Argv) +{ + $XmlFile = $Argv[1] + $IntlArg = 'intl.cpl,,/f:"' + $XmlFile + '"' + Write-Output "Running: control.exe $IntlArg" + control.exe $IntlArg + # intl.cpl executes asynchronously which means that: + # - The exit code cannot be used to check for failures. + # - The configuration file should not be removed too early. + # - Further locale modifications (e.g. setting the code pages) should only + # be done after intl.cpl is done to avoid races. + # So 'wait' for intl.cpl to be done by introducing an arbitrary pause. + Start-Sleep 2 + exit 0 +} + + # # Main # @@ -111,17 +132,21 @@ function ShowSettings() function ShowUsage() { Write-Output "Usage: $Name0 settings" + Write-Output "or $Name0 locales XMLFILE" Write-Output "or $Name0 -?" Write-Output "" - Write-Output "Shows the Windows locales." + Write-Output "Shows or modifies the Windows locales." Write-Output "" Write-Output "Where:" Write-Output " settings Show the current Windows locale settings." + Write-Output " locales Modifies the locales by passing the $Name0.xml file to intl.cpl." + Write-Output " XMLFILE The filename of the intl.cpl XML configuration." Write-Output " -? Shows this help message." }
$Action = $args[0] if ($Action -eq "settings") { ShowSettings } +if ($Action -eq "locales") { SetLocales $args } $Rc = 0 if ($Action -and $Action -ne "-?" -and $Action -ne "-h" -and $Action -ne "help") {