set INSTFILE=V52017U.EXE

if not exist zip.psp goto finished
del zip.psp

strokewd
del \mrscount.*
echo ROMSHELL count > c:\MRSCOUNT.0
attr -r *.bat
attr -r *.exe
filechk %INSTFILE% +0002801563 +0777525619

if errorlevel 1 goto dead

REM Backup copy of VIO.CFG
copy VIO.CFG BACKUP

%INSTFILE% -y

strokewd

REM Restore copy of VIO.CFG
copy BACKUP\VIO.CFG

REM run any train processing auto extractor here

strokewd

:MoveFiles
if exist $LOC24.DAT copy $LOC24.DAT C:\PROGRA~1\AEI\$LOC24.DAT
if exist $LOC24.DAT del $LOC24.DAT

if exist 7za License.txt copy 7za License.txt C:\PROGRA~1\AEI\7za License.txt
if exist 7za License.txt del 7za License.txt

if exist 7za.exe copy 7za.exe C:\PROGRA~1\AEI\7za.exe
if exist 7za.exe del 7za.exe

if exist 800BACK.BAT copy 800BACK.BAT C:\PROGRA~1\AEI\800BACK.BAT
if exist 800BACK.BAT del 800BACK.BAT

if exist 800REST.BAT copy 800REST.BAT C:\PROGRA~1\AEI\800REST.BAT
if exist 800REST.BAT del 800REST.BAT
echo on
REM curl update
if exist *.nls move /y *.nls C:\Windows\SYSTEM32
if exist normaliz.dll move /y normaliz.dll C:\Windows\SYSTEM32

if exist curl.exe move /y curl.exe C:\PROGRA~1\AEI
if exist libcurl.dll move /y libcurl.dll C:\PROGRA~1\AEI
if exist libcurl.dll move /y libcurl.dll C:\PROGRA~1\AEI
if exist CURL_LICENSE move /y CURL_LICENSE C:\PROGRA~1\AEI
if exist OPENSSH_LICENSE move /y OPENSSH_LICENSE C:\PROGRA~1\AEI
if exist OPENSSL_LICENSE move /y OPENSSL_LICENSE C:\PROGRA~1\AEI

if exist INPOUT32.DLL copy INPOUT32.DLL C:\PROGRA~1\AEI\INPOUT32.DLL
REM Do not delete INPOUT32.DLL, we leave a copy in the directory

if exist LXCOMCHK.BAT copy LXCOMCHK.BAT C:\PROGRA~1\AEI\LXCOMCHK.BAT
if exist LXCOMCHK.BAT del LXCOMCHK.BAT

if exist LXCOMCHK.exe copy LXCOMCHK.exe C:\PROGRA~1\AEI\LXCOMCHK.exe
if exist LXCOMCHK.exe del LXCOMCHK.exe

if exist LXSYSCHK.exe copy LXSYSCHK.exe C:\PROGRA~1\AEI\LXSYSCHK.exe
if exist LXSYSCHK.exe del LXSYSCHK.exe

if exist MRRORTXT.BAT copy MRRORTXT.BAT C:\PROGRA~1\AEI\MRRORTXT.BAT
REM Do not delete MRRORTXT.BAT, we leave a copy in the directory

if exist NetMRS.exe copy NetMRS.exe C:\PROGRA~1\AEI\NetMRS.exe
REM Do not delete NetMRS.EXE, we leave a copy in the directory

if exist SlimFTPd License.txt copy SlimFTPd License.txt C:\PROGRA~1\AEI\SlimFTPd License.txt
if exist SlimFTPd License.txt del SlimFTPd License.txt

if exist slimftpd.cfg copy slimftpd.cfg C:\PROGRA~1\AEI\slimftpd.cfg
if exist slimftpd.cfg del slimftpd.cfg

if exist SlimFTPd.exe copy SlimFTPd.exe C:\PROGRA~1\AEI\SlimFTPd.exe
if exist SlimFTPd.exe del SlimFTPd.exe

if exist Validate.exe copy Validate.exe C:\PROGRA~1\AEI\Validate.exe
REM Do not delete Validate.exe, we leave a copy in the directory

if exist Y.DAT copy Y.DAT C:\PROGRA~1\AEI\Y.DAT
REM Do not delete Y.DAT, we leave a copy in the directory

net stop rtxserver /y

if exist WDIDVR.RTS copy WDIDVR.RTS C:\Windows\Rtss\009\WDIDVR.RTS
REM Do not delete WDIDVR.RTS, we leave a copy in the directory

:MoveFilesDone

strokewd

rem remove xtrack parameter file that has xtrack enabled by default
del XTRKSYS.DAT

rem Don't delete distribution file
rem del %INSTFILE%

del dead.dir

if exist SYSPARMS.CRC del SYSPARMS.CRC

if exist REPORT del REPORT\*.* < Y.DAT

:CommitAndReboot
if not exist D:\AEI\ goto end
echo commiting and restarting
ewfmgr C: -commit
xpepm -restart
goto end

:finished
echo NO ZIP.PSP file present
echo If LX800, assuming commit and restart already happened
set INSTFILE=
del "%~f0"
goto end

:dead
echo Failed to load > dead.dir
filechk %INSTFILE% >> dead.dir
goto end

:end

set INSTFILE=
