@ECHO OFF&PUSHD %~DP0 &TITLE 绿化

:: 安装前结束相关进程避免清不干净
taskkill /f /im QQ* >NUL 2>NUL
taskkill /f /im TXP* >NUL 2>NUL
taskkill /f /im tad* >NUL 2>NUL

:: 开始清理掉后台一些相关残留文件
del /f /q "%TMP%\*.tvl" >NUL 2>NUL
del /f /q "%TMP%\*.tsd" >NUL 2>NUL
del /f /q "%TMP%\ts*.dat" >NUL 2>NUL
del /f /q "%TMP%\QQSa*.exe" >NUL 2>NUL
rd /s /q "%AppData%\Tencent" 2>NUL
rd /s /q "%AppData%\Tencent\QQ" 2>NUL
rd /s /q "%AppData%\Tencent\Logs" 2>NUL
rd /s /q "%AppData%\Tencent\Users" 2>NUL
rd /s /q "%AppData%\Tencent\QTalk" 2>NUL
rd /s /q "%AppData%\Tencent\QQDoctor" 2>NUL
rd /s /q "%AppData%\Tencent\DeskUpdate" 2>NUL
rd /s /q "%ProgramData%\Tencent\QQProtect" 2>NUL
rd /s /q "%AppData%\Tencent\AndroidAssist" 2>NUL
rd /s /q "%AppData%\Tencent\QQPhoneManager" 2>NUL
rd /s /q "%AppData%\Tencent\QQPhoneAssistant" 2>NUL
rd /s /q "%UserProfile%\Documents\Tencent" 2>NUL
rd /s /q "%UserProfile%\My Documents\Tencent" 2>NUL
rd /s /q "%UserProfile%\AppData\LocalLow\QQMiniDL" 2>NUL
rd /s /q "%UserProfile%\AppData\Local\Tencent\QQPet" 2>NUL
rd /s /q "%UserProfile%\Local Settings\Tencent\QQPet" 2>NUL
rd /s /q "%UserProfile%\Local Settings\QQKartLiveUpdate" 2>NUL
rd /s /q "%UserProfile%\Documents\Tencent Files\QPlus" 2>NUL
rd /s /q "%UserProfile%\My Documents\Tencent Files\QPlus" 2>NUL
rd /s /q "%AllUsersProfile%\Application Data\Tencent\QQProtect" 2>NUL
reg delete HKLM\SYSTEM\CurrentControlSet\services\QQProtect /f >NUL 2>NUL

:: 注册SSO核心库、IE及接口快速登录控件
regsvr32 /s Bin\TXSSO\Bin\SSOCommon.dll
regsvr32 /s Bin\TXSSO\Bin\npSSOAxCtrlForPTLogin.dll
:: 注册中转站上传，群共享、微云上传控件
regsvr32 /s Bin\TXSSO\TXFTN\TXFTNActiveX1.17.dll
regsvr32 /s Plugin\Com.Tencent.NetDisk\Bin\QQDisk\Bin\TXFTNActiveX.dll

:: 注册协议：关联网页会话、表情包关联、音乐收听等
if exist Bin\Timwp.dll regsvr32 /s Bin\Timwp.dll
if exist Bin\AppCom.dll regsvr32 /s Bin\AppCom.dll
if exist Bin\CPHelper.dll regsvr32 /s Bin\CPHelper.dll
if exist Bin\TXPFProxy.dll regsvr32 /s Bin\TXPFProxy.dll
if exist Bin\KernelUtil.dll regsvr32 /s Bin\KernelUtil.dll
if exist Bin\TXPlatform.exe Bin\TXPlatform.exe /RegServer
if exist Bin\QQExternal.exe Bin\QQExternal.exe /SetupRegister

:: 传送QQ便签引导，不传送到后台位置则面板图标无法启动
xcopy /s/i/y Bin\TXSSO\QQApp "%AppData%\Tencent\QQ\QQApp" >NUL 2>NUL

:: 设置安装路径，安装视频留言和影音播放等组件下载需要
if not exist "%WinDir%\SysWOW64" reg add HKLM\Software\Tencent\QQ2009 /v Install /d "%~dp0\" /f >NUL
if exist "%WinDir%\SysWOW64" reg add HKLM\Software\Wow6432Node\Tencent\QQ2009 /v Install /d "%~dp0\" /f >NUL

:: 设置安装版本号，企业类型网页会话需要，CRM组件需保留
if not exist "%WinDir%\SysWOW64" reg add HKLM\Software\Tencent\QQ2009 /v version /d "55.21.0.20453.0" /f >NUL
if exist "%WinDir%\SysWOW64" reg add HKLM\Software\Wow6432Node\Tencent\QQ2009 /v version /d "55.21.0.20453.0" /f >NUL

::注册点播控件，直接精简后集成，免去后续安装
regsvr32 /s Bin\TXSSO\QzoneMusic\QzoneMusic.dll
reg add HKCR\Interface\{D9FEA452-F2BD-4ED4-80FC-7814B46915E5}\TypeLib /ve /d "{4560D45A-97D8-47F8-8C0B-09C713FC76F9}" /f >NUL
reg add HKCR\Interface\{D9FEA452-F2BD-4ED4-80FC-7814B46915E5}\ProxyStubClsid32 /ve /d "{00020424-0000-0000-C000-000000000046}" /f >NUL
reg add HKCR\TypeLib\{4560D45A-97D8-47F8-8C0B-09C713FC76F9}\1.0\0\win32 /ve /d "%~dp0Bin\TXSSO\QzoneMusic\QzoneMusic.exe" /f >NUL
reg add HKCR\CLSID\{B45AB714-91D3-4F3D-99A2-D8E6827E2914}\LocalServer32 /ve /d "%~dp0Bin\TXSSO\QzoneMusic\QzoneMusic.exe" /f >NUL

:: 生成个人文件夹保存位置配置文件，让Win7、Win8/8.1或更高版本的系统能正常保存自定义路径！
ver|findstr "5\.[0-9]\.[0-9][0-9]*" > nul && (goto WinXP)
ver|findstr "6\.[0-9]\.[0-9][0-9]*" > nul && (goto Win7+)
ver|findstr "10\.[0-9]\.[0-9][0-9]*" > nul && (goto Win7+)

:WinXP
if not exist "%AllUsersProfile%\Documents\Tencent\QQ" md "%AllUsersProfile%\Documents\Tencent\QQ" 2>NUL
if not exist "%AllUsersProfile%\Documents\Tencent\QQ\UserDataInfo.ini" echo.>"%AllUsersProfile%\Documents\Tencent\QQ\UserDataInfo.ini" 2>NUL
goto DesktopLnk

:Win7+
if not exist "%Public%\Documents\Tencent\QQ" md "%Public%\Documents\Tencent\QQ" 2>NUL
if not exist "%Public%\Documents\Tencent\QQ\UserDataInfo.ini" echo.>"%Public%\Documents\Tencent\QQ\UserDataInfo.ini" 2>NUL
goto DesktopLnk

:DesktopLnk
::提示安装完成了，可选创建桌面快捷方式。
ECHO.&ECHO.完成! 是否创建桌面快捷方式？
ECHO.&ECHO.是请按任意键，否直接关闭吧！&PAUSE >NUL 2>NUL
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\腾讯QQ.lnk""):b.TargetPath=""%~dp0Bin\QQScLauncher.exe"":b.WorkingDirectory=""%~dp0Bin"":b.Save:close")
ECHO.&ECHO.完成! &PAUSE >NUL 2>NUL