@echo off
cd /d "%~dp0"
echo ================================================
echo  Vorbis ACM XP x64 compatibility patch
echo ================================================
echo.
echo This will:
echo   1. back up your original vorbis.acm
echo   2. install KERNXP32.dll into system32
echo   3. install the patched vorbis.acm
echo.
echo You must be running as Administrator.
echo Press Ctrl-C to abort, or
pause
echo.

echo --- generating patched codec ---
patch_vorbis.exe "C:\WINDOWS\system32\vorbis.acm" "vorbis_xp.acm"
if errorlevel 1 goto failed
echo.

echo --- backing up original ---
if not exist "%~dp0vorbis.acm.original" (
    copy /y "C:\WINDOWS\system32\vorbis.acm" "%~dp0vorbis.acm.original"
    echo Backup saved to %~dp0vorbis.acm.original
) else (
    echo Backup already exists, keeping it.
)
echo.

echo --- installing shim ---
copy /y KERNXP32.dll "C:\WINDOWS\system32\KERNXP32.dll"
if errorlevel 1 goto failed
echo.

echo --- installing patched codec ---
copy /y vorbis_xp.acm "C:\WINDOWS\system32\vorbis.acm"
if errorlevel 1 goto failed
echo.

echo --- verifying ---
acmtest3_64.exe "C:\WINDOWS\system32\vorbis.acm"
echo.
echo --- enumerating 64-bit ACM drivers ---
acmtest64.exe > verify.txt 2>^&1
findstr /c:"driver]" verify.txt
echo.
echo If "Ogg Vorbis" appears above, it worked. Start FL64 and test.
goto end

:failed
echo.
echo FAILED. Are you running as Administrator?

:end
pause
