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