51 lines
1.6 KiB
PowerShell
Raw Normal View History

2016-09-18 20:50:08 -07:00
[cmdletbinding()]
param([string]$targetBinary, [string]$installedDir, [string]$tlogFile)
$g_searched = @{}
function deployBinary([string]$targetBinaryDir, [string]$targetBinaryName) {
if (Test-Path "$targetBinaryDir\$targetBinaryName") {
Write-Verbose " ${targetBinaryName}: already present - Only recurse"
}
else {
Copy-Item "$installedDir\$targetBinaryName" $targetBinaryDir
Write-Verbose " ${targetBinaryName}: Copying $installedDir\$targetBinaryName"
}
"$targetBinaryDir\$targetBinaryName"
if ($tlogFile) { Add-Content $tlogFile "$targetBinaryDir\$targetBinaryName" }
}
function resolve([string]$targetBinary) {
Write-Verbose "Resolving $targetBinary..."
try
{
$targetBinaryPath = Resolve-Path $targetBinary -erroraction stop
}
catch [System.Management.Automation.ItemNotFoundException]
{
return
}
2016-09-18 20:50:08 -07:00
$targetBinaryDir = Split-Path $targetBinaryPath -parent
$a = $(dumpbin /DEPENDENTS $targetBinary | ? { $_ -match "^ [^ ].*\.dll" } | % { $_ -replace "^ ","" })
2016-09-18 20:50:08 -07:00
$a | % {
if ([string]::IsNullOrEmpty($_)) {
return
}
if ($g_searched.ContainsKey($_)) {
Write-Verbose " ${_}: previously searched - Skip"
return
}
$g_searched.Set_Item($_, $true)
2016-09-18 20:50:08 -07:00
if (Test-Path "$installedDir\$_") {
deployBinary($targetBinaryDir, $_)
2016-09-18 20:50:08 -07:00
resolve("$targetBinaryDir\$_")
} else {
Write-Verbose " ${_}: $installedDir\$_ not found"
2016-09-18 20:50:08 -07:00
}
}
Write-Verbose "Done Resolving $targetBinary."
2016-09-18 20:50:08 -07:00
}
resolve($targetBinary)
Write-Verbose $($g_searched | out-string)