function GetDefaultBrower()
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	local cmdvalue = ""
	local ret = false
	local regpath = "\\http\\shell\\open\\command"
	if Obj:XL_IsUACOS()==true then
		regpath="Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice"
		local value = Obj:QueryRegValue("HKEY_CURRENT_USER", regpath, "Progid")
		ret,cmdvalue = GetShellCmd(value)
	else
		ret,cmdvalue = GetShellCmd("http")
	end
	if ret == false then
		return ""
	end
	local exeName=""
	if string.sub(cmdvalue, 1,1)=="\"" then
		local j = string.find(cmdvalue, "\"", 2)
		if j~=nil then
			exeName = string.lower(string.sub(cmdvalue, 2, j-1))
		end
	else
		local j = string.find(cmdvalue, "%.", 2)
		local k=0
		if j~=nil then
			k = string.find(cmdvalue, "%s", j)
		end
		if k~=nil and k~=0 then
			exeName = string.lower(string.sub(cmdvalue, 1, k-1))
		end
	end
	--XLMessageBox(exeName)
	return exeName
end
function GetShellCmd(regpath)
	if regpath==nil or regpath == "" then
		return  false, ""
	end
	local Obj = XLGetObject("Xunlei.OSShell.Obj")
	local path = regpath.."\\Shell\\open\\command"
	local value = Obj:QueryRegValue("HKEY_CLASSES_ROOT", path, "")
	regpath = value
	if value==nil or value == "" then
		return false, value
	else
		return true, value
	end
end
local function Is360Installed()
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local value = Obj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{23F3F476-BE34-4f48-9C77-2806A8393EC4}", "UninstallString")
	if value==nil or value=="" then
		return false
	else
		return true
	end
end
local function IsTheWorldInstalled(nVer)
	local reg_theworld_uninstall = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{46AA30DF-ED7B-438a-9462-60AB9A6D57E4}"
	if nVer=="2" then
		-- check theworld 2.0
		reg_theworld_uninstall = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{CBE331E3-CB6B-46a3-A669-2C6DABBA2601}"
	end
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local value = Obj:QueryRegValue("HKEY_LOCAL_MACHINE", reg_theworld_uninstall, "UninstallString")
	if value==nil or value=="" then
		return false
	else
		return true
	end
end
local function IsDefaultBrowser360AndNotEnableBho(exeName)
	local isDefault360=false
	if Is360Installed()==false then
		isDefault360 = false
	end
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
--	local exeName = Obj:QueryRegValue("HKEY_CLASSES_ROOT", "http\\shell\\open\\command", "")
--	local exeName = GetDefaultBrower()
	if exeName~=nil and string.find(exeName, "360") ~=nil then
		isDefault360 = true
	else		
		return false
	end
	
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local path = Obj:GetAppDataPath();
	local iniPath = path.."\\360se\\360SE.ini";
	local isBhoEnable = Obj:ReadInteger(iniPath, "IEBhoState", "{889D2FEB-5411-4565-8998-1DD2C5261283}", 0)
	return isDefault360==true --and isBhoEnable==0
end
local function IsDefaultBrowserTheWorldAndNotEnableBho(exeName)	
	local isDefault = false
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	if string.find(exeName, "theworld") ~= nil then
		return true
		--isDefault = true
	else
		return false
	end	
	--HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\[Progid]
	local ver = Obj:GetFileVerStr(exeName)
	local i, j= string.find(ver, "%.")
	if i==nil or i<1 then return true end
	local nVer = string.sub(ver, 1, i-1)	
	
	if IsTheWorldInstalled(nVer)==false then
		isDefault = false
	end
	local isBhoEnable = 0
--		local reg_theworld_uninstall = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{46AA30DF-ED7B-438a-9462-60AB9A6D57E4}"
--		local instdir=Obj:QueryRegValue("HKEY_LOCAL_MACHINE", reg_theworld_uninstall, "InstallLocation")
		--	::SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, szPath);
		--
		local iniPath = Obj:PathAppendLua(exeName, "..\\TheWorld.ini")
--		if instdir~=nil then
		--	local iniPath = instdir.."\\TheWorld.ini";
	if nVer=="3" then
			isBhoEnable = Obj:ReadInteger(iniPath, "IEBhoState", "{889D2FEB-5411-4565-8998-1DD2C5261283}", 0)
--		end
	elseif nVer == "2" then		
			isBhoEnable = Obj:ReadInteger(iniPath, "PlugIn", "{889D2FEB-5411-4565-8998-1DD2C5261283}BHO", 0)
			--XLMessageBox(tostring(isBhoEnable))
	end
	local result = false 
	if  isBhoEnable==0   then
		result = true
	end
	--XLMessageBox(tostring(result))
	return result 
end
local function isExeRun(nFlag)
		local Obj=XLGetObject("Xunlei.OSShell.Obj")
		if  nFlag == 0 and ( Obj:IsProcessExist("360SE.exe")==true or Obj:IsProcessExist("TheWorld.exe")==true ) then
			return true
		elseif nFlag==1 and Obj:IsProcessExist("360SE.exe")==true then
			return true
		elseif nFlag==2 and Obj:IsProcessExist("TheWorld.exe")==true then
			return true
		end
		return false
end
local function _360DefaultIsThunder()	
	if Is360Installed()==false then
		return true
	end 
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local path = Obj:GetAppDataPath();
	local iniPath = path.."\\360se\\extensions\\ExtDownload\\ExtDownload.ini"
	local strValue = Obj:ReadString(iniPath, "Download", "DownProgID", "ThunderAgent.Agent")
	if strValue=="ThunderAgent.Agent" then
		return true
	else
		return false
	end
end

local function _TheWorldDefaultIsThunder(exeName)
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	
	local ver = Obj:GetFileVerStr(exeName)
	local i, j= string.find(ver, "%.")
	if i==nil or i<1 then return true end
	local nVer = string.sub(ver, 1, i-1)	
	--local nVer = string.sub(ver, 1, 1)	
	
	if IsTheWorldInstalled(nVer)==false then
		return true
	end 
	if nVer == "3"	then
		local reg_theworld_uninstall = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{46AA30DF-ED7B-438a-9462-60AB9A6D57E4}"
		local instdir=Obj:QueryRegValue("HKEY_LOCAL_MACHINE", reg_theworld_uninstall, "InstallLocation")
		local iniPath=""
		if instdir~=nil then
			iniPath = instdir.."\\extensions\\ExtDownload\\ExtDownload.ini"
		end
		
		if Obj:XL_IsUACOS()==true then
			local v1,v2,v3,v4 = string.match(ver, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
			local bNewVer=false        --3.2.0.5 以上版本
			if v2>"2" then
				bNewVer = true			
			elseif v2=="2" then
					if v3>"0" then
						bNewVer=true
					elseif v3=="0" then
							if v4>="5" then
								bNewVer = true
							end
					end				
			end
			local path = Obj:GetAppDataPath()
			local Root = string.match(exeName, "%a:\\")
			local systempath = Obj:GetSystemPath()
			local systemroot = string.match(tostring(systempath), "%a:\\")
			if Root==nil or systemroot==nil then
				return true
			end
			if string.lower(Root) == string.lower(systemroot) or bNewVer==false then		
				iniPath = path.."\\TheWorld\\extensions\\ExtDownload\\ExtDownload.ini"
			end
			
		end
		
		local strValue = Obj:ReadString(iniPath, "Download", "DownProgID", "ThunderAgent.Agent")
		if strValue=="ThunderAgent.Agent" then
			return true
		else
			return false
		end
	elseif nVer == "2" then		
		local iniPath = Obj:PathAppendLua(exeName, "..\\TheWorld.ini")
		local value = Obj:ReadString(iniPath, "OPTION", "DownTool", "2")
		if value=="2" then
			local value = Obj:ReadString(iniPath, "OPTION", "DownToolName", "")
			if value=="迅雷5" then
				return true
			else
				return false
			end
		else
			return false
		end
	end
end

local function Set360DefaultThunder()
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local AppDataPath = Obj:GetAppDataPath()
	local iniPath = AppDataPath.."\\360se\\extensions\\ExtDownload\\ExtDownload.ini"
	local bRet = Obj:WriteString(iniPath, "Download", "DownProgID", "ThunderAgent.Agent");
	return bRet	
end

local function SetTheWorldDefaultThunder(exeName)	
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local reg_theworld_uninstall = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{46AA30DF-ED7B-438a-9462-60AB9A6D57E4}"
	local instdir=Obj:QueryRegValue("HKEY_LOCAL_MACHINE", reg_theworld_uninstall, "InstallLocation")
	
	local bRet = false
	local iniPath=""
	local ver = Obj:GetFileVerStr(exeName)
	local i, j= string.find(ver, "%.")
	if i==nil or i<1 then return false end
	local nVer = string.sub(ver, 1, i-1)	
	if nVer == "3"	 then
		if instdir~=nil then
			iniPath = instdir.."\\extensions\\ExtDownload\\ExtDownload.ini"
		else
			return false
		end
		if Obj:XL_IsUACOS()==true then
			local v1,v2,v3,v4 = string.match(ver, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
			local bNewVer=false        --3.2.0.5 以上版本
			if v2>"2" then
				bNewVer = true			
			elseif v2=="2" then
					if v3>"0" then
						bNewVer=true
					elseif v3=="0" then
							if v4>="5" then
								bNewVer = true
							end
					end				
			end
			local path = Obj:GetAppDataPath()
			local Root = string.match(exeName, "%a:\\")
			local systempath = Obj:GetSystemPath()
			local systemroot = string.match(tostring(systempath), "%a:\\")
			if Root==nil or systemroot==nil then
				return true
			end
			if string.lower(Root) == string.lower(systemroot) or bNewVer==false then		
				iniPath = path.."\\TheWorld\\extensions\\ExtDownload\\ExtDownload.ini"
			end
		end
		bRet = Obj:WriteString(iniPath, "Download", "DownProgID", "ThunderAgent.Agent")
	elseif nVer=="2" then
		iniPath = Obj:PathAppendLua(exeName, "..\\TheWorld.ini")
		bRet = Obj:WriteString(iniPath, "OPTION", "DownTool", "2")
		bRet = bRet and Obj:WriteString(iniPath, "OPTION", "DownToolName", "迅雷5")
	end
	return bRet
end


function check_360(exeName)
	local result =0 
	if IsDefaultBrowser360AndNotEnableBho(exeName)==true then
			if _360DefaultIsThunder()==false then
				result = 1
			end
	end
	return result
end

function fix_360(exeName)
	local result = 0
	local i=0 
	local j=0
	while i~=nil do
		j=i
		i=string.find(exeName, "\\", j+1)
	end
	
	local ProcessName = string.sub(exeName, j+1)
	local Obj=XLGetObject("Xunlei.OSShell.Obj")
	if IsDefaultBrowser360AndNotEnableBho(exeName)==true then
			if _360DefaultIsThunder()==false then					
				if Obj:IsProcessExist(ProcessName)==true then
					return 4
				end				
				if Set360DefaultThunder()==false then			
					result = 1
				end
			end
	end
	return result
end

function check_theworld(exeName)
	local result=0
	if IsDefaultBrowserTheWorldAndNotEnableBho(exeName)==true then
			if _TheWorldDefaultIsThunder(exeName)==false then
				result = 1
			end
	end
	return result
end

function fix_theworld(exeName)
	local result=0
	local i=0 
	local j=0
	while i~=nil do
		j=i
		i=string.find(exeName, "\\", j+1)
	end
	
	local ProcessName = string.sub(exeName, j+1)
	local Obj=XLGetObject("Xunlei.OSShell.Obj")
	if IsDefaultBrowserTheWorldAndNotEnableBho(exeName)==true then
			if _TheWorldDefaultIsThunder(exeName)==false then				
				if Obj:IsProcessExist(ProcessName)==true then
					return 4
				end
				if SetTheWorldDefaultThunder(exeName)==false then				
					result = 1
				end
			end
	end
	return result
end

function check_maxthon(exeName, bhoDir)
--	1 maxthon2: ...\\SharedAccount\\Config\\Config.ini      
--安装：
--HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Maxthon2   UninstallString
--设置：
--[Download]
--Downloader=ThunderAgent.Agent.1 or ThunderAgent.Agent
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	
	local ver = Obj:GetFileVerStr(exeName)
	local i, j= string.find(ver, "%.")
	if i==nil or i<1 then return 0 end
	local nVer = string.sub(ver, 1, i-1)	
	if nVer~="2" then return 0 end
--	local dir = Obj:PathAppendLua(exeName, "..")
--	local subdirs = Obj:GetSubDirs(dir)
--	local accontDirs = {}
--	for i=1, #subdirs do
--		XLMessageBox(subdirs[i])
--		local a = subdirs[i]
--		local j = string.find(a, "@")
--		if j~=nil and j>1 then
--			local k = string.find(a, "%.", j+1)
--			if k~=nil and k>j+1 then
--				XLMessageBox("is accont")
--				table.insert(accontDirs, a)
--			end
--		end
--	end
--	XLMessageBox("ok")
--	for i=1, #accontDirs do
--		XLMessageBox(accontDirs[i])
--	end
	local iniPath = Obj:PathAppendLua(exeName, "..\\SharedAccount\\Config\\Config.ini")
	if not Obj:FileExists(iniPath) then 
		--XLMessageBox("file don't exist")
		return 0 
	end
--	local fileatr = Obj:GetFileAttributes(iniPath)
--	--XLMessageBox("fileatr= "..tostring(fileatr))
--	local bRet = Obj:SetFileAttributes(iniPath, 128)
--	--XLMessageBox("bRet= "..tostring(bRet))
	local dlTools = Obj:ReadString(iniPath, "Download", "Downloader", "-none-")
	--XLMessageBox("dlTools="..dlTools)
	if dlTools=="-none-" then
		local ver=""
		local orgDllName = bhoDir.."\\".."xunleiBHO"..".dll"
		ver = Obj:GetFileVerStr(orgDllName)			
		strDllName = bhoDir.."\\".."xunleiBHO"..ver..".dll"
		local bDefalutDownload = false
		local regValue=Obj:QueryRegValue("HKEY_CURRENT_USER","SOFTWARE\\Microsoft\\Internet Explorer", "DownLoadUI")
		if regValue~=nil and regValue=="{802F530B-A8F6-4631-AE49-6BACAAC6373E}" then
			local regdllpath=Obj:QueryRegValue("HKEY_CLASSES_ROOT", "CLSID\\{802F530B-A8F6-4631-AE49-6BACAAC6373E}\\InprocServer32","");
			if regdllpath~=nil and regdllpath~="" and string.lower(regdllpath)==string.lower(strDllName) and Obj:FileExists(regdllpath) then
				bDefalutDownload=true
			end
		elseif regValue==nil then
			local regValue=Obj:QueryRegValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Internet Explorer", "DownLoadUI")
			if regValue~=nil and regValue=="{802F530B-A8F6-4631-AE49-6BACAAC6373E}" then
				local regdllpath=Obj:QueryRegValue("HKEY_CLASSES_ROOT", "CLSID\\{802F530B-A8F6-4631-AE49-6BACAAC6373E}\\InprocServer32","");
				if regdllpath~=nil and regdllpath~="" and string.lower(regdllpath)==string.lower(strDllName) and Obj:FileExists(regdllpath) then
					bDefalutDownload=true
				end
			end
		end		
		if bDefalutDownload==true then
			result=0
		else
			result=1
		end
		return result
	end
	if dlTools~="ThunderAgent.Agent" and dlTools~="ThunderAgent.Agent.1" then
		return 1
	else
		return 0
	end
end
function fix_maxthon(exeName)	
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local iniPath = Obj:PathAppendLua(exeName, "..\\SharedAccount\\Config\\Config.ini")
	--WriteString(iniPath, "Download", "DownProgID", "ThunderAgent.Agent");
	local i=0
	local j=0
	while i~=nil do
		j=i
		i=string.find(exeName, "\\", j+1)
	end
	
	local ProcessName = string.sub(exeName, j+1)
	if Obj:IsProcessExist(ProcessName)==true then
		return 4
	end	
	
	local dir = Obj:PathAppendLua(exeName, "..")
	local subdirs = Obj:GetSubDirs(dir)
	local accontDirs = {}
	for i=1, #subdirs do
		--XLMessageBox(subdirs[i])
		local a = subdirs[i]
		local j = string.find(a, "@")
		if j~=nil and j>1 then
			local k = string.find(a, "%.", j+1)
			if k~=nil and k>j+1 then
				--XLMessageBox("is accont")
				table.insert(accontDirs, a)
			end
		end
	end
	--XLMessageBox("ok")
	
	local ret = Obj:WriteString(iniPath, "Download", "Downloader", "ThunderAgent.Agent.1")
	ret = ret and Obj:WriteString(iniPath, "Download", "AllFileType", "1")
	for i=1, #accontDirs do
		local iniPath = Obj:PathAppendLua(exeName, "..\\"..accontDirs[i].."\\Config\\Config.ini")
		if Obj:FileExists(iniPath) then
			ret = ret and Obj:WriteString(iniPath, "Download", "Downloader", "ThunderAgent.Agent.1")
			ret = ret and Obj:WriteString(iniPath, "Download", "AllFileType", "1")
		end
		--XLMessageBox(accontDirs[i])
	end
	if ret~=true then
		return 1
	else
		return 0
	end
end

function check_firefox(exeName)		
	--"D:\Program Files\Mozilla Firefox\firefox.exe" -requestPending -osint -url "%1"
	
	local Obj = XLGetObject("Xunlei.OSShell.Obj")	
	local ver = Obj:GetFileVerStr(exeName)
	local i, j= string.find(ver, "%.")
	if i==nil or i<1 then return 0 end
	local nVer = string.sub(ver, 1, i-1)	
	local nver = nVer + 0
	if nver>1 then return 0 end
	local path = Obj:GetAppDataPath()
	local iniPath = path.."\\Mozilla\\Firefox\\profiles.ini"
	local Sections={}
	Sections=Obj:ReadSections(iniPath)
	local section="Profile0"
	for i=1,#Sections do 
		--XLMessageBox(Sections[i])
		local nDefault = Obj:ReadInteger(iniPath, Sections[i], "default", 0)
		if nDefault==1 then
			section=Sections[i]
			break
		end
	end
	local strValue = Obj:ReadStringUtf8(iniPath, section, "Path", "")
	if strValue=="" then return 0 end
	local binstall = false
	local i= string.match(strValue, "^%a:\\")
	local dir=""	
	if i~=nil then		
		dir=strValue
	else		
	 	dir= path.."\\Mozilla\\Firefox\\"..strValue
	end
	local instrdf=dir.."\\extensions\\{1B33E42F-EF14-4cd3-B6DC-174571C4349C}\\install.rdf"  --是否安装
	if Obj:FileExists(instrdf) then binstall=true end
	local extrdf=dir.."\\extensions.rdf"
	--XLMessageBox("wait!")	
	--local extrdf="D:\\xl_doctor_client\\bin\\debug\\DefaultRule\\Config.xml
	if Obj:FileExists(extrdf)==false then 
		return 0 
	end
	local tabHead = Obj:GetXmlTable(extrdf)
	local result=1
	if tabHead~=nil and tabHead['RDF:RDF']~=nil then
		for i=0, #tabHead['RDF:RDF'] do
			if tabHead['RDF:RDF'][i]~=nil  and tabHead['RDF:RDF'][i]['RDF:Description']~=nil then
				local about = tabHead['RDF:RDF'][i]['RDF:Description@']['RDF:about']
				if about~=nil and string.find(about, "{1B33E42F%-EF14%-4cd3%-B6DC%-174571C4349C}") then
					local disable = tabHead['RDF:RDF'][i]['RDF:Description@']['NS1:userDisabled']
					if disable~=nil then 
						if disable=="true" or disable=="needs-disable" then
							return 1
						end
					end
					local installLocation = tabHead['RDF:RDF'][i]['RDF:Description@']['NS1:installLocation']
					if installLocation=="app-profile" then 
						return 0
					elseif binstall==false then
						return 1
					end
					result=0
					break
				end
			end
		end
	else
		return 0
	end
	return result
end
function fix_firefox(exeName, FixExePath)
	--NS1:userDisabled="needs-enable">
	local Obj = XLGetObject("Xunlei.OSShell.Obj")		
	
	local i=0
	local j=0
	while i~=nil do
		j=i
		i=string.find(exeName, "\\", j+1)
	end
	
	local path = Obj:GetAppDataPath()
	local iniPath = path.."\\Mozilla\\Firefox\\profiles.ini"
	local Sections={}
	Sections=Obj:ReadSections(iniPath)
	local section="Profile0"
	for i=1,#Sections do 
		--XLMessageBox(Sections[i])
		local nDefault = Obj:ReadInteger(iniPath, Sections[i], "default", 0)
		if nDefault==1 then
			section=Sections[i]
			break
		end
	end
	local strValue = Obj:ReadStringUtf8(iniPath, section, "Path", "")
	if strValue=="" then return 0 end
	
	local i= string.match(strValue, "^%a:\\")
	local dir=""	
	if i~=nil then		
		dir=strValue
	else		
	 	dir= path.."\\Mozilla\\Firefox\\"..strValue
	end
	
	local instrdf=dir.."\\extensions\\{1B33E42F-EF14-4cd3-B6DC-174571C4349C}\\install.rdf"  --是否安装
	local extrdf=dir.."\\extensions.rdf"
	if Obj:FileExists(instrdf) and Obj:FileExists(extrdf) then 		
		local tabHead = Obj:GetXmlTable(extrdf)
		--XLMessageBox("wait!")
		--local extrdf="D:\\xl_doctor_client\\bin\\debug\\DefaultRule\\Config.xml"		
		local result=0
		if tabHead~=nil and tabHead['RDF:RDF']~=nil then
			for i=0, #tabHead['RDF:RDF'] do
				if tabHead['RDF:RDF'][i]~=nil  and tabHead['RDF:RDF'][i]['RDF:Description']~=nil then
					local about = tabHead['RDF:RDF'][i]['RDF:Description@']['RDF:about']
					if about~=nil and string.find(about, "{1B33E42F%-EF14%-4cd3%-B6DC%-174571C4349C}") then
						local disable = tabHead['RDF:RDF'][i]['RDF:Description@']['NS1:userDisabled']
						if disable~=nil  then
							local ProcessName = string.sub(exeName, j+1)
							if Obj:IsProcessExist(ProcessName)==true then
								return 4
							end		
							if disable=="true" then
								local cache=Obj:PathAppendLua(extrdf, "..\\extensions.cache")
								Obj:DeleteFile(cache)
								tabHead['RDF:RDF'][i]['RDF:Description@']['NS1:userDisabled']="needs-enable"
							elseif disable=="needs-disable" then
								tabHead['RDF:RDF'][i]['RDF:Description@']['NS1:userDisabled']=nil 
							end
						end
						break
					end
				end
			end
			local ret = Obj:SetXml(extrdf, tabHead)
			return 0		
		end
	end
	
	local thunderxpi = Obj:PathAppendLua(FixExePath, "..\\thunder.xpi")
	if Obj:FileExists(thunderxpi)==false then return 1 end
	local cmdline = "\""..thunderxpi.."\""
	Obj:ShellExecute(exeName, cmdline, 0, 0)
	local ProcessName = string.sub(exeName, j+1)
	if Obj:IsProcessExist(ProcessName)==true then
		return 0
	else 
		return 1
	end		
--	local cmdline = "\""..thunderxpi
--	--XLMessageBox(cmdline)
--	local ret=Obj:ShellExecute(exeName, cmdline, 0)
--	if ret==true then		
--		tabHead = Obj:GetXmlTable(extrdf)
--		for i=1, #tabHead['RDF:RDF'] do
--			if tabHead['RDF:RDF'][i]['RDF:Description']~=nil then
--				local about = tabHead['RDF:RDF'][i]['RDF:Description@']['RDF:about']
--				if about~=nil and string.find(about, "{1B33E42F%-EF14%-4cd3%-B6DC%-174571C4349C}") then
--					return 0
--				end
--			end
--		end
--	end
	return 1
end

function check_opera(exeName, FixExePath)
	local operaapptype={{"application/7z","7","7z"},{"application/cab","7","cab"},{"application/iso","7","iso"},
	{"application/msi","7","msi"},{"application/rar","7","rar"},{"application/rmvb","7","rmvb"},{"application/x-gtar","7","gtar,tar"},
	{"application/x-msdos-program","7","exe,bat,pif,com,scr"},{"application/x-pn-realmedia","7","rm"},{"application/x-rar-compressed","7","rar"},
	{"application/x-tar","7","tar,tgz,gz,bz2"},{"application/zip","7","zip"},{"application/x-zip-compressed","7","zip"},{"application/x-msdownload","7","exe,bat,pif,com,scr"},
	{"audio/mp3","7","mp3"},{"audio/x-mpeg","7","mp3"}}
	local Obj=XLGetObject("Xunlei.OSShell.Obj")
	local ver= Obj:GetFileVerStr(exeName)
	--XLMessageBox(ver)
	local i, j= string.find(ver, "%.")
	if i==nil or i==1 then return 0  end	
	local nVer = string.sub(ver, 1, i-1)
	--XLMessageBox(nVer)
	local opval9={"operadef6.ini","\\profile\\opera6.ini","defaults\\standard_menu.ini"};
	local opval10={"operaprefs_default.ini","\\operaprefs.ini","ui\\standard_menu.ini"}
	local opval={}
	if nVer=="9" then
		opval=opval9
	elseif nVer=="10" then		
		opval=opval10
	else
		return 0
	end
	--XLMessageBox(opval[1])
--	local dir=Obj:PathAppendLua(exeName, "../")
	--XLMessageBox(Obj:PathAppendLua(exeName, "..\\"..opval[1]))
	local uMultiUser=Obj:ReadInteger(Obj:PathAppendLua(exeName, "..\\"..opval[1]), "System", "Multi User", 0)
	--XLMessageBox("Multi="..tostring(uMultiUser))
--	UINT uMultiUser = GetPrivateProfileInt("System", "Multi User", 0, (szBrowser + szPrefile).c_str());

	local strProfile=""
	
	local i=0 
	local j=0
	local k=0
	while i~=nil do
		k=j
		j=i
		i=string.find(exeName, "\\", j+1)
	end

	local dirname = string.sub(exeName, k+1, j-1)
	local AppDataPath=Obj:GetAppDataPath()	
	if AppDataPath==nil then return 1 end
	if uMultiUser==0 then
			strProfile = Obj:PathAppendLua(exeName, ".."..opval[2])
	else			
			strProfile = AppDataPath.."\\Opera\\"..dirname..opval[2]			
	end
	--XLMessageBox(strProfile)
	if nVer=="10" then		
		local value = Obj:ReadStringUtf8(strProfile, "User Prefs", "Use External Download Manager", "");
		if value~="1" then 
			return 1
		end
		value = Obj:ReadStringUtf8(strProfile, "User Prefs", "Download Manager", "")
		if value~="迅雷7" then 
			return 1 
		end
	end
	local result=true
	for i=1,#operaapptype do 
		local value = Obj:ReadStringUtf8(strProfile, "File Types", operaapptype[i][1], "");
		local rightvalue=operaapptype[i][2]..","..FixExePath..",,,"..operaapptype[i][3]..",|"
		--XLMessageBox(value)
		--XLMessageBox(rightvalue)
		if value~=rightvalue then
			result = false
			return 1
			--break
		end
	end
	--XLMessageBox("result="..tostring(result))
	--local menuiniPath = Obj:PathAppendLua(strProfile, "..\\menu\\menu_thunder.ini")
	local menuiniPath=Obj:ReadStringUtf8(strProfile, "User Prefs", "Menu Configuration", "")
	--XLMessageBox("valu= "..value)
	--XLMessageBox("menuiniPath="..menuiniPath)
	if menuiniPath==nil or Obj:FileExists(menuiniPath)==false then --or string.lower(menuiniPath) ~=string.lower(value)  then
		return 1
	end


	
	local value=Obj:ReadStringUtf8(menuiniPath, "Link Popup Menu", "Item,\"使用迅雷下载\"","")
	--XLMessageBox("value="..value)
	if value~="Execute Program, \""..FixExePath.."\", \"@%l %u\"" then
		return 1
	end
	local value=Obj:ReadStringUtf8(menuiniPath, "Image Link Popup Menu", "Item,\"使用迅雷下载\"","")
	--XLMessageBox("value="..value)
	if value~="Execute Program, \""..FixExePath.."\", \"@%l %u\"" then
		return 1
	end
	local value=Obj:ReadStringUtf8(menuiniPath, "Image Popup Menu", "Item,\"使用迅雷下载\"","")
	--XLMessageBox("value="..value)
	if value~="Copy image address & Execute Program, \""..FixExePath.."\", \"@%c %u\"" then
		return 1
	end
	local value=Obj:ReadStringUtf8(menuiniPath, "Document Popup Menu", "Item,\"使用迅雷下载全部链接\"","")
	--XLMessageBox("value="..value)
	if value~="Execute Program, \""..FixExePath.."\", \"#%s %u\"" then
		return 1
	end
	--XLMessageBox("OK")
	return 0
--	[Link Popup Menu]
--	Item,"使用迅雷下载"=Execute Program, "D:\Program Files\Thunder Network\Thunder7\BHO\XLNonIESvr.exe", "@%l %u"
--	[Image Link Popup Menu]
--	Item,"使用迅雷下载"=Execute Program, "D:\Program Files\Thunder Network\Thunder7\BHO\XLNonIESvr.exe", "@%l %u"
--	[Image Popup Menu]
--	Item,"使用迅雷下载"=Copy image address & Execute Program, "D:\Program Files\Thunder Network\Thunder7\BHO\XLNonIESvr.exe", "@%c %u"
--	[Document Popup Menu]
--	Item,"使用迅雷下载全部链接"=Execute Program, "D:\Program Files\Thunder Network\Thunder7\BHO\XLNonIESvr.exe", "#%s %u"
--	--XLMessageBox(strProfile)
--	string strMenu = "Item,\"";
--	char szMenu[64];
--	DWORD dwSize;
--	dwSize = WideCharToMultiByte(CP_UTF8, 0, L"使用迅雷下载", -1, szMenu, 0, NULL, NULL);
--	WideCharToMultiByte(CP_UTF8, 0, L"使用迅雷下载", -1, szMenu, dwSize, NULL, NULL);


end
function fix_opera(exeName, FixExePath)
	local operaapptype={{"application/7z","7","7z"},{"application/cab","7","cab"},{"application/iso","7","iso"},
	{"application/msi","7","msi"},{"application/rar","7","rar"},{"application/rmvb","7","rmvb"},{"application/x-gtar","7","gtar,tar"},
	{"application/x-msdos-program","7","exe,bat,pif,com,scr"},{"application/x-pn-realmedia","7","rm"},{"application/x-rar-compressed","7","rar"},
	{"application/x-tar","7","tar,tgz,gz,bz2"},{"application/zip","7","zip"},{"application/x-zip-compressed","7","zip"},{"application/x-msdownload","7","exe,bat,pif,com,scr"},
	{"audio/mp3","7","mp3"},{"audio/x-mpeg","7","mp3"}}	
	local Obj=XLGetObject("Xunlei.OSShell.Obj")
	local i=0
	local j=0
	while i~=nil do
		j=i
		i=string.find(exeName, "\\", j+1)
	end
	
	local ProcessName = string.sub(exeName, j+1)
	if Obj:IsProcessExist(ProcessName)==true then
		return 4
	end	
		local ver= Obj:GetFileVerStr(exeName)
	local i, j= string.find(ver, "%.")
	if i==nil or i==1 then return 0  end	
	local nVer = string.sub(ver, 1, i-1)
	
	local opval9={"operadef6.ini","\\profile\\opera6.ini","defaults\\standard_menu.ini"};
	local opval10={"operaprefs_default.ini","\\operaprefs.ini","ui\\standard_menu.ini"}
	local opval={}
	if nVer=="9" then
		opval=opval9
	elseif nVer=="10" then		
		opval=opval10
	else
		return 0
	end
	
	local uMultiUser=Obj:ReadInteger(Obj:PathAppendLua(exeName, "..\\"..opval[1]), "System", "Multi User", 0)

	local strProfile=""	
	local i=0 
	local j=0
	local k=0
	while i~=nil do
		k=j
		j=i
		i=string.find(exeName, "\\", j+1)
	end
	local dirname = string.sub(exeName, k+1, j-1)
	local AppDataPath=Obj:GetAppDataPath()	
	if AppDataPath==nil then 
		return 1 
	end
	if uMultiUser==0 then
			strProfile = Obj:PathAppendLua(exeName, ".."..opval[2])
	else			
			strProfile = AppDataPath.."\\Opera\\"..dirname..opval[2]			
	end
	
	if nVer=="10" then		
		local ret = true
		
		ret =  Obj:WriteStringUtf8(strProfile, "User Prefs", "Use External Download Manager", "1")
		
		local lines = {}
		local fileObj = XLGetObject("XLDoctor.FileIO.Obj")
		
		--解决因为Download Manager没有等号 writestring失败问题
		--读文件
		local fileHandleRead =  fileObj:Open(strProfile, "r")
		if fileHandleRead then 
			
			while true do
				--local line = fileObj:read("*line")	
				local line = fileObj:ReadLine(fileHandleRead)		
				if line=="Download Manager" then
		    		table.insert(lines, "Download Manager=")
				elseif line then 
		    		table.insert(lines, line)
				else
					break
				end
			end			
			fileObj:Close(fileHandleRead)
		end
		
		--写文件
		local fileHandleWrite =  fileObj:Open(strProfile, "w")
		if fileHandleWrite then 
			for i=1,#lines do 
				local bSuc = fileObj:WriteLine(fileHandleWrite, lines[i].."\r\n")
				if not bSuc then	--写文件失败
					return 1
				end
			end
			fileObj:Close(fileHandleWrite)
		end
		
		ret = ret and Obj:WriteStringUtf8(strProfile, "User Prefs", "Download Manager", "迅雷7")
		if ret==false then 
			return 1 
		end
	end
	
	if nVer=="10" then		
		local value = Obj:WriteStringUtf8(strProfile, "User Prefs", "Use External Download Manager", "1")
		if value==false then 
			return 1
		end
		value = Obj:WriteStringUtf8(strProfile, "User Prefs", "Download Manager", "迅雷7")
		if value==false then 
			return 1 
		end
	end
	
	for i=1,#operaapptype do 
		local rightvalue=operaapptype[i][2]..","..FixExePath..",,,"..operaapptype[i][3]..",|"
		
		local value = Obj:WriteStringUtf8(strProfile, "File Types", operaapptype[i][1], rightvalue);
		--XLMessageBox(value)
		--XLMessageBox(rightvalue)
		if value==false then
			return 1
			--break
		end
	end
	--XLMessageBox("result="..tostring(result))
	--local menuiniPath = Obj:PathAppendLua(strProfile, "..\\menu\\menu_thunder.ini")
	
	local standMenuini = Obj:PathAppendLua(exeName,"..\\"..opval[3])
	local menuiniPath = AppDataPath.."\\Opera\\"..dirname.."\\menu\\menu_thunder.ini"
	if Obj:FileExists(standMenuini)==false then
		XLMessageBox(standMenuini)
	end
	local ret = Obj:CopyFile(standMenuini, menuiniPath)
	if ret==false then return 1 end
	local ret=Obj:WriteStringUtf8(strProfile, "User Prefs", "Menu Configuration", menuiniPath)
	--XLMessageBox("valu= "..value)
	--XLMessageBox("menuiniPath="..menuiniPath)
	if ret~=true then
		return 1
	end

	
	local value=Obj:WriteStringUtf8(menuiniPath, "Link Popup Menu", "Item,\"使用迅雷下载\"","Execute Program, \""..FixExePath.."\", \"@%l %u\"")
	--XLMessageBox("value="..value)
	if value~=true then
		return 1
	end
	local value=Obj:WriteStringUtf8(menuiniPath, "Image Link Popup Menu", "Item,\"使用迅雷下载\"","Execute Program, \""..FixExePath.."\", \"@%l %u\"")
	--XLMessageBox("value="..value)
	if value~=true then
		return 1
	end
	local value=Obj:WriteStringUtf8(menuiniPath, "Image Popup Menu", "Item,\"使用迅雷下载\"","Copy image address & Execute Program, \""..FixExePath.."\", \"@%c %u\"")
	--XLMessageBox("value="..value)
	if value~=true then
		return 1
	end
	local value=Obj:WriteStringUtf8(menuiniPath, "Document Popup Menu", "Item,\"使用迅雷下载全部链接\"","Execute Program, \""..FixExePath.."\", \"#%s %u\"")
	--XLMessageBox("value="..value)
	if value~=true then
		return 1
	end
	--XLMessageBox("OK")
	--return 0
	
	
	
	
--	local ret=Obj:ShellExecute(FixExePath, " -r opera -silent", 1, 1)
--	if ret==false then
--		return 1
--	end
  local ret = check_opera(exeName, FixExePath)
	if ret~=0 then		
		return 1
	else
		return 0
	end
end

function CheckBho(tabRoot)
	--XLMessageBox("begin to CheckBho")
	local result = 0	
	
	local Obj=XLGetObject("Xunlei.OSShell.Obj")
	
	--防止兼容模式打开
	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 exeName = GetDefaultBrower()
	local FixExePath = tabRoot['rule@']['FixExePath']
	local bhoDir = tabRoot['rule@']['bhodir']
	if FixExePath==nil then return nil end
	if string.find(FixExePath, "{nil}")~=nil then return 2 end 
	if Obj:FileExists(FixExePath)==false then return 3 end
	--XLMessageBox(exeName)
	if exeName~=nil then	
		local objStat = XLGetObject("XLDoctor.StatHelper.Obj")	
		if string.find(exeName, "360") ~=nil then
			--XLMessageBox("check_360")
			local ret = check_360(exeName)
			if ret ~= 0 then objStat:AddStatNumVal("xldoctor|ieplugin|checkfailed|360|"..Obj:GetFileVerStr(exeName), 1) end
			return ret
		elseif string.find(exeName, "theworld") ~=nil then
			local ret = check_theworld(exeName)
			if ret ~= 0 then objStat:AddStatNumVal("xldoctor|ieplugin|checkfailed|theworld|"..Obj:GetFileVerStr(exeName), 1) end
			return ret
		elseif string.find(exeName, "maxthon") ~=nil then
			local ret = check_maxthon(exeName, bhoDir)
			if ret ~= 0 then objStat:AddStatNumVal("xldoctor|ieplugin|checkfailed|maxthon|"..Obj:GetFileVerStr(exeName), 1) end
			return ret
		elseif string.find(exeName, "firefox") ~=nil then
			local ret = check_firefox(exeName)
			if ret ~= 0 then objStat:AddStatNumVal("xldoctor|ieplugin|checkfailed|firefox|"..Obj:GetFileVerStr(exeName), 1) end
			return ret
		elseif string.find(exeName, "opera") ~=nil then
			local ret = check_opera(exeName, FixExePath)
			if ret ~= 0 then objStat:AddStatNumVal("xldoctor|ieplugin|checkfailed|opera|"..Obj:GetFileVerStr(exeName), 1) end
			return ret
		end
	end
	
	return 0
	
	
--	if IsDefaultBrowser360AndNotEnableBho(exeName)==true then
--			if _360DefaultIsThunder()==false then
--				result = 1
--			end
--	elseif IsDefaultBrowserTheWorldAndNotEnableBho(exeName)==true then
--			if _TheWorldDefaultIsThunder(exeName)==false then
--				result = 1
--			end
--	end
--	return result
end

function FixBho(tabRoot)	
	local result = 0
	local exeName = GetDefaultBrower()
	
	local FixExePath = tabRoot['rule@']['FixExePath']
	if FixExePath == "{nil}" then return 2 end 
	local Obj=XLGetObject("Xunlei.OSShell.Obj")
	if Obj:FileExists(FixExePath)==false then return 3 end
	
	local objStat = XLGetObject("XLDoctor.StatHelper.Obj")	
	if exeName~=nil then		
		if string.find(exeName, "360") ~=nil then
			local ret = fix_360(exeName)
			if ret ~= 0 then 
				objStat:AddStatNumVal("xldoctor|ieplugin|fixfailed|360|"..Obj:GetFileVerStr(exeName), 1)
			else
				objStat:AddStatNumVal("xldoctor|ieplugin|fixsuccess|360|"..Obj:GetFileVerStr(exeName), 1)
			end
			return ret
		elseif string.find(exeName, "theworld") ~=nil then
			local ret = fix_theworld(exeName)
			if ret ~= 0 then 
				objStat:AddStatNumVal("xldoctor|ieplugin|fixfailed|theworld|"..Obj:GetFileVerStr(exeName), 1)
			else
				objStat:AddStatNumVal("xldoctor|ieplugin|fixsuccess|theworld|"..Obj:GetFileVerStr(exeName), 1)
			end
			return ret
		elseif string.find(exeName, "maxthon") ~=nil then
			local ret = fix_maxthon(exeName)
			if ret ~= 0 then 
				objStat:AddStatNumVal("xldoctor|ieplugin|fixfailed|maxthon|"..Obj:GetFileVerStr(exeName), 1)
			else
				objStat:AddStatNumVal("xldoctor|ieplugin|fixsuccess|maxthon|"..Obj:GetFileVerStr(exeName), 1)
			end
			return ret
		elseif string.find(exeName, "firefox") ~=nil then
			local ret = fix_firefox(exeName, FixExePath)
			if ret ~= 0 then 
				objStat:AddStatNumVal("xldoctor|ieplugin|fixfailed|firefox|"..Obj:GetFileVerStr(exeName), 1)
			else
				objStat:AddStatNumVal("xldoctor|ieplugin|fixsuccess|firefox|"..Obj:GetFileVerStr(exeName), 1)
			end
			return ret
		elseif string.find(exeName, "opera") ~=nil then
			local ret = fix_opera(exeName, FixExePath)
			if ret ~= 0 then 
				objStat:AddStatNumVal("xldoctor|ieplugin|fixfailed|opera|"..Obj:GetFileVerStr(exeName), 1)
			else
				objStat:AddStatNumVal("xldoctor|ieplugin|fixsuccess|opera|"..Obj:GetFileVerStr(exeName), 1)
			end
			return ret
		end
	end
	
	return 0
	
	
--	if IsDefaultBrowser360AndNotEnableBho(exeName)==true then
--			if _360DefaultIsThunder()==false then					
--				if isExeRun(1)==true then
--					return 4
--				end				
--				if Set360DefaultThunder()==false then			
--					result = 1
--				end
--			end
--	elseif IsDefaultBrowserTheWorldAndNotEnableBho(exeName)==true then
--			if _TheWorldDefaultIsThunder(exeName)==false then				
--				if isExeRun(2)==true then
--					return 4
--				end
--				if SetTheWorldDefaultThunder(exeName)==false then				
--					result = 1
--				end
--			end
--	end
--	return result
end

-- 360,TheWorld,firefox,