Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- LibVersionCheck v1.0
- --]]
- local toc, data = ...
- local AddonId = toc.identifier
- local function Write(text)
- Command.Console.Display("general", true, text, true)
- end
- local function OnStartup()
- Command.Message.Accept(nil, "VERCHK")
- local embeds = {}
- Write("Version Checking")
- local addons = Inspect.Addon.List()
- local addonDetails = Inspect.Addon.Detail(addons)
- for id, addon in pairs(addonDetails) do
- if addon.toc and addon.toc.Embed then
- for embedId, embed in pairs(addon.toc.Embed) do
- local newId = embedId:gsub(".*[/\\]", "")
- print(newId)
- if embed then
- embeds[newId] = true
- end
- end
- end
- end
- local pattern = "[%a%p]*(%d+)%.(%d+)%.?(%d*)%.?(%d*)%p*(%a*)"
- local msgBody = ""
- for id, version in pairs(addons) do
- if not embeds[id] then
- -- Create a version ID
- local parsed = { version:match(pattern) }
- if #parsed == 5 then
- local major = tonumber(parsed[1]) or 0
- local minor = tonumber(parsed[2]) or 0
- local revision = tonumber(parsed[3]) or 0
- local subrevision = tonumber(parsed[4]) or 0
- local suffix = string.lower(parsed[5]):gsub("~",""):gsub("#","")
- --if suffix == "" then suffix = "release" end
- local versionId = string.format("%s~%05d%05d%05d%05d%s", id:gsub("#",""):gsub("~",""), major, minor, revision, subrevision, suffix)
- msgBody = msgBody .. versionId .. "#"
- end
- end
- end
- if msgBody ~= "" then
- Command.Message.Broadcast("yell", nil, "VERCHK", msgBody)
- end
- print(msgBody)
- end
- local function OnMessage(from, type, channel, identifier, data)
- print(string.format("VersionCheckMsg from %s", from))
- for line in data:gmatch("(.-)#") do
- local data = { line:match("(.-)~(%d%d%d%d%d)(%d%d%d%d%d)(%d%d%d%d%d)(%d%d%d%d%d)(.*)") }
- if #data == 6 then
- local id = data[1]
- local major = tonumber(data[2])
- local minor = tonumber(data[3])
- local revision = tonumber(data[4])
- local subrevision = tonumber(data[5])
- local suffix = data[6]
- Write(string.format("<b>%s</b>: %d.%d.%d.%d (%s)", id, major, minor, revision, subrevision, suffix))
- end
- end
- end
- table.insert(Event.Message.Receive, {OnMessage, AddonId, "LibVersionCheck_Message" })
- table.insert(Event.Addon.Startup.End, { OnStartup, AddonId, "LibVersionCheck_Startup" })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement