@echo off

REM Solution: dca100021
REM DATE:     2022-06-14

cd %~dp0
set "IIS_RESET=%systemroot%\system32\iisreset.exe"
set "PATCH_LOG_FILE=patch.log"
set "PATCH_ERRLOG_FILE=patch_error.log"
IF EXIST "%PATCH_LOG_FILE%" DEL "%PATCH_LOG_FILE%"
IF EXIST "%PATCH_ERRLOG_FILE%" DEL "%PATCH_ERRLOG_FILE%"


REM Detect if (local)Administrator
OPENFILES >NUL 2>%PATCH_ERRLOG_FILE%
IF ERRORLEVEL 1 (
	echo ERROR: Logged-on user does not have administrative privilege.
	echo Run the CMD Shell as Administrator
	echo *** NOT COMPLETED ***
	PAUSE
	EXIT /B 1
)

REM IF NOT EXIST "%IIS_RESET%" (
REM 	echo ERROR: IIS server NOT exist!!
REM 	echo *** NOT COMPLETED ***
REM 	PAUSE
REM 	EXIT /B 1
REM )

echo Installing PATCHES: >%CD%\%PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%

::Stop IIS server, so that dlls can be overwritten
echo Stop IIS Server...
iisreset /stop

::Start copying files

call:install_object BackupDCA34_dca100021,About.htm,web
call:install_object BackupDCA34_dca100021,UsersLoggedIn.htm,web\OnlineHelp\enduser
call:install_object BackupDCA34_dca100021,filesperapp.asp,web\Applications
call:install_object BackupDCA34_dca100021,SearchCriteria.asp,web\Search
call:install_object BackupDCA34_dca100021,ExpMO1.asp,web\ExportImportMappingRules
call:install_object BackupDCA34_dca100021,ExportObjDocumentation.asp,web\ExportObjDocumentation
call:install_object BackupDCA34_dca100021,GetDetails.asp,web\ExportImportMappingRules
call:install_object BackupDCA34_dca100021,MPRFDetails.asp,web\MigrationProfiles
call:install_object BackupDCA34_dca100021,ModuinContents.asp,web
call:install_object BackupDCA34_dca100021,RootMenu.asp,web
call:install_object BackupDCA34_dca100021,UsersLoggedin.asp,web\Users
call:install_object BackupDCA34_dca100021,simulate.asp,web\ConversionObjects
call:install_object BackupDCA34_dca100021,Exception.asp,web
call:install_object BackupDCA34_dca100021,expPatch.asp,web\ExportImportPatches
call:install_object BackupDCA34_dca100021,SCA22UserMgt.dll,bin
call:install_object BackupDCA34_dca100021,BBCA20HandleMigProf.dll,bin
call:install_object BackupDCA34_dca100021,BBCA20XMLGenerator.dll,bin
call:install_object BackupDCA34_dca100021,BBCA20DDCdll.dll,bin
call:install_object BackupDCA34_dca100021,BBCA20IDDLOADER.dll,bin
call:install_object BackupDCA34_dca100021,BBCA20VerifyMapRules.dll,bin
call:install_object BackupDCA34_dca100021,BBCA20Convdll.dll,shared
call:install_object BackupDCA34_dca100021,BBCA20ScriptGenerator.dll,shared
call:install_object BackupDCA34_dca100021,enrich_db_with_xml.pyc,bin
call:install_object BackupDCA34_dca100021,ddimport_baan.pyc,py\Lib\dcapackage
call:install_object BackupDCA34_dca100021,sharedlibrary.pyc,py\Lib\dcapackage
call:install_object BackupDCA34_dca100021,SlmClient.exe,bin
call:install_object BackupDCA34_dca100021,iBCAUtilities20.exe,bin
call:install_object BackupDCA34_dca100021,BBCA20DBOptions.exe,bin
call:install_object BackupDCA34_dca100021,BBCA20Scheduler.exe,bin
call:install_object BackupDCA34_dca100021,bbca20recoding.exe,bin
call:install_object BackupDCA34_dca100021,BBCA20UserManager.exe,bin
call:install_object BackupDCA34_dca100021,SCA_Debugger.exe,bin
call:install_object BackupDCA34_dca100021,BBCA20BecsCtl.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20Browse.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20CheckedListBoxCtl.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20FunctionBuilder.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20MappingCtrl.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20ShowMapObject.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20SourceQueryControl.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20TreeView.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA20VRCControl.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCA21Functioncontrol.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,BBCALGYMappingControl.CAB,web\library\Controls
call:install_object BackupDCA34_dca100021,PrjMappingControl.CAB,web\library\Controls




echo Start IIS Server...
iisreset /start  >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%

call :check_empty "%PATCH_ERRLOG_FILE%"

Pause
goto:eof

:install_object
REM Par1: SolutionBackupName
REM Par2: Object
REM Par3: ObjectPath

set des=%~1
set object=%~2
set objectext=%~x2
set objectpath=%~3

echo Installing PATCH: %object% >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%

REM unRegister first in case a .dll
IF "%objectext%"==".dll" regsvr32 /u /s "..\%objectpath%\%object%"  >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%

IF NOT EXIST "..\%des%" md "..\%des%"   >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%
IF NOT EXIST "..\%des%\%objectpath%" md "..\%des%\%objectpath%"  >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%

move "..\%objectpath%\%object%"  "..\%des%\%objectpath%\."  >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%
IF ERRORLEVEL 1 (
	echo WARNING: File was not found or could not be moved. >> %PATCH_LOG_FILE%
	echo move "..\%objectpath%\%object%" to "..\%des%\%objectpath%\."  >> %PATCH_LOG_FILE%
)

copy "%objectpath%\%object%" "..\%objectpath%\." >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%

REM Register in case a .dll
IF "%objectext%"==".dll" regsvr32 /s "..\%objectpath%\%object%"  >> %PATCH_LOG_FILE% 2>%PATCH_ERRLOG_FILE%

REM Install py main
IF "%object%"=="py37_main.exe" (
  del /Q "..\%objectpath%\python*.*"  >nul
  del /Q "..\%objectpath%\vcruntime*.*" >nul
  del /S /Q "..\%objectpath%\DLLs\*.*" >nul
  del /S /Q "..\%objectpath%\Lib\*.*" >nul
  call "..\%objectpath%\py37_main.exe" -y >nul
  echo Y|del "..\%objectpath%\py37_main.exe"
)

goto:eof


:check_empty
if %~z1 == 0 (
echo Patch complete. System ready to use...
) ELSE (
echo Patch Errors found see: %~dp0%PATCH_ERRLOG_FILE%
)

goto:eof

:eof

