@echo off
REM ##############################################
echo Deleting firewall rules (old names).
netsh advfirewall firewall delete rule name=NxCloud_53_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_80_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_443_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_19003_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_19004_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_UDP19004_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_19003_out > NUL
netsh advfirewall firewall delete rule name=NxCloud_19004_out > NUL
netsh advfirewall firewall delete rule name=NxCloud_UDP19004_out > NUL
REM ##############################################
echo Deleting firewall rules (new names).
netsh advfirewall firewall delete rule name=NxCloud_UDP_53_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_TCP_80_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_TCP_443_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_TCP_19003_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_TCP_19004_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_TCP_19003_out > NUL
netsh advfirewall firewall delete rule name=NxCloud_TCP_19004_out > NUL
netsh advfirewall firewall delete rule name=NxCloud_UDP_19004_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_UDP_19004_out > NUL
netsh advfirewall firewall delete rule name=NxCloud_UDP_67_in > NUL
netsh advfirewall firewall delete rule name=NxCloud_UDP_68_out > NUL
REM ##############################################
echo Adding firewall rules (new names).
netsh advfirewall firewall add rule name=NxCloud_UDP_53_in protocol=UDP dir=in localport=53 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_TCP_80_in protocol=TCP dir=in localport=80 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_TCP_443_in protocol=TCP dir=in localport=443 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_TCP_19003_in protocol=TCP dir=in localport=19003 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_TCP_19004_in protocol=TCP dir=in localport=19004 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_TCP_19003_out protocol=TCP dir=out remoteport=19003 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_TCP_19004_out protocol=TCP dir=out remoteport=19004 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_UDP_19004_in protocol=UDP dir=in localport=19004 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_UDP_19004_out protocol=UDP dir=out remoteport=19004 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_UDP_67_in protocol=UDP dir=in localport=67 action=allow > NUL
netsh advfirewall firewall add rule name=NxCloud_UDP_68_out protocol=UDP dir=out remoteport=68 action=allow > NUL
REM ##############################################
set BPATH=%~dp0
cd %BPATH%
cd ..
REM ##############################################
nxwrapper.exe --startup=auto install
set /p APPNAME=<conf\appname
net start %APPNAME%
cd bin
pause