--[[
《 bho左键检测逻辑(同时考虑高低版本问题, 即低版本不覆盖高版本, 除非高版本的响应文件不存在) 》
1. “HKEY_LOCAL_MACHINE\\SOFTWARE\\Thunder Network\\ThunderOem\\thunder_backwnd”的"path"是否正确(拉起thunder.exe的位置)
2. 判断键是否存在: "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects\\{889D2FEB-5411-4565-8998-1DD2C5261283}" 
3. 检测tabRoot['rule']['thuderiePlugin']['items']的clsid在注册表HKCR中对应的信息是否正常

返回值意义：
0 正常，非0 异常
--]]

function CheckIEClickLink(tabRoot)
	if tabRoot == nil then
		return 1
	end
	
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	--当前目录下的thunder.exe路径
	local curExePath = tabRoot['rule']['thuderiePlugin@']['exePath']	
	--注册表“thunder_backwnd”指向的thunder.exe路径
	local regExePath = Obj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Thunder Network\\ThunderOem\\thunder_backwnd", "path")	
	if regExePath == nil then 
		return 1
	end
	local bCurExist = Obj:FileExists(curExePath)
	local bRegExist = Obj:FileExists(regExePath)

	--二者必须都存在
	if not bRegExist or not bCurExist then
		return 1
	end	

	--判断Browser Helper Objects\{889D2FEB-5411-4565-8998-1DD2C5261283} 键是否存在
	local regValue= Obj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects\\{889D2FEB-5411-4565-8998-1DD2C5261283}", "")
	if regValue==nil then
		return 1
	end

	--检测XunleiBHO.dll ThunderAgent.dll在XL7中是否异常
	local xl7BhoDir = tabRoot['rule']['thuderiePlugin@']['instdir']
	if xl7BhoDir == "{nil}" or xl7BhoDir == nil then 
		return 2 
	end 
	local result = VerifyClsidInClassRoot(tabRoot['rule']['thuderiePlugin']['items'], xl7BhoDir, "XL7")
	return result
end

function FixIEClickLink(tabRoot)
	if tabRoot == nil then
		return 1
	end

	local Obj = XLGetObject("Xunlei.OSShell.Obj")			
	
	--修复注册表中的“DownLoadUI”项
	local regValue=Obj:QueryRegValue("HKEY_CURRENT_USER", "SOFTWARE\\Microsoft\\Internet Explorer", "DownLoadUI")
	if regValue==nil or regValue ~= "{802F530B-A8F6-4631-AE49-6BACAAC6373E}" then
		Obj:SetRegValue("HKEY_CURRENT_USER", "SOFTWARE\\Microsoft\\Internet Explorer", "DownLoadUI", 1, "{802F530B-A8F6-4631-AE49-6BACAAC6373E}")
	end

	--修复注册表中的“Browser Helper Objects”项
	local regValue = Obj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects\\{889D2FEB-5411-4565-8998-1DD2C5261283}", "")
	if regValue == nil then
		Obj:SetRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects\\{889D2FEB-5411-4565-8998-1DD2C5261283}", "", 1, "XunleiBHO")
	end
	
	--修复注册表中的“thunder_backwnd”项
	local curExePath = tabRoot['rule']['thuderiePlugin@']['exePath']
	local regExePath = Obj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Thunder Network\\ThunderOem\\thunder_backwnd", "path")
	if regExePath ~= nil and Obj:FileExists(regExePath) then
		--若当前目录的thunder.exe版本 > 注册表指向的thunder.exe版本，则使用curExePath
		if VerCmp(Obj:GetFileVerStr(curExePath), Obj:GetFileVerStr(regExePath)) == 1 then
			Obj:SetRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Thunder Network\\ThunderOem\\thunder_backwnd", "path", 1, curExePath)
		end
	else
		Obj:SetRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Thunder Network\\ThunderOem\\thunder_backwnd", "path", 1, curExePath)
	end
	
	--检测BHO目录下的xunleiBHO.dll ThunderAgent.dll
	local xl7BhoDir = tabRoot['rule']['thuderiePlugin@']['instdir']
	if xl7BhoDir == "{nil}" or xl7BhoDir == nil then 
		return 2 
	end 
	
	local tabItem = tabRoot['rule']['thuderiePlugin']['items']
	for i=1, #tabItem do		
		local clsid = tabItem[i]['item@']['clsid']
		local nameType= tabItem[i]['item@']['nametype']
		local progid = tabItem[i]['item@']['progid']
		local orgDllPath = Obj:PathCombine(xl7BhoDir, tabItem[i]['item@']['name']..".dll")
		
		--对应bho目录下 XunleiBHO.dll ThunderAgent.dll 是否存在
		if not Obj:FileExists(orgDllPath) then
			return 3
		end
		
		--根据nameType生成dll注册后的名字
		local versionedDllPath=""
		if nameType == "0" then
			versionedDllPath= Obj:PathCombine(xl7BhoDir, tabItem[i]['item@']['name'].."_Now.dll")		
		elseif nameType == "1"	then
			local ver = Obj:GetFileVerStr(orgDllPath)			
			versionedDllPath = Obj:PathCombine(xl7BhoDir, tabItem[i]['item@']['name']..tostring(ver)..".dll")
		end
		
		--判断HKEY_CLASSES_ROOT\ThunderAgent.Agent\CLSID 的键值 是否 {485463B7-8FB2-4B3B-B29B-8B919B0EACCE}
		local bForceReg=false
		if progid~=nil then
			local clsidFromReg =  Obj:GetCLSIDFromProgID(progid)
			if clsidFromReg ~= clsid then
				bForceReg=true
			end
		end
		
		--手工修改  HKEY_CLASSES_ROOT\ThunderAgent.Agent\CLSID 的键值
		if bForceReg then
			Obj:SetRegValue("HKEY_CLASSES_ROOT", progid.."\\CLSID", "", 1, clsid)
		end
		
		local regdllpath = Obj:QueryRegValue("HKEY_CLASSES_ROOT", "CLSID\\"..clsid.."\\InprocServer32", "")
		if regdllpath == nil then	--防止regdllpath为nil
			regdllpath = ""
		end
		
		--是否注册表中的版本低于当前目录的dll
		local bIsRegLower = (VerCmp(Obj:GetFileVerStr(versionedDllPath), Obj:GetFileVerStr(regdllpath)) == 1)	
		--注册表中的版本低 或者 regdllpath指向的文件不存在
		if bIsRegLower or not Obj:FileExists(regdllpath) then
			Obj:SetRegValue("HKEY_CLASSES_ROOT", "CLSID\\"..clsid.."\\InprocServer32", "", 1, versionedDllPath)	--手动更改
			SetBHOEnum(orgDllPath, xl7BhoDir)
		end
		
		--标识是否需要注册dll
		local bNeedRegist = false	
		if regdllpath==nil or not Obj:FileExists(regdllpath) or bForceReg==true or bIsRegLower then
			bNeedRegist = true
		end	
		
		--注册dll
		if bNeedRegist then
			if not Obj:XL_IsUACOS() and string.find(string.lower(orgDllPath), "xunleibho") ~= nil then
				local systemdir = Obj:GetSystemPath()
				Obj:ShellExecute(systemdir.."\\regsvr32.exe", " -s \""..orgDllPath.."\"", 0, 1)
			else
				Obj:RegisterDll(orgDllPath) 
			end
		end
				
	end	
	
	--重新检测
	local bCheckResult = CheckIEClickLink(tabRoot)
	return bCheckResult
end

function CheckIERMenu(tabRoot)
	
	if tabRoot == nil then
		return nil
	end
	--XLMessageBox("CheckIERMenu")
	local instdir = tabRoot['rule']['thuderiePlugin@']['instdir']
	if instdir=="{nil}" then return 2 end 
	--XLMessageBox("instdir: "..instdir)
	local result = 0
	local Obj=XLGetObject("Xunlei.OSShell.Obj")
	
	local strGetUrl = instdir.."\\GetUrl.htm"
	local strGetAllUrl = instdir.."\\GetAllUrl.htm"
	if Obj:FileExists(strGetUrl)==false or Obj:FileExists(strGetAllUrl)==false then
		return 3
	end
   --XLMessageBox("strGetUrl = "..strGetUrl)
   --XLMessageBox("strGetAllUrl = "..strGetAllUrl)
	local bCheckGeturl=false
	local bCheckGetallurl=false
	local tabSubkey = Obj:GetRegSubItem("HKEY_CURRENT_USER", "Software\\Microsoft\\Internet Explorer\\MenuExt")
	if tabSubkey==nil then
		result=1
	end
	for i=1, #tabSubkey do
		local strName=Obj:QueryRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..tabSubkey[i], "Name")
		if strName~=nil and string.lower(strName)=="xl_geturl" then
			if bCheckGeturl==true then  --已经检测过，多余的右键菜单
				result=1
			end
			local strValue = Obj:QueryRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..tabSubkey[i], "")
			if strValue==nil or string.lower(strGetUrl)~=string.lower(strValue) then
				--XLMessageBox("url fail!")
				--XLMessageBox("strGetUrl="..strGetUrl.." strValue="..strValue)
				result=1
			elseif Obj:FileExists(strValue)==false then
				return 3
			end
			local dwValue = Obj:QueryRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..tabSubkey[i], "Contexts")
			if dwValue==nil or dwValue~=34  then
				--XLMessageBox("~=34")
				result=1
			end
			bCheckGeturl=true
		elseif strName~=nil and string.lower(strName)=="xl_getallurl" then			
			if bCheckGetallurl==true then	--已经检测过，多余的右键菜单
				result=1
			end	
			local strValue = Obj:QueryRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..tabSubkey[i], "")
			if strValue==nil or string.lower(strGetAllUrl)~=string.lower(strValue) then
				--XLMessageBox("allurl fail!")
				--XLMessageBox("strGetUrl="..strGetUrl.." strValue="..strValue)
				result=1
			elseif Obj:FileExists(strValue)==false then
				return 3
			end
			local dwValue = Obj:QueryRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..tabSubkey[i], "Contexts")
			if dwValue==nil or dwValue~=243  then
				--XLMessageBox("tabSubkey[i] = "..tabSubkey[i])
				--XLMessageBox("~=243")
				result=1
			end
			bCheckGetallurl=true
		end
	end
	if bCheckGetallurl==false or bCheckGeturl==false then 
		result=1 
	end
	
	return result		
end

function FixIERMenu(tabRoot)	
	--XLMessageBox("FixIERMenu")
	if tabRoot == nil then
		return nil
	end
	local instdir = tabRoot['rule']['thuderiePlugin@']['instdir']	
	if instdir == "{nil}" then return 2 end 
	--XLMessageBox("instdir="..instdir)
	local result = 0
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	
	function FixIEMenuExt (tab, strAppPath)
		--XLMessageBox("FixIEMenuExt")
		local strGetUrl = instdir.."\\GetUrl.htm"
		local strGetAllUrl = instdir.."\\GetAllUrl.htm"
		
		--XLMessageBox("strGetUrl = "..strGetUrl)
		--XLMessageBox("strGetAllUrl = "..strGetAllUrl)
		local name1 = tab['rule']['thuderiePlugin']['iemenutxts'][1]['iemenutxt@']['name']	   
		local name2 = tab['rule']['thuderiePlugin']['iemenutxts'][2]['iemenutxt@']['name']
		local bRet =  true
		--先删除所有右键残余链接
		local tabSubkey = Obj:GetRegSubItem("HKEY_CURRENT_USER", "Software\\Microsoft\\Internet Explorer\\MenuExt")
		for i=1, #tabSubkey do
			local strName=Obj:QueryRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\"..tabSubkey[i], "Name")
			if strName~=nil then
				if string.lower(strName)=="xl_geturl" or string.lower(strName)=="xl_getallurl" then
					if Obj:DeleteRegKey("HKEY_CURRENT_USER", "Software\\Microsoft\\Internet Explorer\\MenuExt\\"..tabSubkey[i])==false then
						bRet = false
					end
				end
			end
		end
	   
		-- 修复使用迅雷下载
		
		bRet = Obj:SetRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..name1,  "",  1,  strGetUrl)
		bRet = bRet and Obj:SetRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..name1,  "Contexts",  4,  "34")   		
		bRet = bRet and Obj:SetRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..name1,  "Name",  1,  "xl_geturl")
		--修复使用迅雷下载全部链接    
		bRet = bRet and Obj:SetRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..name2,  "",  1,  strGetAllUrl)
		bRet = bRet and Obj:SetRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..name2,  "Contexts",  4,  "243")   		
		bRet = bRet and Obj:SetRegValue("HKEY_CURRENT_USER",  "Software\\Microsoft\\Internet Explorer\\MenuExt\\" ..name2,  "Name",  1,  "xl_getallurl")
		--XLMessageBox("bRet = "..tostring(bRet))
		return bRet 
	end
			
	if FixIEMenuExt(tabRoot, instdir)==false then
		result = 1
	end
	if CheckIERMenu(tabRoot)==nil or CheckIERMenu(tabRoot)~=0 then
		result = 1 
	else
		result = 0
	end
	--XLMessageBox("result:"..tostring(result))
	return result
end

--检测看看插件
function CheckKankanIEPlugin(tabRoot)
	
	if tabRoot == nil then
		return nil
	end
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	--迅雷5IE 插件

	--防止兼容模式打开
	local bIsVistaOrWin7 = Obj:XL_IsUACOS()
	if bIsVistaOrWin7==false then
		local sysDir = Obj:GetSystemPath()
		local tcpPath = sysDir.."\\drivers\\tcpip.sys"
		local filever = Obj:GetFileVerStr(tcpPath)
		--XLMessageBox(filever:sub(1,1))
		if filever:sub(1,1)=="6" then
			return 0
		end
	end
	
	local result = 0
	for i=0, #tabRoot['rule']['thunderkankanPlugin']['items'] do
		if tabRoot['rule']['thunderkankanPlugin']['items'][i]~=nil then
			local dir = tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['dir']
			if dir == "{nil}" then return 2 end 
			local dllpath=tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['dllpath']
			local dllProgid=tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['progid']
			local bLocalServer=tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['bLocalServer']
			local dllFullpath=dir..dllpath
			if Obj:FileExists(dllFullpath)==false then
				return 3
			end
			local clsid=""
			if dllProgid=="" then			
				clsid = tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['clsid']
			else
				clsid=Obj:GetCLSIDFromProgID(dllProgid)
			end
			if clsid==nil then result=1 end
			local filePath=""
			if bLocalServer=="0" then
				filePath = Obj:QueryRegValue("HKEY_CLASSES_ROOT", "\\CLSID\\"..clsid.."\\InprocServer32", "")
			else
				filePath = Obj:QueryRegValue("HKEY_CLASSES_ROOT", "\\CLSID\\"..clsid.."\\LocalServer32", "")
			end
			if filePath==nil or Obj:FileExists(filePath) == false then
				if bLocalServer=="1" then                          --xmp.exe
					local xmpPath = dir.."Program\\Xmp.exe"
					if Obj:FileExists(xmpPath)==false then
						return 3
					end
				end
				result=1
			end		
		end	
	end	
	--XLMessageBox("result: "..result)
	return result
end

function FixKankanIEPlugin(tabRoot)	
	
	if tabRoot == nil then
		return nil
	end
	--XLMessageBox("FixKankanIEPlugin")
	local Obj = XLGetObject("Xunlei.OSShell.Obj")					
	local result = 0
	
	for i=0, #tabRoot['rule']['thunderkankanPlugin']['items'] do  
		if tabRoot['rule']['thunderkankanPlugin']['items'][i]~=nil then 
			local dir=tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['dir']
			if dir == "{nil}" then return 2 end 
			local dllpath=tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['dllpath']
			local dllProgid=tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['progid']
			local bLocalServer=tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['bLocalServer']
			local clsid=""
			if dllProgid=="" then			
				clsid = tabRoot['rule']['thunderkankanPlugin']['items'][i]['item@']['clsid']
			else
				clsid=Obj:GetCLSIDFromProgID(dllProgid)
			end
			local filePath=""
			if clsid~=nil then
				if bLocalServer=="0" then
					filePath = Obj:QueryRegValue("HKEY_CLASSES_ROOT", "\\CLSID\\"..clsid.."\\InprocServer32", "")
				else
					filePath = Obj:QueryRegValue("HKEY_CLASSES_ROOT", "\\CLSID\\"..clsid.."\\LocalServer32", "")
				end
			end
			if filePath==nil or Obj:FileExists(filePath) == false then
				if Obj:RegisterDll(dir..dllpath)==false then
					result = 1
					break
				end
			end
		end
	end
	local ret=CheckKankanIEPlugin(tabRoot)
	if ret==nil or ret~=0 then
		result = 1
	else
		result = 0 
	end
	return result
	--迅雷5IE 插件	
end
--[[
--暂时注释，以后考虑精简版需要
---------------------------------------
--返回“迅雷精简版”的安装路径，若不存在返回nil
--function GetMiniThunderInstPath()
	local osshellObj = XLGetObject("Xunlei.OSShell.Obj")
	local exePath = osshellObj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Thunder Network\\MiniXLOEM\\thunder", "path");
	if exePath ~= nil and osshellObj:FileExists(exePath) then
		local instPath = osshellObj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Thunder Network\\MiniXLOEM\\thunder", "dir");
		return instPath
	end
	
	return 
end

--检查“迅雷精简版”的“xunleiBho.dll”版本是否高一些
--function IsMiniVersionHigher(xl7BhoVer)
	local osshellObj = XLGetObject("Xunlei.OSShell.Obj")
	local miniInst = GetMiniThunderInstPath()
	
	if miniInst ~= nil then
		local miniDllPath = osshellObj:PathCombine(miniInst,"bho\\MiniXunleiBHO.dll")
		local miniBhoVer = osshellObj:GetFileVerStr(miniDllPath)
		if miniBhoVer ~= nil and xl7BhoVer ~= nil then
			if VerCmp(miniBhoVer, xl7BhoVer) == 1 then		--miniBhoVer > xl7BhoVer
				return true
			end
		end
 	end
	
	return false
end
--]]


--检测tabRoot['rule']['thuderiePlugin']['items']的clsid在注册表HKCR中对应的信息是否正常
--bhoDir：BHO的路径，与checkType相关
--checkType可能取值“XL7”，“MiniThunder”
function VerifyClsidInClassRoot(tabItem, bhoDir, checkType)
	if type(tabItem) ~= "table" then
		return 1
	end
	
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	
	for i=1, #tabItem do
		--若“迅雷精简版”，则加上“Mini”前缀
		if checkType == "MiniThunder" then
			tabItem[i]['item@']['name'] = "Mini"..tabItem[i]['item@']['name']
		end
		
		local nameType = tabItem[i]['item@']['nametype']
		local orgDllPath =  Obj:PathCombine(bhoDir, tabItem[i]['item@']['name']..".dll")
		local progid = tabItem[i]['item@']['progid']
		local clsid = tabItem[i]['item@']['clsid']
		
		--对应bho目录下 XunleiBHO.dll ThunderAgent.dll 是否存在
		if not Obj:FileExists(orgDllPath) then
			return 3
		end
		
		--根据nameType生成dll注册后的名字
		local versionedDllPath=""
		if nameType == "0" then
			versionedDllPath= Obj:PathCombine(bhoDir, tabItem[i]['item@']['name'].."_Now.dll")		
		elseif nameType == "1"	then
			local ver = Obj:GetFileVerStr(orgDllPath)			
			versionedDllPath = Obj:PathCombine(bhoDir, tabItem[i]['item@']['name']..tostring(ver)..".dll")
		end
		
		--判断HKEY_CLASSES_ROOT\ThunderAgent.Agent\CLSID 的键值 是否 {485463B7-8FB2-4B3B-B29B-8B919B0EACCE}
		if progid ~= nil then
			local clsidFromReg =  Obj:GetCLSIDFromProgID(progid)
			if clsidFromReg ~= clsid then
				return 1
			end
		end
		
		--键值对应的dll文件名，是否与同样bho目录下的 （XunleiBHO.dll+版本号）相同
		local regdllpath = Obj:QueryRegValue("HKEY_CLASSES_ROOT", "CLSID\\"..clsid.."\\InprocServer32", "")
		if regdllpath==nil or not Obj:FileExists(regdllpath) then
			return 1
		end
		
		--若当前目录的dll版本 > 注册表指向的dll版本，则返回异常
		if VerCmp(Obj:GetFileVerStr(versionedDllPath), Obj:GetFileVerStr(regdllpath)) == 1 then
			return 1
		end
		
	end
	
	return 0
end

--版本号比较  
--返回值： -1(v1<v2), 0(v1==v2), 1(v1>v2)
function VerCmp(v1, v2)
	if type(v1) ~= "string" or type(v2) ~= "string" then
		return 0
	end
	--分离版本数值
	local tabVer1 = SplitByDot(v1)
	local tabVer2 = SplitByDot(v2)
	--获取最长的表的长度
	local length = #tabVer1
	if #tabVer2 > #tabVer1 then
		length = #tabVer2
	end
	
	local i
	for i=1, length do
		if tabVer1[i] == nil then
			return -1
		end
		if tabVer2[i] == nil then
			return 1
		end
		
		if tabVer1[i] < tabVer2[i] then
			return -1
		elseif tabVer1[i] > tabVer2[i] then
			return 1
		else
			--相等
		end
	end
	
	return 0
end

--将版本号分割，如71.2.36.101分成{71,2,36,101}
function SplitByDot(str)
	local tab = {}
	local pos = 1
	while pos ~= nil do
		table.insert(tab, string.match(str, "^%d+", pos))
		pos = string.find(str, "%.", pos)
		if pos ~= nil then 
			pos = pos + 1
		end
	end
	
	return tab
end

--重设“HKEY_CURRENT_USER\Software\Thunder Network\BHOEnum”，以使低版本的dll能够注册
function SetBHOEnum(orgDllPath, xl7BhoDir)
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	
	local tabVer = SplitByDot(Obj:GetFileVerStr(orgDllPath))
	if tabVer[1] ~= nil and tabVer[4] ~= nil then
		if string.find(string.lower(orgDllPath), "xunleibho") ~= nil then
			Obj:SetRegValue("HKEY_CURRENT_USER", "Software\\Thunder Network\\BHOEnum", "BHOMajVersion", 4, tabVer[1])
			Obj:SetRegValue("HKEY_CURRENT_USER", "Software\\Thunder Network\\BHOEnum", "BHOBuildVersion", 4, tabVer[4])
		elseif string.find(string.lower(orgDllPath), "thunderagent") ~= nil then
			Obj:SetRegValue("HKEY_CURRENT_USER", "Software\\Thunder Network\\BHOEnum", "AgentMajVersion", 4, tabVer[1])
			Obj:SetRegValue("HKEY_CURRENT_USER", "Software\\Thunder Network\\BHOEnum", "AgentBuildVersion", 4, tabVer[4])
		else
			--非法name
		end
		Obj:SetRegValue("HKEY_CURRENT_USER", "Software\\Thunder Network\\BHOEnum", "Thunder7", 1, xl7BhoDir)
	end
end
