@echo off
REM ============================================================
REM  Happy Accident installer  (Windows VST3)
REM
REM  Double-click this file. It asks for administrator rights
REM  once (the Windows "Yes" prompt), then copies the
REM  "Happy Accident.vst3" bundle sitting next to it into the
REM  shared VST3 folder - the same folder Happy Accident itself
REM  scans for the plug-ins it rolls. Only the previous
REM  Happy Accident.vst3 is replaced; nothing else.
REM
REM  "Happy Accident.exe" (the standalone) needs no install -
REM  run it where it sits.
REM ============================================================
setlocal enableextensions

REM --- self-elevate to admin (needed to write Program Files) ---
net session >nul 2>&1
if %errorlevel% neq 0 (
  echo Requesting administrator rights...
  powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
  exit /b
)

set "SRC=%~dp0Happy Accident.vst3"
set "DST=C:\Program Files\Common Files\VST3\Happy Accident.vst3"

REM --- guard: a running DAW locks the .vst3 and the copy fails silently ---
for %%H in (Ableton Cubase reaper Bitwig FL64 Studio One) do (
  tasklist 2>nul | find /i "%%H" >nul
  if not errorlevel 1 (
    echo.
    echo  Close %%H completely first - it locks the plug-in file.
    echo.
    pause
    exit /b 1
  )
)

if not exist "%SRC%" (
  echo.
  echo  Could not find "Happy Accident.vst3" next to this installer.
  echo  Unzip the WHOLE download, then run Install-Happy-Accident.cmd
  echo  from inside it.
  echo.
  pause
  exit /b 1
)

echo.
echo  Installing Happy Accident...
echo     from: %SRC%
echo     to:   %DST%
echo.

robocopy "%SRC%" "%DST%" /MIR /R:1 /W:1 /NJH /NJS /NDL /NFL /NP >nul
if %errorlevel% geq 8 (
  echo  Install FAILED ^(robocopy code %errorlevel%^). Try closing your DAW and re-running.
  pause
  exit /b 1
)

echo  Done. Open your DAW and rescan plug-ins - look for "Happy Accident" ^(VST3^).
echo.
pause
