@echo off

@rem ========== 用户设置区 ==========

@rem 此处一定要注意！！！目录结尾没有斜杠！！！
@rem 此处一定要注意！！！目录结尾没有斜杠！！！
@rem 此处一定要注意！！！目录结尾没有斜杠！！！

set "SDK_DIR=D:\TI\M0_SDK\mspm0_sdk_2_02_00_05"
set "SYSCFG_DIR=D:\TI\sysconfig"

@rem ==============================

set "PROJ_DIR=%~1"
set "FILE_NAME=%~2"

if "%PROJ_DIR%"=="" goto :usage
if "%FILE_NAME%"=="" goto :usage

set "SYSCFG_FILE=%PROJ_DIR%\%FILE_NAME%"
set "SDK_JSON=%SDK_DIR%\.metadata\product.json"
set "CLI_BAT=%SYSCFG_DIR%\sysconfig_cli.bat"
set "NW_EXE=%SYSCFG_DIR%\nw\nw.exe"

echo ====== Launch SysConfig GUI ======
"%NW_EXE%" "%SYSCFG_DIR%" --compiler keil -s "%SDK_JSON%" "%SYSCFG_FILE%"

echo ====== GUI is closed, run CLI generator ======
"%CLI_BAT%" ^
  -o "%PROJ_DIR%" ^
  -s "%SDK_JSON%" ^
  --compiler keil ^
  "%SYSCFG_FILE%"
goto :eof

:usage
echo Usage: gui_then_cli.bat <directory> <filename.syscfg>
exit /b 1