$ErrorActionPreference = "Stop"

$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$pluginName = "Pioneer MP Trigger.vst3"
$pluginSource = Join-Path $scriptDir $pluginName
$vst3Root = Join-Path $env:ProgramFiles "Common Files\VST3"
$pluginDest = Join-Path $vst3Root $pluginName

Write-Host "Pioneer MP Trigger VST3 installer"
Write-Host ""

if (-not (Test-Path -LiteralPath $pluginSource)) {
    throw "Cannot find $pluginName next to this installer script."
}

New-Item -ItemType Directory -Force -Path $vst3Root | Out-Null

if (Test-Path -LiteralPath $pluginDest) {
    Write-Host "Replacing existing installation:"
    Write-Host "  $pluginDest"
    Remove-Item -LiteralPath $pluginDest -Recurse -Force
}

Copy-Item -LiteralPath $pluginSource -Destination $vst3Root -Recurse -Force

Write-Host ""
Write-Host "Installed successfully:"
Write-Host "  $pluginDest"
Write-Host ""
Write-Host "Open your DAW and rescan VST3 plug-ins if it does not appear automatically."
