@chcp 936 >nul
@echo off

title 安装好压绿色版x64
set "installpath=%~dp0"
set SafeCenterPath=

:chkadm
pushd "%~dp0"
reg query "HKU\S-1-5-19" >nul 2>nul || ( start "" mshta vbscript:createobject^("shell.application"^).shellexecute^("cmd.exe","/C pushd ""%~dp0"" && ""%~f0""","","runas",1^)^(window.close^) & exit )

systeminfo 2>nul | find /i "x64-based PC" > nul || ( 
  echo 该程序为64位【x64】，与当前系统不兼容，无法安装
  goto out
)

:confirm
echo.
echo 若已安装了【好压官方版】，强烈建议先卸载官方版本，再来执行绿化安装！！！
echo.
echo 按任意键继续绿化安装，或者直接关闭窗口退出
pause > nul
cls

:clean
echo.
echo 若杀毒软件拦截，请放行或者先退出杀毒软件
echo.
echo ☆☆☆☆正在清理旧文件...
net stop HaoZipSvc >nul 2>nul
sc delete HaoZipSvc >nul 2>nul
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\HaoZipSvc" /f >nul 2>nul
reg delete "HKLM\SYSTEM\ControlSet001\Services\HaoZipSvc" /f >nul 2>nul

net stop 2345HaoZip >nul 2>nul
sc delete 2345HaoZip >nul 2>nul
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\2345HaoZip" /f >nul 2>nul
reg delete "HKLM\SYSTEM\ControlSet001\Services\2345HaoZip" /f >nul 2>nul

if exist HaoZipExt64.dll regsvr32 /s /u HaoZipExt64.dll
if exist HaoZipExt.dll regsvr32 /s /u HaoZipExt.dll
if exist HaoZipExt32.dll regsvr32 /s /u HaoZipExt32.dll
reg delete "HKCU\SOFTWARE\2345.com\HaoZip" /f >nul 2>nul
reg delete "HKCU\SOFTWARE\2345.com\Haozip_2345Upgrade" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\HaoZip" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\HaoZip" /f >nul 2>nul
rd /s/q "%AppData%\HaoZip\Application" 2>nul

rd /s/q "%TEMP%\HaoZip" 2>nul
rd /s/q "%AppData%\HaoZip" 2>nul
rd /s/q "%AppData%\Helper_2345" 2>nul
rd /s/q "%AppData%\2345DomainMon" 2>nul

rd /s/q "%installpath%protect" 2>nul
rd /s/q "%installpath%pic" 2>nul
rd /s/q "%installpath%tool" 2>nul
del /f/q "%installpath%2345Uninst.exe" 2>nul
del /f/q "%installpath%libcurl_x64.dll" 2>nul
del /f/q "%installpath%libcurl_x86.dll" 2>nul
del /f/q "%installpath%Haozip_2345Upgrade.dll" 2>nul
del /f/q "%installpath%Haozip_2345Upgrade.exe" 2>nul
del /f/q "%installpath%HaoZipHomePage.exe" 2>nul
del /f/q "%installpath%HaoZipUpdate.exe" 2>nul
del /f/q "%installpath%HaoZipWorker.exe" 2>nul
del /f/q "%installpath%Uninstall.exe" 2>nul

schtasks /delete /tn "Haozip_2345Upgrade Task" /f >nul 2>nul
echo ☆☆☆☆清理完成

for /f "tokens=1,2,* " %%i in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\2345SafeCenter /v UninstallString 2^>nul ^| find /i "UninstallString"') do (set "SafeCenterPath=%%k")
if not "%SafeCenterPath%" == "" if exist "%SafeCenterPath%" (
  rem appwiz.cpl
  echo.
  echo 提示：建议在系统设置或者控制面板中，手动卸载“安全组件 - 2345”。
  goto install
)

for /f "tokens=1,2,* " %%i in ('reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\2345SafeCenter /v UninstallString 2^>nul ^| find /i "UninstallString"') do (set "SafeCenterPath=%%k")
if not "%SafeCenterPath%" == "" if exist "%SafeCenterPath%" (
  rem appwiz.cpl
  echo.
  echo 提示：建议在系统设置或者控制面板中，手动卸载“安全组件 - 2345”。
)

:install
echo.
echo ☆☆☆☆正在安装...
echo 注册HaoZipExt.dll组件
if exist HaoZipExt.dll regsvr32 /s HaoZipExt.dll

echo 执行HaoZipLoader.exe安装
if exist HaoZipLoader.exe "%installpath%HaoZipLoader.exe" -install02 0 7

echo 安装默认配置
if not exist "%AppData%\HaoZip" md "%AppData%\HaoZip"
if exist "config_green\HaoZip.hzc" copy /y /b config_green\HaoZip.hzc "%AppData%\HaoZip\HaoZip.hzc" >nul 2>nul

echo 安装注册信息
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\HaoZip" /v DisplayVersion /t REG_SZ /f /d "6.5.2.11245_x64" >nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\HaoZip" /v DisplayName /t REG_SZ /f /d "好压绿色版" >nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\HaoZip" /v Publisher /t REG_SZ /f /d "2345移动科技" >nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\HaoZip" /v UninstallString /t REG_SZ /f /d "\"%installpath%☆卸载清理.bat\"" >nul 2>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\HaoZip" /v DisplayIcon /t REG_SZ /f /d "%installpath%HaoZip.exe" >nul 2>nul
echo ☆☆☆☆安装完成

:out
echo.
echo 按任意键退出
timeout /t 60 >nul 2>nul || ( 
  pause > nul
)
exit

