2 param([string]$targetBinary, [string]$installedDir, [string]$tlogFile, [string]$copiedFilesLog)
5 # Note: installedDir is actually the bin\ directory.
6 $g_install_root = Split-Path $installedDir -parent
7 $g_is_debug = $g_install_root -match '(.*\\)?debug(\\)?$'
9 # Ensure we create the copied files log, even if we don't end up copying any files
12 Set-Content -Path $copiedFilesLog -Value "" -Encoding UTF8
15 function computeHash([System.Security.Cryptography.HashAlgorithm]$alg, [string]$str) {
16 $bytes = [System.Text.Encoding]::UTF8.GetBytes($str)
17 $hash = $alg.ComputeHash($bytes)
18 return [Convert]::ToBase64String($hash)
21 function getMutex([string]$targetDir) {
22 $sha512Hash = [System.Security.Cryptography.SHA512]::Create()
24 $hash = computeHash $sha512Hash $targetDir
25 $mtxName = "VcpkgAppLocalDeployBinary-" + $hash
26 return New-Object System.Threading.Mutex($false, $mtxName)
29 return New-Object System.Threading.Mutex($false, "VcpkgAppLocalDeployBinary")
32 # Note: this function signature is depended upon by the qtdeploy.ps1 script introduced in 5.7.1-7
33 function deployBinary([string]$targetBinaryDir, [string]$SourceDir, [string]$targetBinaryName) {
35 $mtx = getMutex($targetBinaryDir)
37 $mtx.WaitOne() | Out-Null
40 if (Test-Path "$targetBinaryDir\$targetBinaryName") {
41 $sourceModTime = (Get-Item $SourceDir\$targetBinaryName).LastWriteTime
42 $destModTime = (Get-Item $targetBinaryDir\$targetBinaryName).LastWriteTime
43 if ($destModTime -lt $sourceModTime) {
44 Write-Verbose " ${targetBinaryName}: Updating $SourceDir\$targetBinaryName"
45 Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir
47 Write-Verbose " ${targetBinaryName}: already present"
51 Write-Verbose " ${targetBinaryName}: Copying $SourceDir\$targetBinaryName"
52 Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir
54 if ($copiedFilesLog) { Add-Content $copiedFilesLog "$targetBinaryDir\$targetBinaryName" -Encoding UTF8 }
55 if ($tlogFile) { Add-Content $tlogFile "$targetBinaryDir\$targetBinaryName" -Encoding Unicode }
58 $mtx.ReleaseMutex() | Out-Null
59 $mtx.Dispose() | Out-Null
65 Write-Verbose "Resolving base path $targetBinary..."
68 $baseBinaryPath = Resolve-Path $targetBinary -erroraction stop
69 $baseTargetBinaryDir = Split-Path $baseBinaryPath -parent
71 catch [System.Management.Automation.ItemNotFoundException]
76 # Note: this function signature is depended upon by the qtdeploy.ps1 script
77 function resolve([string]$targetBinary) {
78 Write-Verbose "Resolving $targetBinary..."
81 $targetBinaryPath = Resolve-Path $targetBinary -erroraction stop
83 catch [System.Management.Automation.ItemNotFoundException]
87 $targetBinaryDir = Split-Path $targetBinaryPath -parent
89 if (Get-Command "dumpbin" -ErrorAction SilentlyContinue) {
90 $a = $(dumpbin /DEPENDENTS $targetBinary | ? { $_ -match "^ [^ ].*\.dll" } | % { $_ -replace "^ ","" })
91 } elseif (Get-Command "llvm-objdump" -ErrorAction SilentlyContinue) {
92 $a = $(llvm-objdump -p $targetBinary| ? { $_ -match "^ {4}DLL Name: .*\.dll" } | % { $_ -replace "^ {4}DLL Name: ","" })
94 Write-Error "Neither dumpbin nor llvm-objdump could be found. Can not take care of dll dependencies."
97 if ([string]::IsNullOrEmpty($_)) {
100 if ($g_searched.ContainsKey($_)) {
101 Write-Verbose " ${_}: previously searched - Skip"
104 $g_searched.Set_Item($_, $true)
105 if (Test-Path "$installedDir\$_") {
106 deployBinary $baseTargetBinaryDir $installedDir "$_"
107 if (Test-Path function:\deployPluginsIfQt) { deployPluginsIfQt $baseTargetBinaryDir "$g_install_root\plugins" "$_" }
108 if (Test-Path function:\deployOpenNI2) { deployOpenNI2 $targetBinaryDir "$g_install_root" "$_" }
109 if (Test-Path function:\deployPluginsIfMagnum) {
111 deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum-d" "$_"
113 deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum" "$_"
116 if (Test-Path function:\deployAzureKinectSensorSDK) { deployAzureKinectSensorSDK $targetBinaryDir "$g_install_root" "$_" }
117 resolve "$baseTargetBinaryDir\$_"
118 } elseif (Test-Path "$targetBinaryDir\$_") {
119 Write-Verbose " ${_}: $_ not found in vcpkg; locally deployed"
120 resolve "$targetBinaryDir\$_"
122 Write-Verbose " ${_}: $installedDir\$_ not found"
125 Write-Verbose "Done Resolving $targetBinary."
128 # Note: This is a hack to make Qt5 work.
129 # Introduced with Qt package version 5.7.1-7
130 if (Test-Path "$g_install_root\plugins\qtdeploy.ps1") {
131 . "$g_install_root\plugins\qtdeploy.ps1"
134 # Note: This is a hack to make OpenNI2 work.
135 if (Test-Path "$g_install_root\bin\OpenNI2\openni2deploy.ps1") {
136 . "$g_install_root\bin\OpenNI2\openni2deploy.ps1"
139 # Note: This is a hack to make Magnum work.
140 if (Test-Path "$g_install_root\bin\magnum\magnumdeploy.ps1") {
141 . "$g_install_root\bin\magnum\magnumdeploy.ps1"
142 } elseif (Test-Path "$g_install_root\bin\magnum-d\magnumdeploy.ps1") {
143 . "$g_install_root\bin\magnum-d\magnumdeploy.ps1"
146 # Note: This is a hack to make Azure Kinect Sensor SDK work.
147 if (Test-Path "$g_install_root\tools\azure-kinect-sensor-sdk\k4adeploy.ps1") {
148 . "$g_install_root\tools\azure-kinect-sensor-sdk\k4adeploy.ps1"
151 resolve($targetBinary)
152 Write-Verbose $($g_searched | out-string)