@echo off
chcp 65001

%~d0
cd %~dp0

cls

set "CUR_SHELL_DIR=%cd%"
set "JAR_NAME=guthon-file-transfer.jar"
set "SYSTEM_NAME=guthon-file-transfer"
set "JAR_PATH=%CUR_SHELL_DIR%\%JAR_NAME%"
set "JAVA_MEM_OPTS= -server -Xms512m -Xmx4g -Dfile.encoding=UTF-8  -Duser.timezone=GMT+08"
set "LOG_FILE=%CUR_SHELL_DIR%\logs\%JAR_NAME%.log"

if  not exist "%CUR_SHELL_DIR%\logs" (
    mkdir "%CUR_SHELL_DIR%\logs"
)

if exist %CUR_SHELL_DIR%\setevent.bat (
    call %CUR_SHELL_DIR%\setevent.bat
)

set "EXEC_JAVA=java"
if not %JAVA_HOME% == "" (
    set "EXEC_JAVA=%JAVA_HOME%\bin\java"
)

echo ===================================================================
echo =     ____     _   _  _____    _   _     U  ___ u  _   _     
echo =  U /"___|uU |"^|u^| ^|^|_ " _|  |'| |'|     \/"_ \/ ^| \ ^|"|   
echo =  \^| ^|  _ / \^| ^|\^| ^|  ^| ^|   /^| ^|_^| ^|\    ^| ^| ^| ^|^<^|  \^| ^|^>   
echo =   ^| ^|_^| ^|   ^| ^|_^| ^| /^| ^|\  U^|  _  ^|u.-,_^| ^|_^| ^|U^| ^|\  ^|u   
echo =    \____^|  ^<^<\___/ u ^|_^|U   ^|_^| ^|_^|  \_)-\___/  ^|_^| \_^|    
echo =    _)(^|_  (__) )(  _// \\_  //   \\       \\    ^|^|   \\,-. 
echo =   (__)__)     (__)(__) (__)(_") ("_)     (__)   (_")  (_/  
echo = -----------------------------------------------------------------
echo = 谷神文件传输服务正在运行
echo = -----------------------------------------------------------------
echo = JAVA_HOME     : %JAVA_HOME%
echo = JAR_NAME      : %JAR_NAME%
echo = Service path  : %CUR_SHELL_DIR%
echo = Log file path : %CUR_SHELL_DIR%\logs\%JAR_NAME%.log
echo ===================================================================
echo = 
echo = 警告！！不要关闭本窗口，否则服务将中止运行。
echo = Warning!! do not close this window, otherwise the service will stop running.
echo = 控制台日志文件存在[%LOG_FILE%]
echo = The console logs can be viewed at [%LOG_FILE%]

title %SYSTEM_NAME%

del /q /f %LOG_FILE%

%EXEC_JAVA% %JAVA_MEM_OPTS% -jar %JAR_PATH% > %LOG_FILE%

pause