@echo off

set TIZEN_SDK_INSTALL_PATH=%INSTALLED_PATH%
set TOOLS_PATH=%TIZEN_SDK_INSTALL_PATH%\tools

:: Make link file
set TEMP_SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
set HOME_PATH=%TOOLS_PATH%\ide\bin
set LINK_FILE=%HOME_PATH%\tizen.lnk
set TARGET_FILE=%HOME_PATH%\tizen.bat

echo Set oWS = WScript.CreateObject("WScript.Shell") >> %TEMP_SCRIPT%
echo LinkFile = "%LINK_FILE%" >> %TEMP_SCRIPT%
echo Set Link = oWS.CreateShortcut(LinkFile) >> %TEMP_SCRIPT%
echo Link.TargetPath = "%TARGET_FILE%" >> %TEMP_SCRIPT%
echo Link.Save >> %TEMP_SCRIPT%

cscript /nologo %TEMP_SCRIPT%
del %TEMP_SCRIPT%

:: Set path for ncli log
setlocal enabledelayedexpansion

set NCLI_CONFIG_PATH=%TOOLS_PATH%\ide\conf-ncli
set NCLI_LOG_FILE=..\ncli.log
set LOG4J_CONFIG=log4j-progress.xml
set LOG4J_CONFIG_PATH=%NCLI_CONFIG_PATH%\%LOG4J_CONFIG%
set PRESET_CONFIG=%NCLI_CONFIG_PATH%\preset_windows.xml

set COUNT=0

(for /F "delims=" %%a in ('type "%LOG4J_CONFIG_PATH%"') do (
   set /a COUNT=!COUNT!+1
   if !COUNT! GTR 2 (
   set "line=%%a"
   set "newline=!line:CLI_LOG_FILE=!"
   if "!newline!" NEQ "!line!" (
      set "newline=        <param name="File" value="%NCLI_LOG_FILE%" />"
      set "newline=!newline:\=\\!"
   )
   echo !newline!
)
)) >> "%PRESET_CONFIG%"

del "%LOG4J_CONFIG_PATH%"
ren "%PRESET_CONFIG%" log4j-progress.xml

