@echo off
title Instalando Prestasoft Soporte Remoto
color 0B

REM === Auto-elevar a admin ===
NET FILE 1>NUL 2>NUL
if not '%errorlevel%' == '0' (
  powershell -Command "Start-Process -Verb RunAs -FilePath '%~f0'"
  exit /b
)

set "EXE=%TEMP%\rustdesk-licensed-Qfi8GZuQnZvNXY0NXZyBnLvR3btVmcv8iOzBHd0hmI6ISawFmIsISPw4EZzYFaB12M3RDc6NHd4p3TShTZ5RlYTlWT6RlMudWUpRXMElGZj1mRpJiOikXZrJCLi8GZuQnZvNXY0NXZyBnLvR3btVmciojI0N3boJye.exe"

echo.
echo  =================================================
echo   Prestasoft - Instalador de Soporte Remoto
echo  =================================================
echo.
echo  [1/4] Descargando instalador (RustDesk 1.5.0)...
powershell -NoProfile -Command "[Net.ServicePointManager]::SecurityProtocol = 'Tls12'; Invoke-WebRequest -Uri 'https://descargas.prestasoft.do/windows.exe' -OutFile '%EXE%' -UseBasicParsing" || (echo  Error descargando RustDesk & pause & exit /b 1)
echo       OK

echo  [2/4] Instalando aplicacion (el nombre del archivo ya trae la configuracion)...
"%EXE%" --silent-install
timeout /t 10 /nobreak >NUL
echo       OK

echo  [3/4] Aplicando configuracion del servidor (refuerzo)...
set "CFG_USER=%APPDATA%\RustDesk\config"
set "CFG_SVC=C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config"
if not exist "%CFG_USER%" mkdir "%CFG_USER%"
if not exist "%CFG_SVC%" mkdir "%CFG_SVC%"
powershell -NoProfile -Command "[Net.ServicePointManager]::SecurityProtocol = 'Tls12'; Invoke-WebRequest -Uri 'https://descargas.prestasoft.do/RustDesk2.toml' -OutFile '%CFG_USER%\RustDesk2.toml' -UseBasicParsing"
copy /Y "%CFG_USER%\RustDesk2.toml" "%CFG_SVC%\RustDesk2.toml" >NUL
echo       OK

echo  [4/4] Reiniciando servicio RustDesk...
net stop RustDesk >NUL 2>NUL
timeout /t 2 /nobreak >NUL
net start RustDesk >NUL 2>NUL
del /Q "%EXE%" >NUL 2>NUL
echo       OK

echo.
echo  =================================================
echo   Instalacion completada con exito
echo  =================================================
echo.
echo   El programa quedo conectado al servidor de Prestasoft.
echo   Tu tecnico te pedira el ID de 9 digitos cuando
echo   necesites soporte.
echo.
echo  =================================================
echo.
pause
