@echo off
echo off
setlocal EnableDelayedExpansion
rem -----------------------------------------------
rem this shell for an unified installation(window)
rem -----------------------------------------------
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)
for /f "tokens=3 delims= " %%i in ('findstr /C:"python_path =" %file%') do ( set PYTHON_PATH=%%i)

schtasks /query /tn %TASK_NAME% > nul
if %errorlevel% == 0 (
    schtasks /delete /f /tn %TASK_NAME% > nul
)

%PYTHON_PATH% %INSTALL_PATH%\AgentAssist\bin\agentmanager\uninstall.py
if %errorlevel% == 1 (
    echo "Failed to uninstall the agent assistant."
    pause
    exit /b 0
)

cd !INSTALL_PATH!

call :rd_dirs_files

echo The client assistant is uninstalled successfully.
pause
exit /b 0

:rd_dirs_files

    set dirs_files="%INSTALL_PATH%\PKG" "%INSTALL_PATH%\Subagent" "%AGENT_ROOT%\conf" "c:\\huawei" "%INSTALL_PATH%\AgentAssistPython" "%INSTALL_PATH%\AgentAssist"

    for %%i in (%dirs_files%) do (
        if exist %%i (
            rd /s/q %%i > nul
        )
    )

    goto :EOF
