@echo off
chcp 65001 >nul
echo.
echo   Reparando ARKHON-silent.vbs...
echo.

set "ROOT=C:\ARKHON"
set "VBS=%ROOT%\ARKHON-silent.vbs"
set "DAEMON=%ROOT%\daemon"

:: Buscar node.exe
for /f "tokens=*" %%i in ('where node 2^>nul') do set "NODEEXE=%%i"
if "%NODEEXE%"=="" (
    echo   [ERROR] Node.js no encontrado en PATH.
    pause
    exit /b 1
)

set "INDEXJS=%ROOT%\index.js"

:: Reparar el VBS en la raiz si existe
if exist "%VBS%" (
    echo   Reparando: %VBS%
    (
        echo Dim oShell
        echo Set oShell = CreateObject^("WScript.Shell"^)
        echo oShell.Run Chr^(34^) ^& "%NODEEXE%" ^& Chr^(34^) ^& " " ^& Chr^(34^) ^& "%INDEXJS%" ^& Chr^(34^), 0, False
        echo Set oShell = Nothing
    ) > "%VBS%"
    echo   [OK] VBS reparado.
)

:: Buscar VBS en carpeta daemon
if exist "%DAEMON%\" (
    for %%f in ("%DAEMON%\*.vbs") do (
        echo   Reparando: %%f
        (
            echo Dim oShell
            echo Set oShell = CreateObject^("WScript.Shell"^)
            echo oShell.Run Chr^(34^) ^& "%NODEEXE%" ^& Chr^(34^) ^& " " ^& Chr^(34^) ^& "%INDEXJS%" ^& Chr^(34^), 0, False
            echo Set oShell = Nothing
        ) > "%%f"
        echo   [OK] %%f reparado.
    )
)

echo.
echo   Listo. Intenta iniciar ARKHON de nuevo.
echo.
pause
