@echo off
chcp 65001 >nul
title Instalador IPMonitor v3.1
color 0A

echo ==========================================
echo    IPMonitor v3.1 - Instalador
echo    CdC (C) 2026 - insidees.com
echo ==========================================
echo.

set "INSTALL_DIR=%LOCALAPPDATA%\IPMonitor"
set "DESKTOP=%USERPROFILE%\Desktop"
set "STARTMENU=%APPDATA%\Microsoft\Windows\Start Menu\Programs"

echo Directorio de instalacion: %INSTALL_DIR%
echo.

if exist "%INSTALL_DIR%\IPMonitor.exe" (
    echo IPMonitor ya esta instalado. Se actualizara...
    taskkill /F /IM IPMonitor.exe >nul 2>&1
    timeout /t 2 /nobreak >nul
)

echo Creando directorio...
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"

echo Copiando archivos...
xcopy /E /I /Y "publish\*" "%INSTALL_DIR%\" >nul 2>&1

echo Creando accesos directos...
powershell -Command "$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%DESKTOP%\IPMonitor.lnk'); $Shortcut.TargetPath = '%INSTALL_DIR%\IPMonitor.exe'; $Shortcut.WorkingDirectory = '%INSTALL_DIR%'; $Shortcut.IconLocation = '%INSTALL_DIR%\Resources\app_icon.ico'; $Shortcut.Save()" >nul 2>&1

if not exist "%STARTMENU%\IPMonitor" mkdir "%STARTMENU%\IPMonitor"
powershell -Command "$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%STARTMENU%\IPMonitor\IPMonitor.lnk'); $Shortcut.TargetPath = '%INSTALL_DIR%\IPMonitor.exe'; $Shortcut.WorkingDirectory = '%INSTALL_DIR%'; $Shortcut.IconLocation = '%INSTALL_DIR%\Resources\app_icon.ico'; $Shortcut.Save()" >nul 2>&1

echo.
echo ==========================================
echo    Instalacion completada!
echo ==========================================
echo.
echo IPMonitor se ha instalado en:
echo   %INSTALL_DIR%
echo.
echo Accesos directos creados en:
echo   - Escritorio
echo   - Menu Inicio
echo.
pause
