@echo OFF

setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\IMAGINiT_Technologies\Clarity_Central_Administrator"

set INSTALLDIR_VALUE_NAME=INSTALLDIR

for /f "tokens=2,*" %%a in ('REG QUERY %KEY_NAME% /v %INSTALLDIR_VALUE_NAME% ^| findstr %INSTALLDIR_VALUE_NAME%') DO (
    set InstallLocation=%%b
)

set LICENSE_TYPE_SELECT_VALUE_NAME=LICENSE_TYPE_SELECT

for /f "tokens=2,*" %%a in ('REG QUERY %KEY_NAME% /v %LICENSE_TYPE_SELECT_VALUE_NAME% ^| findstr %LICENSE_TYPE_SELECT_VALUE_NAME%') DO (
    set LicenseType=%%b
)


if defined InstallLocation (
    @echo Install location: %InstallLocation%

    if defined LicenseType (
        @echo License type: %LicenseType%

        if "%LicenseType%" == "ClaritySecurity" (
            "%InstallLocation%..\Tools\ClaritySecurityConfig\Clarity.SecurityConfig.exe" -UPDATE -COPYCONFIG -ForceInstall -ALL "%InstallLocation%CentralSecurity"
        ) else (
            @echo Clarity security is not installed
        )
    ) else (
        @echo %KEY_NAME%\%LICENSE_TYPE_SELECT_VALUE_NAME% not found.
    )
) else (
    @echo %KEY_NAME%\%INSTALLDIR_VALUE_NAME% not found.
)