@ECHO OFF

cd /d %~dp0

ECHO AviSynth+ MT (r2508 x86/x64) Installer by Atak_Snajpera
ECHO =======================================================

SET HasAdminRights=0
FOR /F %%i IN ('WHOAMI /PRIV /NH') DO (
	IF "%%i"=="SeTakeOwnershipPrivilege" SET HasAdminRights=1
)

IF NOT %HasAdminRights%==1 (
	ECHO Error:No admin rights detected. 
	ECHO This script must be run as an Administrator.
	ECHO.
	GOTO END
)

if "%ProgramW6432%" == "" (
SET InstallPath="%PROGRAMFILES%\AviSynth+"
) else (
SET InstallPath="%PROGRAMFILES(x86)%\AviSynth+"
)

if "%ProgramW6432%" == "" (

xcopy "AviSynth+" %InstallPath%\ /E /Y
xcopy "Libraries\x86\AviSynth.dll" "%SYSTEMROOT%\System32\" /Y 
xcopy "Libraries\x86\DevIL.dll" "%SYSTEMROOT%\System32\" /Y 

reg import "RegTemplates\AviSynthPlus_x86.reg" 

reg add HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth /ve /d %InstallPath% /f 
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth /v plugindir2_5 /d %InstallPath%\plugins /f 
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth /v plugindir+ /d %InstallPath%\plugins+ /f 

) else (

xcopy "AviSynth+" %InstallPath%\ /E /Y
xcopy "Libraries\x64\AviSynth.dll" "%SYSTEMROOT%\System32\" /Y 
xcopy "Libraries\x86\AviSynth.dll" "%SYSTEMROOT%\SysWOW64\" /Y 
xcopy "Libraries\x64\DevIL.dll" "%SYSTEMROOT%\System32\" /Y 
xcopy "Libraries\x86\DevIL.dll" "%SYSTEMROOT%\SysWOW64\" /Y 

reg import "RegTemplates\AviSynthPlus_x64_x86.reg"

reg add HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth /ve /d %InstallPath% /f 
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth /v plugindir2_5 /d %InstallPath%\plugins64 /f 
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth /v plugindir+ /d %InstallPath%\plugins64+ /f 

reg add HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Avisynth /ve /d %InstallPath% /f 
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Avisynth /v plugindir2_5 /d %InstallPath%\plugins /f 
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Avisynth /v plugindir+ /d %InstallPath%\plugins+ /f 

)

:END
rem pause