# 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 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]*\r?\n?' $text = [regex]::Replace($text, $pattern, '') if (-not $Remove) { $add = [IO.File]::ReadAllText($block) -replace '(?. $m = [regex]::Match($text, '(?m)^[ \t]*') } if ($end -lt 0) { throw 'No 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' }