@echo off

if "%1"=="" (
title RFTD install batch script
echo ---------------------------------------
echo "|  __ \     /\   | \ | |  ____/ ____|"
echo "| |__) |   /  \  |  \| | |__ | (___  "
echo "|  _  /   / /\ \ | . ` |  __| \___ \ "
echo "| | \ \  / ____ \| |\  | |    ____) |"
echo "|_|  \_\/_/    \_\_| \_|_|   |_____/ "
echo ---------------------------------------
)

echo Check permissions ....
rd "%WinDir%\system32\test_permissions" >NUL 2>NUL
md "%WinDir%\System32\test_permissions" 2>NUL
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
echo Request admin rights...
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B

:gotAdmin
rd "%WinDir%\System32\test_permissions" 2>NUL

cd /d %~dp0
echo Uninstall service ....
call uninstall.bat /b >NUL 2>NUL
call rftd-key.bat /b
call rftd-pwd.bat /b

echo Enable Firewall ...
netsh advfirewall firewall add rule name="RFTD_FTP" dir=in action=allow program="%~dp0\rftd.exe" enable=yes 1>NUL
echo Install rftd service ...
rftd -i
net start rftd

if "%1"==""  pause

