@ECHO OFF&(CD /D "%~DP0")&(>NUL 2>&1 REG QUERY "HKU\S-1-5-19")||(powershell -Command "Start-Process '%~snx0' -Verb RunAs"&&exit)

taskkill /f /im Thunder* >NUL 2>NUL
taskkill /f /im XLLiveUD* >NUL 2>NUL
taskkill /f /im xlbrowsershell*  >NUL 2>NUL
taskkill /f /im DownloadSDKServer* >NUL 2>NUL

::清理相关残留文件
rd/s/q "%TEMP%\Xmp"2>NUL
rd/s/q "%TEMP%\Xunlei"2>NUL
rd/s/q "%TEMP%\Thunder"2>NUL
rd/s/q "%TEMP%\XLLiveUD"2>NUL
rd/s/q "%TEMP%\ThunderLiveUD"2>NUL
rd/s/q "%TEMP%\Thunder Network"2>NUL
rd/s/q "%AppData%\迅雷" 2>NUL
rd/s/q "%AppData%\迅雷X" 2>NUL
rd/s/q "%AppData%\thunder"2>NUL
rd/s/q "%AppData%\thunderx"2>NUL
rd/s/q "%AppData%\XLGameBox"2>NUL
rd/s/q "%AppData%\Thunder Network"2>NUL
del "%ProgramData%\APlayerCodecs3.exe" >NUL 2>NUL
del "%UserProfile%\AppData\APlayerCodecs3.exe" >NUL 2>NUL
del "%AllUsersProfile%\Application Data\APlayerCodecs3.exe" >NUL 2>NUL
del "%AppData%\Microsoft\Windows\Libraries\迅雷下载.library-ms" >NUL 2>NUL
rd/s/q "%ProgramData%\USOShared"2>NUL
rd/s/q "%ProgramData%\USOPrivate"2>NUL
rd/s/q "%ProgramData%\Thunder Network"2>NUL
rd/s/q "%AllUsersProfile%\Xunlei"2>NUL
rd/s/q "%AllUsersProfile%\Thunder Network"2>NUL
rd/s/q "%AllUsersProfile%\Application Data\Xunlei"2>NUL
rd/s/q "%CommonProgramFiles%\Thunder Network"2>NUL
rd/s/q "%CommonProgramFiles(x86)%\Thunder Network"2>NUL
rd/s/q "%UserProfile%\My Documents\Thunder"2>NUL
rd/s/q "%UserProfile%\AppData\LocalLow\XunLei"2>NUL
rd/s/q "%UserProfile%\AppData\LocalLow\XunleiBHO"2>NUL
rd/s/q "%UserProfile%\AppData\LocalLow\Thunder Network"2>NUL
rd/s/q "%UserProfile%\Local Settings\Application Data\Pusher"2>NUL
rd/s/q "%UserProfile%\Local Settings\Application Data\Thunder Network"2>NUL

::阻止后台偷偷上传
ver|findstr "5\.[0-9]\.[0-9][0-9]*" > NUL && (
rd/s/q "%AllUsersProfile%\Application Data\Thunder Network"2>NUL
md "%AllUsersProfile%\Application Data\Thunder Network\cid_store.dat" 2>NUL
md "%AllUsersProfile%\Application Data\Thunder Network\tp_common_info.dat" 2>NUL
md "%AllUsersProfile%\Application Data\Thunder Network\emule_upload_list.dat" 2>NUL
)
ver|findstr "\<6\.[0-9]\.[0-9][0-9]*\> \<10\.[0-9]\.[0-9][0-9]*\>" > NUL && (
rd/s/q "%PUBLIC%\Thunder Network"2>NUL
rd/s/q "%PUBLIC%\Documents\Thunder Network"2>NUL
md "%PUBLIC%\Thunder Network\cid_store.dat" 2>NUL
md "%PUBLIC%\Thunder Network\tp_common_info.dat" 2>NUL
md "%PUBLIC%\Thunder Network\emule_upload_list.dat" 2>NUL
)

::设置软件所在的路径
if /i %PROCESSOR_IDENTIFIER:~0,3%==x86 (
reg add "HKLM\SOFTWARE\Thunder Network\ThunderOem\thunder_backwnd" /f /v "dir /d" "%~dp0\" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Thunder Network\ThunderOem\thunder_backwnd" /f /v "instdir" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Thunder Network\ThunderOem\thunder_backwnd" /f /v "Path" /d "%~dp0Program\Thunder.exe" >NUL 2>NUL 
) else (
reg add "HKLM\SOFTWARE\Wow6432Node\Thunder Network\ThunderOem\thunder_backwnd" /f /v "dir" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Wow6432Node\Thunder Network\ThunderOem\thunder_backwnd" /f /v "instdir" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Wow6432Node\Thunder Network\ThunderOem\thunder_backwnd" /f /v "Path" /d "%~dp0Program\Thunder.exe" >NUL 2>NUL
)

::添加网页右键下载项
reg add "HKCU\SOFTWARE\Microsoft\Internet Explorer\MenuExt\使用迅雷下载" /f /ve /d "%~dp0BHO\geturl.htm"  >NUL 2>NUL
reg add "HKCU\SOFTWARE\Microsoft\Internet Explorer\MenuExt\使用迅雷下载" /f /v "Contexts" /t REG_DWORD /d "0x00000022" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Microsoft\Internet Explorer\MenuExt\使用迅雷下载全部链接" /f /ve /d "%~dp0BHO\getAllurl.htm" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Microsoft\Internet Explorer\MenuExt\使用迅雷下载全部链接" /f /v "Contexts" /t REG_DWORD /d "0x000000f3" >NUL 2>NUL

::注册浏览器关联控件
regsvr32 /s BHO\Platform\np_tdieplat.dll
regsvr32 /s BHO\ThunderAgent.dll
regsvr32 /s BHO\ThunderAgent64.dll

::添加Chrme,firefox扩展程序识别
if /i %PROCESSOR_IDENTIFIER:~0,3%==x86 (
reg add "HKLM\SOFTWARE\MozillaPlugins\@xunlei.com/npxunlei;version=1.0.0.2" /f /v "path" /d "%~dp0BHO\npxunlei.dll" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.xunlei.thunder" /f /ve /d "%~dp0BHO\com.xunlei.thunder.json" >NUL 2>NUL
) else (
reg add "HKLM\SOFTWARE\MozillaPlugins\@xunlei.com/npxunlei;version=1.0.0.2" /f /v "path" /d "%~dp0BHO\npxunlei.dll" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Wow6432Node\MozillaPlugins\@xunlei.com/npxunlei;version=1.0.0.2" /f /v "path" /d "%~dp0BHO\npxunlei.dll" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.xunlei.thunder" /f /ve /d "%~dp0BHO\com.xunlei.thunder.json" >NUL 2>NUL
reg add "HKLM\SOFTWARE\WOW6432Node\Google\Chrome\NativeMessagingHosts\com.xunlei.thunder" /f /ve /d "%~dp0BHO\com.xunlei.thunder.json" >NUL 2>NUL
)

::关联连接协议及临时数据文件
reg add "HKCR\.xltd" /f /ve /d "Xunlei.TDFile.6" >NUL 2>NUL
reg add "HKCR\.downlist" /f /ve /d "Xunlei.LSTFile.6" >NUL 2>NUL
reg add "HKCR\.torrent" /f /ve /d "Xunlei.Bittorrent.6" >NUL 2>NUL
reg add "HKCR\Xunlei.TDFile.6\Shell\Open" /f /ve /d "迅雷临时数据文件" >NUL 2>NUL
reg add "HKCR\Xunlei.TDFile.6\DefaultIcon" /f /ve /d "%~dp0Program\XLTempFile.ico" >NUL 2>NUL
reg add "HKCR\Xunlei.TDFile.6\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\Xunlei.LSTFile.6\Shell\Open" /f /ve /d "使用迅雷下载该任务列表文件" >NUL 2>NUL
reg add "HKCR\Xunlei.LSTFile.6\DefaultIcon" /f /ve /d "%~dp0Program\XLDownloadList.ico" >NUL 2>NUL
reg add "HKCR\Xunlei.LSTFile.6\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\Xunlei.Bittorrent.6\Shell\Open" /f /ve /d "使用迅雷下载该BT文件" >NUL 2>NUL
reg add "HKCR\Xunlei.Bittorrent.6\DefaultIcon" /f /ve /d "%~dp0Program\TorrentFile.ico" >NUL 2>NUL
reg add "HKCR\Xunlei.Bittorrent.6\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\ed2k" /f /ve /d "URL: ed2k Protocol" >NUL 2>NUL
reg add "HKCR\ed2k\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\" -StartType:ed2k" >NUL 2>NUL
reg add "HKCR\magnet" /f /ve /d "URL: Magnet URI" >NUL 2>NUL
reg add "HKCR\magnet" /f /v "Content Type" /d "application/x-magnet" >NUL 2>NUL
reg add "HKCR\magnet\Shell" /f /ve /d "open" >NUL 2>NUL
reg add "HKCR\magnet\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\" -StartType:magnet" >NUL 2>NUL
assoc .=.file >NUL 2>NUL

:: 创建迅雷快捷方式
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""%~dp0\"") & ""Thunder.lnk""):b.TargetPath=""%~dp0Program\Thunder.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\迅雷X.lnk""):b.TargetPath=""%~dp0Program\Thunder.exe"":b.WorkingDirectory=""%~dp0Program"":b.Save:close")

ECHO.&ECHO 完成！&PAUSE>NUL&EXIT