@echo off
%~d0
cd %~dp0
cd ../

set panel_path=%cd%


if "%1%" == "start" (
	goto panel_start
) else if "%1%" == "stop" (
	goto panel_stop
) else if "%1%" == "restart" (
	goto panel_restart
) else if "%1%" == "reload" (
	goto panel_reload
) else if "%1%" == "status" (
	goto panel_status
) else if "%1%" == "logs" (
	goto panel_logs
) else if "%1%" == "default" (
	%panel_path%/aaPanel.exe --cli 14
) else if "%1%" == "open" (
	goto panel_open
) else if "%1%" == "close" (
	goto panel_close
) else if "%1%" == "update" (
	%panel_path%/aaPanel.exe --repair_panel
	goto panel_end
) else if "%1%" == "help" (
	%panel_path%/aaPanel.exe --help
	goto panel_end
) else if "%1%" == "tools" (
	%panel_path%/aaPanel.exe --tools %2%
	goto panel_end
) else (
	%panel_path%/aaPanel.exe --cli %1%
)
goto panel_end
cmd /c dir


:panel_close
echo True>%panel_path%\data\close.pl
goto panel_end


:panel_open
set close_path=%panel_path%\data\close.pl
del %close_path%
goto panel_end

:panel_start
net start aaTask
net start aaPanel
goto panel_end

:panel_stop
net stop aaTask
net stop aaPanel
goto panel_end

:panel_reload
for /f "skip=3 tokens=4" %%i in ('sc query aaPanel') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
    net stop aaPanel
    net start aaPanel
) else (
    net start aaPanel
)
goto panel_end

:panel_restart
for /f "skip=3 tokens=4" %%i in ('sc query aaTask') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
    net stop aaTask
    net start aaTask
) else (
    net start aaTask
)

for /f "skip=3 tokens=4" %%i in ('sc query aaPanel') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
    net stop aaPanel
    net start aaPanel
) else (
    net start aaPanel
)
goto panel_end

:panel_status
goto panel_end


:panel_logs
tail %panel_path%\logs\error.log 

:panel_end
cmd /k
