@rem *********
@rem build.cmd
@rem *********
@rem
@rem Batch script to build the Mettler-Toledo ICS4xx/ICS6xx driver
@rem
@rem Parameter:
@rem
@rem  no_exit  if passed, no exit will be called
@rem

@rem Parse parameters.
@rem -----------------
:loop1
@if /I "%1"=="no_exit"      set NO_EXIT=on
@shift
@if not "%1"=="" goto loop1


rem Build the driver by the driver package builder.
rem -----------------------------------------------
rem Build signed version
cd UsbCdcAcm_Win\V2.15.0\DriverPackageBuilder\
call create_drvpackages.cmd 
if %ERRORLEVEL% NEQ 0 goto exit_error
rem Build also unsigned version
call create_drvpackages.cmd no_sys_signing
if %ERRORLEVEL% NEQ 0 goto exit_error
cd ..\..\..

rem Build the installer.

rem Compiling the installer.
rem ------------------------
cd Mettler-Toledo_ICS4-ICS6_USB_Driver
%NSIS_BIN% Mettler-Toledo_ICS4xx-ICS6xx_USB_Driver.nsi
if %ERRORLEVEL% NEQ 0 goto exit_error
cd..

rem Wait 2 seconds that makensis.exe has time to release the output file.
ping -n 2 127.0.0.1

rem Signing the installer.
rem ----------------------
call UsbCdcAcm_Win\V2.15.0\signing\vendor_sign_files.cmd Mettler-Toledo_ICS4-ICS6_USB_Driver\Mettler-Toledo_ICS4xx-ICS6xx_USB_Driver.exe
if %ERRORLEVEL% NEQ 0 goto exit_error
goto end

:exit_error
@rem Exit with an error
echo "Error occurred!"
if NOT "%NO_EXIT%"=="on" exit 1
goto end 

:end
