Commit 5f24ceed authored by Simpy's avatar Simpy 🐹

update version check code (also lib elvui plugin version code)

parent b456eb0d
......@@ -7,13 +7,12 @@ if not lib then return end
local pairs, tonumber, strmatch, strsub = pairs, tonumber, strmatch, strsub
local format, strsplit, strlen, gsub, ceil = format, strsplit, strlen, gsub, ceil
--WoW API / Variables
local CreateFrame = CreateFrame
local IsInGroup, IsInRaid = IsInGroup, IsInRaid
local GetAddOnMetadata = GetAddOnMetadata
local IsAddOnLoaded = IsAddOnLoaded
local GetLocale = GetLocale
local CreateFrame, IsAddOnLoaded = CreateFrame, IsAddOnLoaded
local IsInGroup, IsInRaid, IsInGuild = IsInGroup, IsInRaid, IsInGuild
local GetAddOnMetadata, GetChannelName = GetAddOnMetadata, GetChannelName
local C_ChatInfo_RegisterAddonMessagePrefix = C_ChatInfo.RegisterAddonMessagePrefix
local C_ChatInfo_SendAddonMessage = C_ChatInfo.SendAddonMessage
local GetNumGroupMembers = GetNumGroupMembers
local LE_PARTY_CATEGORY_HOME = LE_PARTY_CATEGORY_HOME
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
......@@ -67,7 +66,24 @@ end
-- Registers a module with the given name and option callback, pulls version info from metadata
--
function lib:RegisterPlugin(name,callback, isLib)
function lib:GenerateVersionCheckMessage()
local list = ""
for _, plugin in pairs(lib.plugins) do
if plugin.name ~= MAJOR then
list = list..plugin.name.."="..plugin.version..";"
end
end
return list
end
local function SendPluginVersionCheck()
lib:SendPluginVersionCheck(lib:GenerateVersionCheckMessage())
end
function lib:RegisterPlugin(name, callback, isLib)
if not ElvUI then return end -- lol?
lib.E = ElvUI[1]
local plugin = {}
plugin.name = name
plugin.version = name == MAJOR and MINOR or GetAddOnMetadata(name, "Version")
......@@ -79,18 +95,21 @@ function lib:RegisterPlugin(name,callback, isLib)
if not lib.vcframe then
C_ChatInfo_RegisterAddonMessagePrefix(lib.prefix)
local f = CreateFrame('Frame')
f:RegisterEvent("GROUP_ROSTER_UPDATE")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("CHAT_MSG_ADDON")
f:SetScript('OnEvent', lib.VersionCheck)
lib.vcframe = f
end
if not lib.delayedCheck then
lib.E:Delay(10, SendPluginVersionCheck)
lib.delayedCheck = true
end
if not loaded then
if not lib.ConfigFrame then
local configFrame = CreateFrame("Frame")
configFrame:RegisterEvent("ADDON_LOADED")
configFrame:SetScript("OnEvent", function(self, event, addon)
configFrame:SetScript("OnEvent", function(_, _, addon)
if addon == "ElvUI_Config" then
for _, PlugIn in pairs(lib.plugins) do
if PlugIn.callback then
......@@ -104,7 +123,7 @@ function lib:RegisterPlugin(name,callback, isLib)
elseif loaded then
-- Need to update plugins list
if name ~= MAJOR then
ElvUI[1].Options.args.plugins.args.plugins.name = lib:GeneratePluginList()
lib.E.Options.args.plugins.args.plugins.name = lib:GeneratePluginList()
end
callback()
end
......@@ -113,7 +132,7 @@ function lib:RegisterPlugin(name,callback, isLib)
end
function lib:GetPluginOptions()
ElvUI[1].Options.args.plugins = {
lib.E.Options.args.plugins = {
order = -10,
type = "group",
name = HDR_CONFIG,
......@@ -133,71 +152,49 @@ function lib:GetPluginOptions()
}
end
function lib:GenerateVersionCheckMessage()
local list = ""
for _, plugin in pairs(lib.plugins) do
if plugin.name ~= MAJOR then
list = list..plugin.name.."="..plugin.version..";"
function lib:VersionCheck(event, prefix, message, _, sender)
if (event == "CHAT_MSG_ADDON") and (prefix == lib.prefix) and (sender and message and not strmatch(message, "^%s-$")) then
if not lib.myName then lib.myName = lib.E.myname..'-'..gsub(lib.E.myrealm,'[%s%-]','') end
if sender == lib.myName then
if lib.delayedCheck then
lib.delayedCheck = nil
end
return
end
end
return list
end
local function SendPluginVersionCheck(self)
lib:SendPluginVersionCheck(lib:GenerateVersionCheckMessage())
if self["ElvUIPluginSendMSGTimer"] then
self:CancelTimer(self["ElvUIPluginSendMSGTimer"])
self["ElvUIPluginSendMSGTimer"] = nil
end
end
function lib:VersionCheck(event, prefix, message, channel, sender)
local E = ElvUI[1]
if (event == "CHAT_MSG_ADDON") and sender and message and (not strmatch(message, "^%s-$")) and (prefix == lib.prefix) then
if not lib.myName then lib.myName = E.myname..'-'..gsub(E.myrealm,'[%s%-]','') end
if sender == lib.myName then return end
if not E["pluginRecievedOutOfDateMessage"] then
if not lib.E["pluginRecievedOutOfDateMessage"] then
local name, version, plugin, Pname
for _, p in pairs({strsplit(";",message)}) do
if not strmatch(p, "^%s-$") then
name, version = strmatch(p, "([%w_]+)=([%d%p]+)")
if lib.plugins[name] then
plugin = lib.plugins[name]
if plugin.version ~= 'BETA' and version ~= nil and tonumber(version) ~= nil and plugin.version ~= nil and tonumber(plugin.version) ~= nil and tonumber(version) > tonumber(plugin.version) then
plugin.old = true
plugin.newversion = tonumber(version)
if (version ~= nil and plugin.version ~= nil and plugin.version ~= 'BETA') and (tonumber(version) ~= nil and tonumber(plugin.version) ~= nil) and (tonumber(version) > tonumber(plugin.version)) then
plugin.old, plugin.newversion = true, tonumber(version)
Pname = GetAddOnMetadata(plugin.name, "Title")
E:Print(format(MSG_OUTDATED,Pname,plugin.version,plugin.newversion))
E["pluginRecievedOutOfDateMessage"] = true
lib.E:Print(format(MSG_OUTDATED,Pname,plugin.version,plugin.newversion))
lib.E["pluginRecievedOutOfDateMessage"] = true
end
end
end
end
end
else
if not E.SendPluginVersionCheck then
E.SendPluginVersionCheck = SendPluginVersionCheck
if not lib.E.SendPluginVersionCheck then
lib.E.SendPluginVersionCheck = SendPluginVersionCheck
end
local num = GetNumGroupMembers()
if num ~= lib.groupSize then
if num > 1 and num > lib.groupSize then
E["ElvUIPluginSendMSGTimer"] = E:ScheduleTimer("SendPluginVersionCheck", 12)
end
lib.groupSize = num
end
lib.E:ScheduleTimer("SendPluginVersionCheck", 10)
end
end
function lib:GeneratePluginList()
local list, E = "", ElvUI[1]
local list = ""
local author, Pname, color
for _, plugin in pairs(lib.plugins) do
if plugin.name ~= MAJOR then
author = GetAddOnMetadata(plugin.name, "Author")
Pname = GetAddOnMetadata(plugin.name, "Title") or plugin.name
color = plugin.old and E:RGBToHex(1,0,0) or E:RGBToHex(0,1,0)
color = plugin.old and lib.E:RGBToHex(1,0,0) or lib.E:RGBToHex(0,1,0)
list = list .. Pname
if author then
list = list .. " ".. INFO_BY .." " .. author
......@@ -235,7 +232,7 @@ function lib:SendPluginVersionCheck(message)
splitMessage = strmatch(strsub(message, 1, maxChar), '.+;')
if splitMessage then -- incase the string is over 250 but doesnt contain `;`
message = gsub(message, "^"..gsub(splitMessage, '([%(%)%.%%%+%-%*%?%[%^%$])','%%%1'), "")
ElvUI[1]:Delay(delay, C_ChatInfo_SendAddonMessage, lib.prefix, splitMessage, ChatType, Channel)
lib.E:Delay(delay, C_ChatInfo_SendAddonMessage, lib.prefix, splitMessage, ChatType, Channel)
delay = delay + 1
end
end
......
......@@ -28,7 +28,8 @@ local RequestBattlefieldScoreData = RequestBattlefieldScoreData
local C_ChatInfo_SendAddonMessage = C_ChatInfo.SendAddonMessage
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
local UnitHasVehicleUI = UnitHasVehicleUI
local GetNumGroupMembers = GetNumGroupMembers
local GetChannelName = GetChannelName
local JoinPermanentChannel = JoinPermanentChannel
local UnitLevel, UnitStat, UnitAttackPower = UnitLevel, UnitStat, UnitAttackPower
local COMBAT_RATING_RESILIENCE_PLAYER_DAMAGE_TAKEN = COMBAT_RATING_RESILIENCE_PLAYER_DAMAGE_TAKEN
local ERR_NOT_IN_COMBAT = ERR_NOT_IN_COMBAT
......@@ -918,35 +919,24 @@ function E:SendMessage()
end
end
local SendRecieveGroupSize = -1 --this is negative one so that the first check will send (if group size is greater than one; specifically for /reload)
local myRealm = gsub(E.myrealm,'[%s%-]','')
local myName = E.myname..'-'..myRealm
local function SendRecieve(_, event, prefix, message, _, sender)
if event == "CHAT_MSG_ADDON" then
if (sender == myName) then
return
end
if sender == myName then return end
if prefix == "ELVUI_VERSIONCHK" then
if (not E.recievedOutOfDateMessage) and (tonumber(message) ~= nil and tonumber(message) > tonumber(E.version)) then
local msg, ver = tonumber(message), tonumber(E.version)
if (not E.recievedOutOfDateMessage) and (msg ~= nil and msg > ver) then
E:Print(L["ElvUI is out of date. You can download the newest version from www.tukui.org. Get premium membership and have ElvUI automatically updated with the Tukui Client!"])
if((tonumber(message) - tonumber(E.version)) >= 0.05) then
if msg ~= nil and ((msg - ver) >= 0.05) then
E:StaticPopup_Show("ELVUI_UPDATE_AVAILABLE")
end
E.recievedOutOfDateMessage = true
elseif (tonumber(message) ~= nil and tonumber(message) < tonumber(E.version)) then -- Send Message Back if you intercept and are higher revision
E:ScheduleTimer('SendMessage', 10)
end
end
elseif event == "GROUP_ROSTER_UPDATE" then
local num = GetNumGroupMembers()
if num ~= SendRecieveGroupSize then
if num > 1 and num > SendRecieveGroupSize then
elseif msg ~= nil and (msg < ver) then -- Send Message Back if you intercept and are higher revision
E:ScheduleTimer('SendMessage', 10)
end
SendRecieveGroupSize = num
end
else
E:ScheduleTimer('SendMessage', 10)
......@@ -956,9 +946,7 @@ end
C_ChatInfo.RegisterAddonMessagePrefix('ELVUI_VERSIONCHK')
local f = CreateFrame("Frame")
f:RegisterEvent("GROUP_ROSTER_UPDATE")
f:RegisterEvent("CHAT_MSG_ADDON")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", SendRecieve)
function E:UpdateAll(ignoreInstall)
......@@ -1603,8 +1591,13 @@ local function HandleCommandBar()
end
end
local DelayedElvUIGVC = function()
JoinPermanentChannel('ElvUIGVC')
E:Delay(5, SendRecieve)
end
function E:Initialize(loginFrame)
E:Delay(30, function() JoinPermanentChannel('ElvUIGVC') end)
E:Delay(30, DelayedElvUIGVC)
twipe(self.db)
twipe(self.global)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment