-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWFI_UpdaterStatus.lua
323 lines (276 loc) · 8.08 KB
/
WFI_UpdaterStatus.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
local WFI_UPDATER_ADDONS = {}
for i = 1, GetNumAddOns() do
local name = GetAddOnInfo(i)
if GetAddOnMetadata(name, "X-PKG-Manifest") then
WFI_UPDATER_ADDONS[name] = "#Managed"
elseif GetAddOnMetadata(name, "X-WFI-Addon") then
WFI_UPDATER_ADDONS[name] = "#Unmanaged"
end
end
local DIRECTORY = {}
local WFI_UpdaterStatus = LibStub("AceAddon-3.0"):NewAddon("WFI_UpdaterStatus", "AceComm-3.0", "AceSerializer-3.0", "AceConsole-3.0", "AceEvent-3.0")
WFIUP = WFI_UpdaterStatus
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local Outer = { type = "group", childGroups = "tree", args = {} }
local GUI = Outer.args
local GroupUnits = {
"party1", "party2", "party3", "party4", "party5",
"raid1", "raid2", "raid3", "raid4", "raid5", "raid6", "raid7", "raid8", "raid9",
"raid10", "raid11", "raid12", "raid13", "raid14", "raid15", "raid16", "raid17", "raid18", "raid19",
"raid20", "raid21", "raid22", "raid23", "raid24", "raid25", "raid26", "raid27", "raid28", "raid29",
"raid30", "raid31", "raid32", "raid33", "raid34", "raid35", "raid36", "raid37", "raid38", "raid39",
"raid40",
}
function WFI_UpdaterStatus:RebuildGUI()
wipe(GUI)
for name in pairs(DIRECTORY) do
local addon = {
type = "group",
name = name,
args = {}
}
for _, unit in ipairs(GroupUnits) do
if UnitExists(unit) then
local user = Ambiguate(UnitName(unit), "short")
if not DIRECTORY[name][user] then
DIRECTORY[name][user] = "#NotInstalled"
end
end
end
local max = 0
for _, rev in pairs(DIRECTORY[name]) do
if type(rev) == "table" and rev.ts > max then
max = rev.ts
end
end
for user, rev in pairs(DIRECTORY[name]) do
local label
if type(rev) == "table" then
label = "|cff" .. ((rev.ts == max) and "abd473" or "ff7f00") .. rev.date
elseif type(rev) == "string" and rev:sub(1, 1) == "#" then
local state = rev:sub(2)
local color = (state == "Unmanaged") and "abd473" or "c41f3b"
label = "|cff" .. color .. state
else
label = "|cffc41f3b" .. tostring(rev)
end
addon.args[user] = {
type = "description",
name = user .. " - " .. label,
width = "normal"
}
end
GUI[name] = addon
end
AceConfigRegistry:NotifyChange("WFI_UpdaterStatus")
end
function WFI_UpdaterStatus:Request()
wipe(DIRECTORY)
if IsInRaid(LE_PARTY_CATEGORY_HOME) then
WFI_UpdaterStatus:SendCommMessage("WFIUPS", "$REQ", "RAID")
end
end
function WFI_UpdaterStatus:OnInitialize()
self:RegisterComm("WFIUPS")
self:RegisterChatCommand("fsu", "OnSlash")
AceConfig:RegisterOptionsTable("WFI_UpdaterStatus", Outer)
end
function WFI_UpdaterStatus:OnEnable()
for addon, rev in pairs(WFI_UPDATER_ADDONS) do
local name, _, _, _, reason = GetAddOnInfo(addon)
if not name or (reason and reason == "MISSING") then
WFI_UPDATER_ADDONS[addon] = "#NotFound"
elseif reason then
WFI_UPDATER_ADDONS[addon] = "#" .. reason
elseif GetAddOnEnableState(UnitName("player"), addon) == 0 then
WFI_UPDATER_ADDONS[addon] = "#Disabled"
elseif not IsAddOnLoaded(addon) and not IsAddOnLoadOnDemand(addon) then
WFI_UPDATER_ADDONS[addon] = "#NotLoaded"
else
local manifest = GetAddOnMetadata(addon, "X-PKG-Manifest")
WFI_UPDATER_ADDONS[addon] = manifest and _G[manifest] or rev:sub(1, 10)
end
end
self:RebuildGUI()
self:BroadcastRevisions()
self:RegisterEvent("GROUP_ROSTER_UPDATE")
self:RegisterEvent("ENCOUNTER_START")
self:RegisterEvent("ENCOUNTER_END")
end
function WFI_UpdaterStatus:OnSlash()
self:Request()
AceConfigDialog:Open("WFI_UpdaterStatus")
end
do
local delay
function WFI_UpdaterStatus:BroadcastRevisions()
if delay then delay:Cancel() end
delay = C_Timer.NewTimer(5, function()
if IsInRaid(LE_PARTY_CATEGORY_HOME) then
local serialized = self:Serialize(WFI_UPDATER_ADDONS)
self:SendCommMessage("WFIUPS", serialized, "RAID")
end
end)
end
end
do
local inRaid = false
function WFI_UpdaterStatus:GROUP_ROSTER_UPDATE()
local now = IsInRaid(LE_PARTY_CATEGORY_HOME)
if now and not inRaid then
self:Request()
self:BroadcastRevisions()
end
inRaid = now
end
end
do
local encounterInProgress = false
local deferred = false
local updates = {}
local warned = {}
function WFI_UpdaterStatus:OnCommReceived(prefix, text, _, sender)
if prefix == "WFIUPS" then
if text == "$REQ" then
self:BroadcastRevisions()
else
local res, addons = self:Deserialize(text)
if not res then return end
local doWarn = false
for addon, rev in pairs(addons) do
local list = DIRECTORY[addon]
if not list then
list = {}
DIRECTORY[addon] = list
end
list[Ambiguate(sender, "short")] = rev
if type(WFI_UPDATER_ADDONS[addon]) == "table" and type(rev) == "table" then
if WFI_UPDATER_ADDONS[addon].ts < rev.ts and (not warned[addon] or warned[addon] < rev.ts) then
if not warned[addon] then
updates[#updates + 1] = addon
end
warned[addon] = rev.ts
doWarn = true
end
end
end
if doWarn then
if encounterInProgress then
deferred = true
else
self:Open(updates)
end
end
self:RebuildGUI()
end
end
end
function WFI_UpdaterStatus:ENCOUNTER_START()
encounterInProgress = true
end
function WFI_UpdaterStatus:ENCOUNTER_END()
encounterInProgress = false
if deferred then
self:Open(updates)
deferred = false
end
end
end
--- GUI
do
local window
local container
local status = {}
-- Create a text label
local function CreateLabel(text)
local label = AceGUI:Create("Label")
label:SetText(text)
label:SetFullWidth(true)
local old_ww = label.label:CanWordWrap()
local old_nsw = label.label:CanNonSpaceWrap()
label.label:SetWordWrap(true)
label.label:SetNonSpaceWrap(true)
label:SetCallback("OnRelease", function()
label.label:SetWordWrap(old_ww)
label.label:SetNonSpaceWrap(old_nsw)
end)
return label
end
local function ContainerHeight(container)
local height = 0
for _, child in ipairs(container.obj.children) do
local frame = child.frame
local fheight = frame.height or frame:GetHeight()
height = height + fheight
end
return height
end
-- Resize the dialog window
function WFI_UpdaterStatus:Layout()
container:DoLayout()
local height = ContainerHeight(container.frame)
window:SetHeight(height + 57 - 10)
end
function WFI_UpdaterStatus:Open(updates)
if not window then
window = AceGUI:Create("Window")
window:SetStatusTable(status)
window:EnableResize(false)
window:SetWidth(300)
window:SetCallback("OnClose", function()
window:Release()
window = nil
ObjectiveTrackerFrame:Show()
end)
container = AceGUI:Create("SimpleGroup")
container:SetAutoAdjustHeight(true)
container:SetFullWidth(true)
container:SetLayout("list")
window:AddChild(container)
window:ClearAllPoints()
window:SetPoint("TOPRIGHT", ObjectiveTrackerFrame)
ObjectiveTrackerFrame:Hide()
else
container:ReleaseChildren()
end
local function add_text(text, font, cont)
if not cont then cont = container end
if not font then font = GameFontHighlight end
local text_label = CreateLabel(text)
text_label:SetFontObject(font)
cont:AddChild(text_label)
return text_label
end
local function add_buttons(buttons)
local actions = AceGUI:Create("SimpleGroup")
actions:SetLayout("flow")
actions:SetFullWidth(true)
container:AddChild(actions)
for _, button in ipairs(buttons) do
local btn = AceGUI:Create("Button")
btn:SetText(button[1])
btn:SetFullWidth(true)
actions:AddChild(btn)
if button[2] then
btn:SetCallback("OnClick", button[2])
else
btn:SetDisabled(true)
end
end
end
window:SetTitle("Updates available")
add_text("Updates available for some of your addons:", GameFontHighlightLarge)
add_text(" ")
for _, addon in ipairs(updates) do
add_text(" - |cffe6494a" .. addon, GameFontHighlightLarge)
end
add_text("\nPlease run WFI-Updater and then reload your interface.\n")
add_buttons({
{ "Reload", function() ReloadUI() end }
})
self:Layout()
end
end