@echo off
PUSHD %~dp0
color 0a
title Alcohol 120% 辅助安装程序
mode con: cols=70 lines=20

echo .>%windir%\test.txt
if exist %windir%\test.txt (
    del /f /q /a %windir%\test.txt>nul 2>nul
) else (
    cls
    echo.
    echo.
    echo    请右键“以管理员身份运行”本程序
    echo.
    echo    如果有安全软件阻挡了程序的运行
    echo    请先禁用其防护后再运行本程序
    echo.
    echo    按任意键退出...
    pause>nul
    exit
)

set str3=%ProgramFiles%\Alcohol Soft\Alcohol 120
if not "%PROCESSOR_ARCHITECTURE%"=="x86" set str3=%ProgramFiles(x86)%\Alcohol Soft\Alcohol 120

if exist "%str3%\Alcohol.exe" goto next

echo.
echo.
echo    正在安装,请勿关闭本窗口...
echo.
echo.
echo    注意：
echo        1、请安装软件到默认文件夹中。
echo        2、如果安装时提示重新启动，在重启安装完成后，
echo           请再运行一次“Alcohol.cmd”来完成進一步的设置。
echo.

setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /a-d /b Alcohol*.exe 2^>nul') do (set str=%%a)

if exist !str! (
  ver|find /i " 6." >nul&&(regedit /s set64.reg)||(regedit /s set.reg)
  type %windir%\system32\drivers\etc\hosts |find /i "127.0.0.1 www.alcohol-soft.com">nul
  if errorlevel==1 (
    type %windir%\system32\drivers\etc\hosts |find /i "127.0.0.1 support.alcohol-soft.com">nul
    if errorlevel==1 (
        (
        echo.
        echo 127.0.0.1 www.alcohol-soft.com
        echo 127.0.0.1 support.alcohol-soft.com
        echo 127.0.0.1 www.getsystemreport.com
        echo 127.0.0.1 mirror1.free-downloads.net
        echo 127.0.0.1 www.google-analytics.com
        echo 127.0.0.1 www.filefacts.net
        echo 127.0.0.1 serial.alcohol-soft.com
        echo 127.0.0.1 images.alcohol-soft.com
        echo 127.0.0.1 trial.alcohol-soft.com
        echo 127.0.0.1 forum.alcohol-soft.com
        echo 127.0.0.1 users.alcohol-soft.com
        echo 127.0.0.1 shop.alcohol-soft.com
        echo 127.0.0.1 vodka.alcohol-soft.com
        echo ::1 www.getsystemreport.com
        echo ::1 www.alcohol-soft.com
        echo ::1 support.alcohol-soft.com
        echo ::1 mirror1.free-downloads.net
        echo ::1 www.google-analytics.com
        echo ::1 www.filefacts.net
        echo ::1 serial.alcohol-soft.com
        echo ::1 images.alcohol-soft.com
        echo ::1 trial.alcohol-soft.com
        echo ::1 forum.alcohol-soft.com
        echo ::1 users.alcohol-soft.com
        echo ::1 shop.alcohol-soft.com
        echo ::1 vodka.alcohol-soft.com
        )>>%windir%\system32\drivers\etc\hosts
    )
)
    !str!
    if exist "%str3%\Alcohol.exe" goto next
    exit
) else (
    cls
    echo.
    echo.
    echo    当前目录下没有发现 Alcohol 120% 安装程序
    echo    请放置后从新运行本程序
    ping -n 7 127.1 >nul
    exit
)

:next

::导入设置
ver|find /i " 6." >nul&&(regedit /s set64.reg)||(regedit /s set.reg)

::删除插件
del /f /q /a "%temp%\AxSFADownloader.exe" 2>nul

::删除多余语言文件
for /f  %%p in ('dir /a-d /b "%str3%\Langs"^|findstr /v /i "AX_Chs.dll AX_Cht.dll"') do (
    del /f /q /a "%str3%\Langs\%%~nxp" 2>nul
)

::设置刻录速度
copy /y AxType.ini "%str3%" 2>nul

::屏蔽联网地址
type %windir%\system32\drivers\etc\hosts |find /i "127.0.0.1 www.alcohol-soft.com">nul
  if errorlevel==1 (
    type %windir%\system32\drivers\etc\hosts |find /i "127.0.0.1 support.alcohol-soft.com">nul
    if errorlevel==1 (
        (
        echo.
        echo 127.0.0.1 www.alcohol-soft.com
        echo 127.0.0.1 support.alcohol-soft.com
        echo 127.0.0.1 www.getsystemreport.com
        echo 127.0.0.1 mirror1.free-downloads.net
        echo 127.0.0.1 www.google-analytics.com
        echo 127.0.0.1 www.filefacts.net
        echo 127.0.0.1 serial.alcohol-soft.com
        echo 127.0.0.1 images.alcohol-soft.com
        echo 127.0.0.1 trial.alcohol-soft.com
        echo 127.0.0.1 forum.alcohol-soft.com
        echo 127.0.0.1 users.alcohol-soft.com
        echo 127.0.0.1 shop.alcohol-soft.com
        echo 127.0.0.1 vodka.alcohol-soft.com
        echo ::1 www.getsystemreport.com
        echo ::1 www.alcohol-soft.com
        echo ::1 support.alcohol-soft.com
        echo ::1 mirror1.free-downloads.net
        echo ::1 www.google-analytics.com
        echo ::1 www.filefacts.net
        echo ::1 serial.alcohol-soft.com
        echo ::1 images.alcohol-soft.com
        echo ::1 trial.alcohol-soft.com
        echo ::1 forum.alcohol-soft.com
        echo ::1 users.alcohol-soft.com
        echo ::1 shop.alcohol-soft.com
        echo ::1 vodka.alcohol-soft.com
        )>>%windir%\system32\drivers\etc\hosts
    )
)

::系统防火墙阻止联网
reg query "HKLM\SYSTEM\CurrentControlSet\Control" /v SystemStartOptions|find /i "MININT">nul 2>nul&&goto nofirewall

if "%PROCESSOR_ARCHITEW6432%"=="AMD64" (
    set "sys_root=%SystemRoot%\sysnative"
) else (
    set "sys_root=%SystemRoot%\system32"
)

ver|find /i " 5." >nul||(
	if exist %sys_root%\netsh.exe (
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_ACID.exe_Block" dir=out|find "Alcohol_120_ACID.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_ACID.exe_Block" dir=out program="%str3%\ACID.exe" action=block >nul
		)
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_Alcohol.exe_Block" dir=out|find "Alcohol_120_Alcohol.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_Alcohol.exe_Block" dir=out program="%str3%\Alcohol.exe" action=block >nul
		)
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_AxAutoMntSrv.exe_Block" dir=out|find "Alcohol_120_AxAutoMntSrv.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_AxAutoMntSrv.exe_Block" dir=out program="%str3%\AxAutoMntSrv.exe" action=block >nul
		)
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_AxCmd.exe_Block" dir=out|find "Alcohol_120_AxCmd.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_AxCmd.exe_Block" dir=out program="%str3%\AxCmd.exe" action=block >nul
		)
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_AxShlExHlper.exe_Block" dir=out|find "Alcohol_120_AxShlExHlper.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_AxShlExHlper.exe_Block" dir=out program="%str3%\AxShlExHlper.exe" action=block >nul
		)
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_AxSrvUACHlper.exe_Block" dir=out|find "Alcohol_120_AxSrvUACHlper.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_AxSrvUACHlper.exe_Block" dir=out program="%str3%\Plugins\Helper\AxSrvUACHlper.exe" action=block >nul
		)		
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_AxXMLPoster.exe_Block" dir=out|find "Alcohol_120_AxXMLPoster.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_AxXMLPoster.exe_Block" dir=out program="%str3%\Plugins\Helper\AxXMLPoster.exe" action=block >nul
		)
		%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_UACHlper.exe_Block" dir=out|find "Alcohol_120_UACHlper.exe_Block" >nul
		if errorlevel 1 (
			%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_UACHlper.exe_Block" dir=out program="%str3%\Plugins\Helper\UACHlper.exe" action=block >nul
		)
		if not "%PROCESSOR_ARCHITECTURE%"=="x86" (
			%sys_root%\netsh.exe advfirewall firewall show rule name="Alcohol_120_UACHlperx64.exe_Block" dir=out|find "Alcohol_120_UACHlperx64.exe_Block" >nul
			if errorlevel 1 (
				%sys_root%\netsh.exe advfirewall firewall add rule name="Alcohol_120_UACHlperx64.exe_Block" dir=out program="%str3%\Plugins\Helper\UACHlperx64.exe" action=block >nul
			)
		)
	)
)

:nofirewall

cls
echo.
echo.
echo.
echo   已完成安装和设置
ping -n 5 127.1  >nul