@echo off
set xxxsrc=bin
if %1==install3 goto install3
if %1==install2 goto install2
if %1==install goto install1
if %1==remove goto remove
if %1==regir50 goto regir50
if %1==sethddmontask goto sethddmon
if %1==rmhddmontask goto rmhddmon
goto end

:install3
set xxxcount=3

set xxxmsg=Installing...phase %xxxcount%
set xxxdst=bin%xxxcount%
echo.
echo %xxxmsg%
if not exist %xxxdst% mkdir %xxxdst%

"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\cdtools" "%xxxdst%\cdtools">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\CustomProfile" "%xxxdst%\CustomProfile">nul
echo 5%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\dialog_pic" "%xxxdst%\dialog_pic">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\digitalPTZ" "%xxxdst%\digitalPTZ">nul
echo 10%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\event_viewer_pic" "%xxxdst%\event_viewer_pic">nul
echo 15%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\pic" "%xxxdst%\pic">nul
echo 20%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\player_pic" "%xxxdst%\player_pic">nul
echo 25%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_pic" "%xxxdst%\ptz_pic">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_pic160" "%xxxdst%\ptz_pic160">nul
echo 30%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_plugin" "%xxxdst%\ptz_plugin">nul
echo 35%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\Resource" "%xxxdst%\Resource">nul
echo 40%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\SmartSearchPic" "%xxxdst%\SmartSearchPic">nul
echo 45%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\Web" "%xxxdst%\Web">nul
echo 50%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ocx" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.del" "%xxxdst%">nul
echo 55%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.dil" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.hm" "%xxxdst%">nul
echo 60%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.hpf" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.mpf" "%xxxdst%">nul
echo 65%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.raw" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.wav" "%xxxdst%">nul
echo 70%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.yuv" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.pem" "%xxxdst%">nul
echo 75%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.cur" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.avi" "%xxxdst%">nul
echo 80%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ico" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.exe" "%xxxdst%">nul
echo 90%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.dll" "%xxxdst%">nul
echo 99%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.bmp" "%xxxdst%">nul

"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\server.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\Live.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\Player.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\FilterGraph.ini" "%xxxdst%">nul
echo 100%%

:install2
set xxxcount=2

set xxxmsg=Installing...phase %xxxcount%
set xxxdst=bin%xxxcount%
echo.
echo %xxxmsg%
if not exist %xxxdst% mkdir %xxxdst%

"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\cdtools" "%xxxdst%\cdtools">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\CustomProfile" "%xxxdst%\CustomProfile">nul
echo 5%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\dialog_pic" "%xxxdst%\dialog_pic">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\digitalPTZ" "%xxxdst%\digitalPTZ">nul
echo 10%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\event_viewer_pic" "%xxxdst%\event_viewer_pic">nul
echo 15%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\pic" "%xxxdst%\pic">nul
echo 20%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\player_pic" "%xxxdst%\player_pic">nul
echo 25%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_pic" "%xxxdst%\ptz_pic">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_pic160" "%xxxdst%\ptz_pic160">nul
echo 30%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_plugin" "%xxxdst%\ptz_plugin">nul
echo 35%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\Resource" "%xxxdst%\Resource">nul
echo 40%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\SmartSearchPic" "%xxxdst%\SmartSearchPic">nul
echo 45%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\Web" "%xxxdst%\Web">nul
echo 50%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ocx" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.del" "%xxxdst%">nul
echo 55%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.dil" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.hm" "%xxxdst%">nul
echo 60%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.hpf" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.mpf" "%xxxdst%">nul
echo 65%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.raw" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.wav" "%xxxdst%">nul
echo 70%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.yuv" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.pem" "%xxxdst%">nul
echo 75%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.cur" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.avi" "%xxxdst%">nul
echo 80%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ico" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.exe" "%xxxdst%">nul
echo 90%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.dll" "%xxxdst%">nul
echo 99%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.bmp" "%xxxdst%">nul

"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\server.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\Live.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\Player.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\FilterGraph.ini" "%xxxdst%">nul
echo 100%%

:install1
set xxxcount=1

:install

set xxxmsg=Installing...phase %xxxcount%
set xxxdst=bin%xxxcount%
echo.
echo %xxxmsg%
if not exist %xxxdst% mkdir %xxxdst%

"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\cdtools" "%xxxdst%\cdtools">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\CustomProfile" "%xxxdst%\CustomProfile">nul
echo 5%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\dialog_pic" "%xxxdst%\dialog_pic">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\digitalPTZ" "%xxxdst%\digitalPTZ">nul
echo 10%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\event_viewer_pic" "%xxxdst%\event_viewer_pic">nul
echo 15%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\pic" "%xxxdst%\pic">nul
echo 20%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\player_pic" "%xxxdst%\player_pic">nul
echo 25%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_pic" "%xxxdst%\ptz_pic">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_pic160" "%xxxdst%\ptz_pic160">nul
echo 30%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\ptz_plugin" "%xxxdst%\ptz_plugin">nul
echo 35%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\Resource" "%xxxdst%\Resource">nul
echo 40%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\SmartSearchPic" "%xxxdst%\SmartSearchPic">nul
echo 45%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\Web" "%xxxdst%\Web">nul
echo 50%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ocx" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.del" "%xxxdst%">nul
echo 55%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.dil" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.hm" "%xxxdst%">nul
echo 60%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.hpf" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.mpf" "%xxxdst%">nul
echo 65%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.raw" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.wav" "%xxxdst%">nul
echo 70%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.yuv" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.pem" "%xxxdst%">nul
echo 75%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.cur" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.avi" "%xxxdst%">nul
echo 80%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.ico" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.exe" "%xxxdst%">nul
echo 90%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.dll" "%xxxdst%">nul
echo 99%%
"%SystemRoot%\system32\xcopy" /e /v /i /h /r /y "%xxxsrc%\*.bmp" "%xxxdst%">nul

"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\server.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\Live.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\Player.ini" "%xxxdst%">nul
"%SystemRoot%\system32\xcopy" /v /r /y "temp\%xxxdst%\FilterGraph.ini" "%xxxdst%">nul
echo 100%%

goto end

:remove
set xxxcount=3
set xxxmsg=Uninstalling...phase %xxxcount%
set xxxdst=bin%xxxcount%
echo %xxxmsg%
if not exist %xxxdst% goto remove2
rmdir /s /q "%xxxdst%\cdtools"
rmdir /s /q "%xxxdst%\dialog_pic"
rmdir /s /q "%xxxdst%\digitalPTZ"
rmdir /s /q "%xxxdst%\event_viewer_pic"
rmdir /s /q "%xxxdst%\pic"
rmdir /s /q "%xxxdst%\player_pic"
rmdir /s /q "%xxxdst%\ptz_pic"
rmdir /s /q "%xxxdst%\ptz_pic160"
rmdir /s /q "%xxxdst%\ptz_plugin"
rmdir /s /q "%xxxdst%\Resource"
rmdir /s /q "%xxxdst%\SmartSearchPic"
rmdir /s /q "%xxxdst%\Web"
del /q "%xxxdst%\*.ocx"
del /q "%xxxdst%\*.del"
del /q "%xxxdst%\*.dil"
del /q "%xxxdst%\*.hm"
del /q "%xxxdst%\*.hpf"
del /q "%xxxdst%\*.mpf"
del /q "%xxxdst%\*.raw"
del /q "%xxxdst%\*.wav"
del /q "%xxxdst%\*.yuv"
del /q "%xxxdst%\*.ini"
del /q "%xxxdst%\*.pem"
del /q "%xxxdst%\*.cur"
del /q "%xxxdst%\*.avi"
del /q "%xxxdst%\*.ico"
del /q "%xxxdst%\*.exe"
del /q "%xxxdst%\*.dll"
del /q "%xxxdst%\*.bmp"

:remove2
set xxxcount=2
set xxxmsg=Uninstalling...phase %xxxcount%
set xxxdst=bin%xxxcount%
echo %xxxmsg%
if not exist %xxxdst% goto remove1
rmdir /s /q "%xxxdst%\cdtools"
rmdir /s /q "%xxxdst%\dialog_pic"
rmdir /s /q "%xxxdst%\digitalPTZ"
rmdir /s /q "%xxxdst%\event_viewer_pic"
rmdir /s /q "%xxxdst%\pic"
rmdir /s /q "%xxxdst%\player_pic"
rmdir /s /q "%xxxdst%\ptz_pic"
rmdir /s /q "%xxxdst%\ptz_pic160"
rmdir /s /q "%xxxdst%\ptz_plugin"
rmdir /s /q "%xxxdst%\Resource"
rmdir /s /q "%xxxdst%\SmartSearchPic"
rmdir /s /q "%xxxdst%\Web"
del /q "%xxxdst%\*.ocx"
del /q "%xxxdst%\*.del"
del /q "%xxxdst%\*.dil"
del /q "%xxxdst%\*.hm"
del /q "%xxxdst%\*.hpf"
del /q "%xxxdst%\*.mpf"
del /q "%xxxdst%\*.raw"
del /q "%xxxdst%\*.wav"
del /q "%xxxdst%\*.yuv"
del /q "%xxxdst%\*.ini"
del /q "%xxxdst%\*.pem"
del /q "%xxxdst%\*.cur"
del /q "%xxxdst%\*.avi"
del /q "%xxxdst%\*.ico"
del /q "%xxxdst%\*.exe"
del /q "%xxxdst%\*.dll"
del /q "%xxxdst%\*.bmp"

:remove1
set xxxcount=1
set xxxmsg=Uninstalling...phase %xxxcount%
set xxxdst=bin%xxxcount%
echo %xxxmsg%
if not exist %xxxdst% goto remove0
rmdir /s /q "%xxxdst%\cdtools"
rmdir /s /q "%xxxdst%\dialog_pic"
rmdir /s /q "%xxxdst%\digitalPTZ"
rmdir /s /q "%xxxdst%\event_viewer_pic"
rmdir /s /q "%xxxdst%\pic"
rmdir /s /q "%xxxdst%\player_pic"
rmdir /s /q "%xxxdst%\ptz_pic"
rmdir /s /q "%xxxdst%\ptz_pic160"
rmdir /s /q "%xxxdst%\ptz_plugin"
rmdir /s /q "%xxxdst%\Resource"
rmdir /s /q "%xxxdst%\SmartSearchPic"
rmdir /s /q "%xxxdst%\Web"
del /q "%xxxdst%\*.ocx"
del /q "%xxxdst%\*.del"
del /q "%xxxdst%\*.dil"
del /q "%xxxdst%\*.hm"
del /q "%xxxdst%\*.hpf"
del /q "%xxxdst%\*.mpf"
del /q "%xxxdst%\*.raw"
del /q "%xxxdst%\*.wav"
del /q "%xxxdst%\*.yuv"
del /q "%xxxdst%\*.ini"
del /q "%xxxdst%\*.pem"
del /q "%xxxdst%\*.cur"
del /q "%xxxdst%\*.avi"
del /q "%xxxdst%\*.ico"
del /q "%xxxdst%\*.exe"
del /q "%xxxdst%\*.dll"
del /q "%xxxdst%\*.bmp"

:remove0
goto end

:regir50
if exist "%SystemRoot%\system32\ir50_32.dll" "%SystemRoot%\system32\regsvr32.exe" /s "%SystemRoot%\system32\ir50_32.dll"
goto end

:sethddmon
echo Creating HDD Monitor scheduled task...
"%SystemRoot%\system32\schtasks.exe" /create /tn hddmon /tr "\%3" /sc ONEVENT /ec Application /mo EventID=65535 /rl HIGHEST
goto end

:rmhddmon
echo Removing HDD Monitor scheduled task...
echo y|"%SystemRoot%\system32\schtasks.exe" /delete /tn hddmon
goto end

:end
echo Done.
