@echo off


set LOG_FILE=log\Setup.log

cd /d %~dp0%

if NOT EXIST log (
	mkdir log
)

echo [%date%-%time%] Start: Setupwin.bat >> %LOG_FILE%
echo Set up Web Console Launcher
echo Set up Web Console Launcher >> %LOG_FILE%

set CDIR=%~dp0%

echo Install path: %CDIR%
echo Install path: %CDIR% >> %LOG_FILE%

echo reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher /f >> %LOG_FILE%
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher /f >> %LOG_FILE% 2>&1
IF NOT "%ERRORLEVEL%" == "0" (
GOTO :ERROR
)
echo reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell /f >> %LOG_FILE%
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell /f >> %LOG_FILE% 2>&1
IF NOT "%ERRORLEVEL%" == "0" (
GOTO :ERROR
)
echo reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell\open /f >> %LOG_FILE%
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell\open /f >> %LOG_FILE% 2>&1
IF NOT "%ERRORLEVEL%" == "0" (
GOTO :ERROR
)
echo reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell\open\command /f >> %LOG_FILE%
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell\open\command /f >> %LOG_FILE% 2>&1
IF NOT "%ERRORLEVEL%" == "0" (
GOTO :ERROR
)

echo reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell\open\command /ve /d "\"%CDIR%\WCLauncher.bat\" \"%%1\"" /f >> %LOG_FILE%
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPLauncher\shell\open\command /ve /d "\"%CDIR%\WCLauncher.bat\" \"%%1\"" /f >> %LOG_FILE% 2>&1
IF NOT "%ERRORLEVEL%" == "0" (
GOTO :ERROR
)

echo reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.jnlp /ve /d "JNLPLauncher" /f >> %LOG_FILE%
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.jnlp /ve /d "JNLPLauncher" /f >> %LOG_FILE% 2>&1
IF NOT "%ERRORLEVEL%" == "0" (
GOTO :ERROR
)

echo reg ADD "HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/x-java-jnlp-file" /v "Extension" /d ".jnlp" /f >> %LOG_FILE%
reg ADD "HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/x-java-jnlp-file" /v "Extension" /d ".jnlp" /f >> %LOG_FILE% 2>&1
IF NOT "%ERRORLEVEL%" == "0" (
GOTO :ERROR
)

echo Completed.
echo Completed. >> %LOG_FILE%
echo [%date%-%time%] End(0): UnsetWin.bat >> %LOG_FILE%

exit /b 0

:ERROR

echo Error: Please run as Administrator

echo Error: Please run as Administrator >> %LOG_FILE%
echo [%date%-%time%] End(1): UnsetWin.bat >> %LOG_FILE%

exit /b 1
