@echo off
chcp 65001 >nul
title Actualizador - FV STREAMING AI
color 0B

echo ====================================================
echo        ACTUALIZADOR OFICIAL - FV STREAMING AI
echo ====================================================
echo.

set "TARGET_DIR=%LOCALAPPDATA%\FVStreamingAI"
set "EXE_NAME=FV_Streaming_AI.exe"
set "TARGET_PATH=%TARGET_DIR%\%EXE_NAME%"
set "DOWNLOAD_URL=https://fvstgroup.com/downloads/FV_Streaming_AI.exe"

echo [1/4] Cerrando instancias activas de FV STREAMING AI...
taskkill /F /IM "%EXE_NAME%" >nul 2>&1
timeout /t 1 /nobreak >nul

if not exist "%TARGET_DIR%" (
    mkdir "%TARGET_DIR%"
)

echo [2/4] Descargando version mas reciente desde el servidor oficial...
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%TARGET_PATH%')"

if not exist "%TARGET_PATH%" (
    color 0C
    echo [ERROR] No se pudo descargar la aplicacion. Verifique su conexion.
    pause
    exit /b 1
)

echo [3/4] Creando acceso directo en el Escritorio...
set "DESKTOP_LNK=%USERPROFILE%\Desktop\FV STREAMING AI.lnk"
powershell -Command "$s=(New-Object -COM WScript.Shell).CreateShortcut('%DESKTOP_LNK%');$s.TargetPath='%TARGET_PATH%';$s.WorkingDirectory='%TARGET_DIR%';$s.Save()"

echo [4/4] Actualizacion completada con exito!
echo.
echo Iniciando aplicacion...
start "" "%TARGET_PATH%"

timeout /t 2 /nobreak >nul
exit
