@echo off
rem Diagnostico: revisa si esta computadora puede usar SAYC IA. No instala ni cambia nada.
setlocal
cd /d "%~dp0"
set "R=%USERPROFILE%\Desktop\diagnostico_sayc.txt"
echo Diagnostico SAYC IA - %DATE% %TIME% > "%R%"
echo ================================================== >> "%R%"
echo [1] Windows: >> "%R%"
ver >> "%R%"
echo. >> "%R%"
echo [2] Navegadores: >> "%R%"
if exist "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe" (echo OK Edge >> "%R%") else (if exist "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe" (echo OK Edge >> "%R%") else (echo NO Edge >> "%R%"))
if exist "%ProgramFiles%\Google\Chrome\Application\chrome.exe" (echo OK Chrome >> "%R%") else (if exist "%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe" (echo OK Chrome >> "%R%") else (echo NO Chrome >> "%R%"))
echo. >> "%R%"
echo [3] PowerShell: >> "%R%"
powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Output 'OK PowerShell'" >> "%R%" 2>&1
echo. >> "%R%"
echo [4] Motor del programa (se puede ejecutar desde esta carpeta): >> "%R%"
if exist "%~dp0runtime\node.exe" (
  powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -LiteralPath '%~dp0runtime' -Recurse -File | Unblock-File" >nul 2>&1
  "%~dp0runtime\node.exe" -e "console.log('OK motor ' + process.version)" >> "%R%" 2>&1 || echo NO motor: Windows o el antivirus no dejan ejecutarlo >> "%R%"
) else (
  echo Se prueba despues de descomprimir el programa completo. >> "%R%"
)
echo. >> "%R%"
echo [5] Inicio automatico permitido: >> "%R%"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$s=[Environment]::GetFolderPath('Startup'); try { New-Item -ItemType File -Path (Join-Path $s 'sayc_prueba.tmp') -Force | Out-Null; Remove-Item (Join-Path $s 'sayc_prueba.tmp'); 'OK' } catch { 'NO' }" >> "%R%" 2>&1
echo. >> "%R%"
echo [6] Conexion a SAYC y a Copilot: >> "%R%"
powershell -NoProfile -ExecutionPolicy Bypass -Command "foreach($u in 'https://sayc.ccss.sa.cr/SAYC/','https://m365.cloud.microsoft/'){ try { $r=Invoke-WebRequest -Uri $u -UseBasicParsing -TimeoutSec 15; \"OK $u\" } catch { \"NO $u - $($_.Exception.Message)\" } }" >> "%R%" 2>&1
echo ================================================== >> "%R%"
echo Fin. Si todo dice OK, el programa puede usarse en esta computadora. >> "%R%"
start "" notepad "%R%"
