param( [Parameter(Mandatory = $true)] [string]$ProjectRoot, [string]$SdkRoot, [string]$QtRoot, [string]$PostgresBin, [switch]$RuntimeOnly ) $ErrorActionPreference = 'Stop' function Resolve-ExistingDirectory { param([string[]]$Candidates, [string]$Label) foreach ($candidate in $Candidates) { if ($candidate -and (Test-Path -LiteralPath $candidate -PathType Container)) { return [IO.Path]::GetFullPath($candidate) } } throw "$Label directory was not found." } function Copy-FileIfChanged { param([string]$Source, [string]$Destination) if (-not (Test-Path -LiteralPath $Source -PathType Leaf)) { throw "Missing deployment file: $Source" } $sourceItem = Get-Item -LiteralPath $Source $destinationItem = Get-Item -LiteralPath $Destination -ErrorAction SilentlyContinue if ($destinationItem -and $destinationItem.Length -eq $sourceItem.Length -and $destinationItem.LastWriteTimeUtc -eq $sourceItem.LastWriteTimeUtc) { return } $parent = Split-Path -Parent $Destination if ($parent) { New-Item -ItemType Directory -Path $parent -Force | Out-Null } Copy-Item -LiteralPath $Source -Destination $Destination -Force } function Copy-TreeIncremental { param([string]$Source, [string]$Destination) if (-not (Test-Path -LiteralPath $Source -PathType Container)) { throw "Missing deployment directory: $Source" } foreach ($file in Get-ChildItem -LiteralPath $Source -Recurse -File) { $relative = $file.FullName.Substring($Source.Length).TrimStart('\', '/') Copy-FileIfChanged $file.FullName (Join-Path $Destination $relative) } } $project = [IO.Path]::GetFullPath($ProjectRoot) $output = Join-Path $project 'bin' $sdk = Resolve-ExistingDirectory @( $SdkRoot, $env:HVG_SDK_ROOT, (Join-Path $project '../../HikVisionGuide/HikVisionGuide_DLL') ) 'HikVisionGuidance SDK' $qt = Resolve-ExistingDirectory @( $QtRoot, $env:HVG_QT_ROOT, 'C:\Qt\Qt5.14.1\5.14.1\msvc2017_64' ) 'Qt 5.14.1 MSVC x64' $postgres = Resolve-ExistingDirectory @( $PostgresBin, $env:HVG_POSTGRES_BIN, 'C:\Program Files\PostgreSQL\16\bin' ) 'PostgreSQL client runtime' New-Item -ItemType Directory -Path $output -Force | Out-Null $sdkBin = Join-Path $sdk 'bin' foreach ($pattern in @('*.dll', '*.cti', '*.ini', '*.manifest')) { foreach ($file in Get-ChildItem -LiteralPath $sdkBin -File -Filter $pattern) { Copy-FileIfChanged $file.FullName (Join-Path $output $file.Name) } } Copy-FileIfChanged (Join-Path $sdkBin 'qt.conf') (Join-Path $output 'qt.conf') foreach ($directory in @('platforms', 'imageformats', 'styles', 'ThirdParty')) { Copy-TreeIncremental (Join-Path $sdkBin $directory) (Join-Path $output $directory) } foreach ($name in @('Qt5Sql.dll', 'Qt5SerialBus.dll')) { Copy-FileIfChanged (Join-Path $qt "bin/$name") (Join-Path $output $name) } Copy-FileIfChanged (Join-Path $qt 'plugins/sqldrivers/qsqlpsql.dll') ` (Join-Path $output 'sqldrivers/qsqlpsql.dll') foreach ($name in @('libpq.dll', 'libssl-3-x64.dll', 'libcrypto-3-x64.dll', 'libintl-9.dll', 'libiconv-2.dll')) { Copy-FileIfChanged (Join-Path $postgres $name) (Join-Path $output $name) } # PostgreSQL loads libwinpthread first. Use the SDK version for both consumers: # the older PostgreSQL copy lacks clock_gettime64/nanosleep64 required by MVS FFmpeg. Copy-FileIfChanged (Join-Path $sdkBin 'ThirdParty/libwinpthread-1.dll') ` (Join-Path $output 'libwinpthread-1.dll') if (-not $RuntimeOnly) { Copy-FileIfChanged (Join-Path $project 'config.ini') (Join-Path $output 'config.ini') Copy-TreeIncremental (Join-Path $sdk 'config') (Join-Path $output 'config') Copy-TreeIncremental (Join-Path $sdk 'assets') (Join-Path $output 'assets') } $requiredRuntime = @( 'ssp.exe', 'HikVisionGuidance.dll', 'opencv_world4120.dll', 'onnxruntime.dll', 'VisionGuide.dll', 'VisionGuide_cpp.dll', 'MvCameraControl.dll', 'Qt5Core.dll', 'Qt5Gui.dll', 'Qt5Widgets.dll', 'Qt5Network.dll', 'Qt5SerialPort.dll', 'Qt5SerialBus.dll', 'Qt5Sql.dll', 'platforms/qwindows.dll', 'sqldrivers/qsqlpsql.dll', 'libpq.dll', 'libwinpthread-1.dll', 'ThirdParty/libwinpthread-1.dll' ) foreach ($relative in $requiredRuntime) { if (-not (Test-Path -LiteralPath (Join-Path $output $relative) -PathType Leaf)) { throw "Incomplete runtime deployment: $relative" } } if (-not $RuntimeOnly) { $sdkConfigPath = Join-Path $output 'config/sdk.json' $sdkConfig = Get-Content -LiteralPath $sdkConfigPath -Raw -Encoding UTF8 | ConvertFrom-Json $assetRoot = [IO.Path]::GetFullPath((Join-Path (Split-Path -Parent $sdkConfigPath) $sdkConfig.asset_root)) foreach ($entry in $sdkConfig.files.PSObject.Properties) { $path = Join-Path $assetRoot ([string]$entry.Value) $expectedType = if ($entry.Name -eq 'trays') { 'Container' } else { 'Leaf' } if (-not (Test-Path -LiteralPath $path -PathType $expectedType)) { throw "Incomplete asset deployment: files.$($entry.Name) -> $path" } } } Write-Host "Deployment complete: $output" Write-Host ($(if ($RuntimeOnly) { 'Runtime libraries only.' } else { 'Runtime libraries, configuration and assets.' }))