@echo off
REM Licensed Materials - Property of IBM
REM 5648-F10 (C) Copyright International Business Machines Corp. 2010, 2012
REM All Rights Reserved
REM US Government Users Restricted Rights- Use, duplication or disclosure
REM restricted by GSA ADP Schedule Contract with IBM Corp.

title Preparing to start InitTool

rem Prevent multiple instances.
tasklist | find /I "InitTool.exe" && exit

echo Copying application to local disk...

rem Go to BAT real executing path
cd /D %~d0%~p0

set targetDir=%tmp%\initTool

setlocal enabledelayedexpansion

if exist %targetDir% (
    FOR /F "tokens=2 delims=: " %%i in (.\InitTool\launchpad\content\build.txt) do set usbVer=!usbVer!%%i
    FOR /F "tokens=2 delims=: " %%i in (%targetDir%\launchpad\content\build.txt) do set existingVer=!existingVer!%%i
) else goto clearTgtDir

if %usbVer% == %existingVer% if exist %targetDir%\flashdrivepath.txt goto startAPP

:clearTgtDir
if exist %targetDir%  (
    rd /S /Q %targetDir%
)

if not exist %targetDir% mkdir %targetDir%

xcopy /E /Q InitTool\* %targetDir%

:startAPP
rem Write Flash drive path into temporary folder.
echo %cd% > %targetDir%\flashdrivepath.txt

cd /D %targetDir%

echo Start InitTool from local disk...
if exist InitTool.ex1 (
    rename InitTool.ex1 InitTool.exe
)
start InitTool.exe
