@echo off
echo off
setlocal EnableDelayedExpansion
rem -----------------------------------------------
rem this shell for an unified installation(window)
rem -----------------------------------------------
set MODE=%1
set AGENT_ROOT=%~dp0
set TASK_NAME="AGENT_ASSIST_TASK"
set file="!AGENT_ROOT!conf\common.conf"
for /f "tokens=3 delims= " %%i in ('findstr /C:"install_path =" %file%') do ( set INSTALL_PATH=%%i)  > nul
for /f "tokens=3 delims= " %%i in ('findstr /C:"python_path =" %file%') do ( set PYTHON_PATH=%%i)  > nul

%PYTHON_PATH% %INSTALL_PATH%\AgentAssist\bin\assist\agentassisthandle\start.py
if %errorlevel% == 1 (
    echo Failed to start the client assistant.
    pause
    exit /b 0
)

schtasks /query /tn %TASK_NAME% >nul 2>nul
if %errorlevel% == 1 (
    SCHTASKS /CREATE /f /sc minute /mo 1 /tn "AGENT_ASSIST_TASK" /ru "System" /tr "%INSTALL_PATH%\AgentAssist\start.bat 'CALLED'" > nul
    schtasks /run /tn %TASK_NAME% > nul
)

echo The client assistant is started successfully.

if !MODE! NEQ "CALLED" (
    pause
)

exit /b 0