# Wild Dragon MAM - Premiere Pro plugin installer (Windows)
# Run from PowerShell as the same user that runs Premiere Pro (NOT as admin)
#
# Usage:
#   1. Open this folder in PowerShell
#   2. Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
#   3. .\install-windows.ps1

$ErrorActionPreference = 'Stop'

$src  = $PSScriptRoot
$dest = Join-Path $env:APPDATA 'Adobe\CEP\extensions\com.wilddragon.mam.panel'

Write-Host "Source: $src"
Write-Host "Target: $dest"

if (Test-Path $dest) {
    Write-Host "Removing existing extension at $dest"
    Remove-Item -Recurse -Force $dest
}
New-Item -ItemType Directory -Force -Path $dest | Out-Null
Copy-Item -Recurse -Force "$src\*" $dest -Exclude 'install-windows.ps1'

Write-Host 'Files copied.'

# Enable CEP debug mode for the supported CEP versions (Premiere Pro uses CSXS.11+).
foreach ($v in 8..13) {
    $regPath = "HKCU:\Software\Adobe\CSXS.$v"
    if (-not (Test-Path $regPath)) { New-Item -Path $regPath -Force | Out-Null }
    Set-ItemProperty -Path $regPath -Name 'PlayerDebugMode' -Value 1 -Type String
    Write-Host "Set PlayerDebugMode=1 on $regPath"
}

Write-Host ''
Write-Host 'Done. Restart Premiere Pro, then:'
Write-Host '  Window -> Extensions -> Wild Dragon MAM'
Write-Host ''
Write-Host 'Server URL inside the panel should be the MAM web-UI, e.g.:'
Write-Host '  http://10.0.0.25:47434'
