# Setup script for finngineering/apxutil on Windows (PowerShell), from https://gitmanual.com/finngineering/apxutil # Read it before you run it: the commands come from the repo's own README and files. # Run: powershell -ExecutionPolicy Bypass -File .\setup.ps1 $ErrorActionPreference = "Stop" function Write-Step($t) { Write-Host "`n==> $t" -ForegroundColor Cyan } # Windows ships a python that only opens the Microsoft Store; it doesn't count. function Have($c) { $cmd = Get-Command $c -ErrorAction SilentlyContinue; [bool]$cmd -and $cmd.Source -notlike '*\WindowsApps\*' } # New installs change PATH; pick it up without opening a new window. function Update-Path { $env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [Environment]::GetEnvironmentVariable("Path", "User") } # Stop when a program fails, like bash's set -e. Dot-sourced, so cd and venv activation carry on to the next step. function Invoke-Step([scriptblock]$Block) { $global:LASTEXITCODE = 0; . $Block; if ($LASTEXITCODE) { throw "Failed with exit code $LASTEXITCODE" } } Write-Step '1/3 Clone the repository' if (-not (Test-Path 'apxutil')) { Invoke-Step { git clone https://github.com/finngineering/apxutil.git } } Set-Location 'apxutil' Write-Step '2/3 Install the required tools' # Python 3 if (-not (Have 'python')) { Invoke-Step { winget install Python.Python.3.12 -e --accept-source-agreements --accept-package-agreements }; Update-Path } Write-Step '3/3 Follow the README: Usage' # In the maintainers' order. Do the README instructions above first — they cover steps outside the terminal. Invoke-Step { python apxutil.py -h } Invoke-Step { usage: apxutil.py [-h] [-f filaname-apx] [-F filaname-sta] [-e dir] [-E dir] [-a manifestpath] [-A manifestpath] [-d] } Invoke-Step { [-x] [-B] [-r] } Invoke-Step { Tool to manipulate Schneider Electric .sta and .apx files } Invoke-Step { options: } Invoke-Step { -h, --help show this help message and exit } Invoke-Step { -f, --apxfile filaname-apx } Invoke-Step { .apx file to read or write } Invoke-Step { -F, --stafile filaname-sta } Invoke-Step { .sta file to read or write } Invoke-Step { -e, --extract-apx dir } Invoke-Step { extract contents of the Station.apx file } Invoke-Step { -E, --extract-sta dir } Invoke-Step { extract contents of the .sta file } Invoke-Step { -a, --assemble-apx manifestpath } Invoke-Step { create Station.apx file based on apx_manifest.ini } Invoke-Step { -A, --assemble-sta manifestpath } Invoke-Step { create a .sta file from files in sta_manifest.ini } Invoke-Step { -d, --decompress decompress Station.apx sections that are compressed } Invoke-Step { -x, --hexdump print hexdump of Station.apx with header information } Invoke-Step { -B, --include-apd include Station.apd when creating .sta archive } Invoke-Step { -r, --restart-offsets } Invoke-Step { restart offsets at 0 for each section in hexdump print (useful for diffing) } Invoke-Step { python apxutil.py -F archive.sta -E extracted } Invoke-Step { python apxutil.py -f extracted/BinAppli/Station.apx -e contents -d } Invoke-Step { python apxutil.py -f extracted/BinAppli/Station.apx -a contents } Invoke-Step { python apxutil.py -F modified-archive.sta -A extracted } Invoke-Step { python apxutil.py -F modified-archive.sta -x } Write-Host 'Set up finngineering/apxutil.' Write-Host 'Manual: https://gitmanual.com/finngineering/apxutil'