@echo off
REM ============================================================
REM  Rack installer  (Windows VST3)
REM
REM  Double-click this file. It asks for administrator rights
REM  once (the Windows "Yes" prompt), then copies the Rack.vst3
REM  bundle sitting next to it into the shared VST3 folder -
REM  one of the two standard VST3 folders Rack scans for the
REM  plug-ins it hosts (the other is the per-user one under
REM  %LOCALAPPDATA%\Programs\Common\VST3).
REM  Only the previous Rack.vst3 is replaced; nothing else.
REM
REM  The whole Rack.vst3 FOLDER is installed, not a single file:
REM  it carries RackScanner.exe, the helper Rack starts to open
REM  plug-in bundles without freezing the DAW.
REM
REM  Rack.exe (the standalone) needs no install - run it where
REM  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=%~dp0Rack.vst3"
set "DST=C:\Program Files\Common Files\VST3\Rack.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 "Rack.vst3" next to this installer.
  echo  Unzip the WHOLE download, then run Install-Rack.cmd from inside it.
  echo.
  pause
  exit /b 1
)

echo.
echo  Installing Rack...
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 "Rack" ^(VST3^).
echo.
pause
