34 lines
1.8 KiB
PowerShell
34 lines
1.8 KiB
PowerShell
# Add or remove the CI-Eng-Sample layout block in Layouts.xml (CI Server R1.03.00).
|
|
# Usage: powershell -ExecutionPolicy Bypass -File layout.ps1 [-Remove]
|
|
# The block between <!-- CIENG-SAMPLE-BEGIN and <!-- CIENG-SAMPLE-END --> is inserted after
|
|
# the last layout (before the translations; an existing block is replaced). The first run
|
|
# saves Layouts-before-CIENG.xml next to Layouts.xml.
|
|
# No admin rights needed. Reopen the Operator Interface (or View > Reload All) afterwards.
|
|
param([switch]$Remove)
|
|
|
|
$wap = $env:TLS_WAP_PATH
|
|
if (-not $wap) { $wap = 'C:\Users\Public\Yokogawa\tls\wap' }
|
|
$file = Join-Path $wap 'cfg\operatorInterfaces\DEPLOY\layouts\Layouts.xml'
|
|
$backup = Join-Path $wap 'cfg\operatorInterfaces\DEPLOY\layouts\Layouts-before-CIENG.xml'
|
|
$block = Join-Path $PSScriptRoot 'CIENG_Operator.xml'
|
|
|
|
if (-not (Test-Path $file)) { throw "Not found: $file" }
|
|
if (-not (Test-Path $backup)) { Copy-Item -LiteralPath $file -Destination $backup }
|
|
|
|
$text = [IO.File]::ReadAllText($file)
|
|
$pattern = '(?s)[ \t]*<!-- CIENG-SAMPLE-BEGIN.*?<!-- CIENG-SAMPLE-END -->\r?\n?'
|
|
$text = [regex]::Replace($text, $pattern, '')
|
|
|
|
if (-not $Remove) {
|
|
$add = [IO.File]::ReadAllText($block) -replace '(?<!\r)\n', "`r`n"
|
|
# Insert after the last layout: before the first <translations, else before </layouts>.
|
|
$m = [regex]::Match($text, '(?m)^[ \t]*<translations\b')
|
|
if ($m.Success) { $end = $m.Index } else { $end = $text.LastIndexOf('</layouts>') }
|
|
if ($end -lt 0) { throw 'No </layouts> in Layouts.xml' }
|
|
$text = $text.Substring(0, $end) + $add + $text.Substring($end)
|
|
}
|
|
|
|
# Check that the result is still well-formed XML before writing it.
|
|
[xml]$null = $text
|
|
[IO.File]::WriteAllText($file, $text, (New-Object Text.UTF8Encoding($false)))
|
|
if ($Remove) { 'CIENG_Operator layout removed' } else { 'CIENG_Operator layout added' }
|