--include "SysFixerCommon.lua"
--include "LuaApi.lua"

GUID="{7286A710-6BE5-43e5-AF84-C844B02B47D8}"

function IsRemoteDirectory(path)
 if (string.sub(path, 1, 2) == "\\\\") then
  return true
 end
 return false
end


function ScanDesktopIcon()
local SpecialFolder =
{
 CSIDL_DESKTOPDIRECTORY,
 CSIDL_COMMON_DESKTOPDIRECTORY
}

 for i = 1 , #SpecialFolder do
  repeat
  BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("SpecialFolder="..SpecialFolder[i])

  local lRet = 0
  local folder_path = ""
  local files
  local folders

  lRet, folder_path = GetSpecialFolderPath(SpecialFolder[i])
  BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("folder_path="..folder_path)
 -- if lRet ~= 0 then
  -- break;
 -- end

  local find_lnk_path = folder_path.."*.lnk"
  lRet, files = FindFiles(find_lnk_path)
 -- if lRet ~= 0 then
  -- break;
 -- end

  for j = 1 , #files do
   repeat
   BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("******files["..j.."] = "..files[j])
   local url=""
   local target=""
   local arguments=""
   local bExist = false

  lRet,url = GetUrlInfo(files[j])
  BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("$$$$$files["..j.."] url = "..url)

  lRet, target, arguments = GetLnkInfo(files[j])
  BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("%%%%%files["..j.."] target = "..target)
  BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("^^^^^files["..j.."] arguments = "..arguments)

  -- --判断不是网络文件夹,假设有个函数IsRemoteDirectory(string)来判断一个路径是不是网络文件夹  
   -- if IsRemoteDirectory(target) == true then  
    -- BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("---IsRemoteDirectory:"..target)
    -- BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("---call break")
    -- break;
   -- end
  -- --判断文件不存在
  -- --判断文件夹不存在
   if (ExistFile(target) == false and DirectoryExists(target) == false) then
    BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString(target.."  ~~~~~not exist!!!")
    BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("~~~~DeleteFile files["..j.."] = "..files[j])

    DelayOperatorBefore("DeleteFile", files[j])
    DelayOperatorBefore("DeleteFolder", files[j])

    local Key = GUID..target
    ScanInfoToInterfaceAfter("hello world", "hello world", "hello world", "1", "hello world", Key)
   end
   until true
  end
  until true
 end

 -- BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("---for end")

 -- return 0
end

function Scan()
ScanDesktopIcon()
--ScanInfoToInterfaceAfter("安装残留", "卫士安装残留文件", "系统残留", 6, "清理", Key)
end


function Fix(Index)
BDM_LUA_GLOBAL_OBSERVER:Lua_PrintDebugString("测试脚本")
nSuccess, ErrorFuncTable = PlayRecord(Index)
if nSuccess == 0 then  
 RetFixResult("success")
else
 RetFixResult("fail")
end
end