@echo off

SET SCRIPT_DIR=%~dp0
SET EXE_PATH=%SCRIPT_DIR%DDNSUpdater.exe
SET NSSM_PATH=%SCRIPT_DIR%nssm.exe

REM Logs directory
SET LOG_DIR=%SCRIPT_DIR%logs

IF NOT EXIST "%LOG_DIR%" mkdir "%LOG_DIR%"

REM Remove old service (ignore errors)
"%NSSM_PATH%" remove DDNSUpdaterService confirm

REM Install service
"%NSSM_PATH%" install DDNSUpdaterService "%EXE_PATH%"

REM Set auto-start
"%NSSM_PATH%" set DDNSUpdaterService Start SERVICE_AUTO_START

REM 🔥 Redirect output to logs
"%NSSM_PATH%" set DDNSUpdaterService AppStdout "%LOG_DIR%\output.log"
"%NSSM_PATH%" set DDNSUpdaterService AppStderr "%LOG_DIR%\error.log"

REM Optional: rotate logs (prevent huge files)
"%NSSM_PATH%" set DDNSUpdaterService AppRotateFiles 1
"%NSSM_PATH%" set DDNSUpdaterService AppRotateOnline 1

REM Start service
"%NSSM_PATH%" start DDNSUpdaterService

echo Service installed with logging enabled.
pause
