@echo off
title Assistenza Remota MaxIdea - Configurazione
color 1F
echo ============================================
echo   Assistenza Remota MaxIdea
echo   Configurazione in corso...
echo ============================================
echo.

set SERVER=assistenza.maxidea.it
set KEY=kp2eQwB2uAV480YHDEKBpgHFvUJpFjdEyNJOzVSt7fo=
set PASS=maxidea2026!
set CONFIGDIR=%APPDATA%\RustDesk\config

if not exist "%CONFIGDIR%" mkdir "%CONFIGDIR%"

echo [1/2] Scrittura configurazione server...
(
echo [options]
echo custom-rendezvous-server = '%SERVER%'
echo relay-server = '%SERVER%'
echo key = '%KEY%'
) > "%CONFIGDIR%\RustDesk2.toml"

echo [2/2] Impostazione password e riavvio...
taskkill /f /im rustdesk.exe >nul 2>&1
timeout /t 2 /nobreak >nul

start "" "%~dp0RustDesk-Setup.exe" /SILENT
timeout /t 10 /nobreak >nul

set RDEXE=
if exist "C:\Program Files\RustDesk\rustdesk.exe" set RDEXE=C:\Program Files\RustDesk\rustdesk.exe
if exist "C:\Program Files (x86)\RustDesk\rustdesk.exe" set RDEXE=C:\Program Files (x86)\RustDesk\rustdesk.exe

if defined RDEXE (
    start "" "%RDEXE%" --password %PASS%
)

echo.
echo ============================================
echo   Configurazione completata!
echo ============================================
echo.
echo   RustDesk e' pronto.
echo   Comunica il tuo ID al tecnico MaxIdea.
echo.
pause
