Advertisement
Wildtide

Playing with Version Checking

Jul 13th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. --[[
  2.     LibVersionCheck v1.0
  3. --]]
  4.  
  5. local toc, data = ...
  6. local AddonId = toc.identifier
  7.  
  8. local function Write(text)
  9.     Command.Console.Display("general", true, text, true)
  10. end
  11.  
  12. local function OnStartup()
  13.  
  14.     Command.Message.Accept(nil, "VERCHK")
  15.  
  16.     local embeds = {}
  17.  
  18.     Write("Version Checking")
  19.     local addons = Inspect.Addon.List()
  20.     local addonDetails = Inspect.Addon.Detail(addons)
  21.     for id, addon in pairs(addonDetails) do
  22.         if addon.toc and addon.toc.Embed then
  23.             for embedId, embed in pairs(addon.toc.Embed) do
  24.                 local newId = embedId:gsub(".*[/\\]", "")
  25.                 print(newId)
  26.                 if embed then
  27.                     embeds[newId] = true
  28.                 end
  29.             end
  30.         end
  31.     end
  32.  
  33.     local pattern = "[%a%p]*(%d+)%.(%d+)%.?(%d*)%.?(%d*)%p*(%a*)"
  34.    
  35.     local msgBody = ""
  36.    
  37.     for id, version in pairs(addons) do
  38.         if not embeds[id] then
  39.             -- Create a version ID
  40.             local parsed = { version:match(pattern) }
  41.             if #parsed == 5 then       
  42.                 local major = tonumber(parsed[1]) or 0
  43.                 local minor = tonumber(parsed[2]) or 0
  44.                 local revision = tonumber(parsed[3]) or 0
  45.                 local subrevision = tonumber(parsed[4]) or 0
  46.                 local suffix = string.lower(parsed[5]):gsub("~",""):gsub("#","")
  47.                 --if suffix == "" then suffix = "release" end
  48.                 local versionId = string.format("%s~%05d%05d%05d%05d%s", id:gsub("#",""):gsub("~",""), major, minor, revision, subrevision, suffix)
  49.                 msgBody = msgBody .. versionId .. "#"
  50.             end
  51.         end
  52.     end
  53.  
  54.     if msgBody ~= "" then
  55.         Command.Message.Broadcast("yell", nil, "VERCHK", msgBody)
  56.     end
  57.    
  58.     print(msgBody)
  59.    
  60. end
  61.  
  62. local function OnMessage(from, type, channel, identifier, data)
  63.     print(string.format("VersionCheckMsg from %s", from))
  64.    
  65.     for line in data:gmatch("(.-)#") do
  66.         local data = { line:match("(.-)~(%d%d%d%d%d)(%d%d%d%d%d)(%d%d%d%d%d)(%d%d%d%d%d)(.*)") }
  67.         if #data == 6 then
  68.             local id = data[1]
  69.             local major = tonumber(data[2])
  70.             local minor = tonumber(data[3])
  71.             local revision = tonumber(data[4])
  72.             local subrevision = tonumber(data[5])
  73.             local suffix = data[6] 
  74.             Write(string.format("<b>%s</b>: %d.%d.%d.%d (%s)", id, major, minor, revision, subrevision, suffix))
  75.         end
  76.     end
  77.    
  78. end
  79.  
  80. table.insert(Event.Message.Receive, {OnMessage, AddonId, "LibVersionCheck_Message" })
  81. table.insert(Event.Addon.Startup.End, { OnStartup, AddonId, "LibVersionCheck_Startup" })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement