@echo off
echo Welcome to EnTrak Installer

SET location=NF
SET batpath=%cd%

rem copy ProjectsList to temporary location 
IF EXIST "C:\Program Files (x86)" (
	chdir /D "C:\Program Files (x86)"
	IF EXIST Ampps (
		SET location=PFx86
	)
	IF EXIST "Ampps\www\EnTrak" (
		ECHO EnTrak already installed, this installer will override the older version
		mkdir "C:\tmp"
		DEL C:\tmp\ProjectsList.csv
		COPY "C:\Program Files (x86)\Ampps\www\EnTrak\EnTrak\ProjectsList.csv" C:\tmp\ProjectsList.csv
		RD /S /Q "C:\Program Files (x86)\Ampps\www\EnTrak"
	)
)
IF EXIST "C:\Program Files" (
	chdir /D "C:\Program Files"
	IF EXIST Ampps (
		SET location=PF
	)
	IF EXIST "Ampps\www\EnTrak" (
		ECHO EnTrak already installed, this installer will override the older version
		mkdir "C:\tmp"
		DEL C:\tmp\ProjectsList.csv
		COPY "C:\Program Files\Ampps\www\EnTrak\EnTrak\ProjectsList.csv" C:\tmp\ProjectsList.csv
		RD /S /Q "C:\Program Files\Ampps\www\EnTrak"
	)
)

cd %batpath%
ECHO BATPATH %batpath%

IF %location% == NF (
	ECHO Ampps is not installed on the system or is not installed in the
	ECHO standard location "Program Files" or "Program Files (x86)"
	ECHO Please install from www.ampps.com before installing EnTrak
)

IF %location% == PFx86 (
	ECHO install to PFx86
	XCOPY /Q "EnTrak" "C:\Program Files (x86)\Ampps\www"  /E /C /R /I /K /Y 
	XCOPY /Q "BatFiles" "C:\Program Files (x86)\Ampps"  /E /C /R /I /K /Y 

rem order of preference of projects list file is 
rem what was copied there ProjectsList.csv previously by this script a few lines up
rem                       PL.csv  = by the updater script
rem                       PLU.csv = by the uninstall script
	IF EXIST "C:\tmp\ProjectsList.csv" MOVE /Y "C:\tmp\ProjectsList.csv" "C:\Program Files (x86)\Ampps\www\EnTrak\EnTrak\ProjectsList.csv"
	IF EXIST "C:\tmp\PL.csv"           MOVE /Y "C:\tmp\PL.csv" "C:\Program Files (x86)\Ampps\www\EnTrak\EnTrak\ProjectsList.csv"
	IF EXIST "C:\tmp\PLU.csv"          MOVE /Y "C:\tmp\PLU.csv" "C:\Program Files (x86)\Ampps\www\EnTrak\EnTrak\ProjectsList.csv"
)

IF %location% == PF (
	ECHO install to PF
	XCOPY /Q "EnTrak" "C:\Program Files\Ampps\www"  /E /C /R /I /K /Y 
	XCOPY /Q "BatFiles" "C:\Program Files\Ampps"  /E /C /R /I /K /Y 
	IF EXIST "C:\tmp\ProjectsList.csv" MOVE /Y "C:\tmp\ProjectsList.csv" "C:\Program Files\Ampps\www\EnTrak\EnTrak\ProjectsList.csv"
	IF EXIST "C:\tmp\PL.csv"           MOVE /Y "C:\tmp\PL.csv" "C:\Program Files\Ampps\www\EnTrak\EnTrak\ProjectsList.csv"
	IF EXIST "C:\tmp\PLU.csv"          MOVE /Y "C:\tmp\PLU.csv" "C:\Program Files\Ampps\www\EnTrak\EnTrak\ProjectsList.csv"
)

rem ECHO batpath is %batpath%
rem ECHO current console location is %cd%
rem ECHO install location is %location%

IF NOT [%1]==[auto] SET/P userinput="... press return(enter) to exit"

rem TIMEOUT 30












