# 调用方法：
# powershell -ExecutionPolicy RemoteSigned  -Command "&'$(ProjectDir)Script\Post-Build-GdCpp.ps1' '$(ProjectDir)' '$(OutputPath)' '$(TargetFileName)' '$(Configuration)'"

# 参数列表。缺省参数用于调试脚本，以及参考示例
param(
    [string]$projectDir="d:\GoodVisionMotion\PC\KsCamExpert3\GdCpp\",
    [string]$targetDir="d:\GoodVisionMotion\PC\KsCamExpert3\GdCpp\x64\Debug",
    [string]$targetFileName="GdCppD.dll",
    [string]$Configuration="Debug"
)

$projectDir=(Split-Path -Parent $PSScriptRoot);


# 加载自定义函数
if(Test-Path "$PSScriptRoot\kslib.ps1") {
    . "$PSScriptRoot\kslib.ps1"
} else {
    Write-Output "kslib.ps1" 不存在
    pause
    exit 0
}

# 在输出增加一个空行，再打印提示
Write-Output "" 
Write-Output "执行Post-Build.ps1"
Write-Output ($msg = "projectDir    : "+$projectDir)
Write-Output ($msg = "targetDir     : "+$targetDir)
Write-Output ($msg = "targetFileName: "+$targetFileName)
Write-Output ($msg = "Configuration : "+$Configuration)

# 分解文件名与扩展名
$targetName = [System.IO.Path]::GetFileNameWithoutExtension($targetFileName) # CamExpert
$targetExt = [System.IO.Path]::GetExtension($targetFileName) # .exe

# 编译目标文件的完整路径
$srcBin = (Join-Path $targetDir $targetFileName);
$srcPdb = (Join-Path $targetDir "$targetName.pdb");
$srcLib = (Join-Path $targetDir "$targetName.lib");

# 如果更改了调试工作目录，且目录存在，复制到调试目录
$hasDebugDir=$false;

Write-Host 复制到lib目录
    
copy-file-ne $srcBin  (Join-Path $projectDir "bin")
copy-file-ne $srcPdb  (Join-Path $projectDir "bin")
copy-file-ne $srcLib  (Join-Path $projectDir "lib")



