$ErrorActionPreference = "Stop"

$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$PluginName = "CALM EverClean"
$SrcVst3 = Join-Path $ScriptDir "$PluginName.vst3"
$SrcExe = Join-Path $ScriptDir "$PluginName.exe"
$Vst3Dir = Join-Path ${env:CommonProgramFiles} "VST3"
$DstVst3 = Join-Path $Vst3Dir "$PluginName.vst3"
$StandaloneDir = Join-Path ${env:ProgramFiles} "Everworks\\$PluginName"
$DstExe = Join-Path $StandaloneDir "$PluginName.exe"

Write-Host ""
Write-Host "CALM EverClean Windows installer"
Write-Host "================================"
Write-Host "Close all DAWs and SuperRack/LiveProfessor before running."
Write-Host ""

if (-not (Test-Path $SrcVst3)) {
    throw "Missing VST3 folder: $SrcVst3"
}

New-Item -ItemType Directory -Path $Vst3Dir -Force | Out-Null
Remove-Item $DstVst3 -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item $SrcVst3 $DstVst3 -Recurse -Force
Write-Host "Installed VST3: $DstVst3"

if (Test-Path $SrcExe) {
    New-Item -ItemType Directory -Path $StandaloneDir -Force | Out-Null
    Copy-Item $SrcExe $DstExe -Force
    Write-Host "Installed Standalone: $DstExe"
}

Write-Host ""
Write-Host "Done. Reopen your host and rescan VST3 plug-ins."

