-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddonSearch.lua
More file actions
186 lines (164 loc) · 5.06 KB
/
Copy pathAddonSearch.lua
File metadata and controls
186 lines (164 loc) · 5.06 KB
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
local addon, ns = ...
local L = ns.L
local listFrame = AddonMgrAddonList
listFrame:HookScript("OnShow", function(self)
if not self.db.searchAddon then return end
local function stop(guiltyAddon)
for name, enabled in next, self.db.searchAddon.initialList do
self:enableAddon(name, enabled, self.charGUID)
end
if guiltyAddon then self:enableAddon(guiltyAddon, false, false) end
self.db.searchAddon = nil
ReloadUI()
end
StaticPopupDialogs[listFrame.addonName.."SEARCH_RESULT"] = {
text = addon..": "..L["SEARCH_RESULT_QUESTION"],
button1 = YES,
button2 = NO,
whileDead = 1,
OnAccept = function(_, name) stop(name) end,
OnCancel = function() stop() end,
}
local function continue(inList, popup)
popup:Hide()
local suspected, justified = self.db.searchAddon.enabled, self.db.searchAddon.disabled
if inList then suspected, justified = justified, suspected end
for i, name in ipairs(justified) do
tinsert(self.db.searchAddon.justified, name)
for pName, list in next, self.db.searchAddon.childByPName do
tDeleteItem(list, name)
if #list == 0 then
self.db.searchAddon.childByPName[pName] = nil
end
end
end
local function notDepSuspected(name)
local deps = self.depsByName[name]
if deps ~= nil then
for i = 1, #deps do
if tContains(suspected, deps[i]) then return false end
end
end
return true
end
local hasParentByName = self.db.searchAddon.hasParentByName
for name in next, hasParentByName do
if notDepSuspected(name) then hasParentByName[name] = nil end
end
if #suspected > 1 then
self:listSifting(suspected)
else
StaticPopup_Show(listFrame.addonName.."SEARCH_RESULT", NORMAL_FONT_COLOR:WrapTextInColorCode(suspected[1] or "Not Found!"), nil, suspected[1])
end
end
StaticPopupDialogs[listFrame.addonName.."SEARCH_YES_NO_STOP"] = {
text = addon..": "..L["SEARCH_PROGRESS_QUESTION"],
button1 = YES,
button2 = NO,
button3 = CANCEL,
whileDead = 1,
selectCallbackByIndex = 1,
OnButton1 = function(self) continue(true, self) end,
OnButton2 = function(self) continue(false, self) end,
OnButton3 = function() stop() end,
}
StaticPopup_Show(listFrame.addonName.."SEARCH_YES_NO_STOP", #self.db.searchAddon.enabled + #self.db.searchAddon.disabled, #self.db.searchAddon.justified)
end)
function listFrame:startSearch()
StaticPopupDialogs[listFrame.addonName.."START_SEARCH"] = {
text = addon..": "..L["Start seearching for the guilty addon?"],
button1 = ACCEPT,
button2 = CANCEL,
hideOnEscape = 1,
whileDead = 1,
OnAccept = function(self, cb) cb() end,
}
StaticPopup_Show(self.addonName.."START_SEARCH", nil, nil, function()
local initialList = {}
local loadedList = {}
local childByPName = {}
local hasParentByName = {}
local function checkDeps(dName, pName)
if pName == addon or self.circular[pName] then return true end
local deps = self.depsByName[pName]
if deps ~= nil then
for i, name in ipairs(deps) do
if dName == name or checkDeps(dName, name) then
return true
end
end
end
return false
end
for i = 1, #self.sorted do
local name = self.sorted[i]
local loadable, reason = C_AddOns.IsAddOnLoadable(name, self.charGUID)
initialList[name] = reason ~= "DISABLED"
if name ~= addon and (loadable or reason == "DEMAND_LOADED" or reason == "DEP_DEMAND_LOADED") then
loadedList[#loadedList + 1] = name
local deps = self.depsByName[name]
if deps ~= nil then
for j = 1, #deps do
local dName = deps[j]
if dName ~= addon then
local addChild = true
for n = 1, #deps do
if n ~= j and checkDeps(dName, deps[n]) then
addChild = false
break
end
end
if addChild then
hasParentByName[name] = true
local childs = childByPName[dName]
if childs then childs[#childs + 1] = name
else childByPName[dName] = {name} end
end
end
end
end
end
end
self.db.searchAddon = {
initialList = initialList,
childByPName = childByPName,
hasParentByName = hasParentByName,
justified = {},
}
self:listSifting(loadedList)
end)
end
function listFrame:listSifting(list)
local childByPName = self.db.searchAddon.childByPName
local hasParentByName = self.db.searchAddon.hasParentByName
local actualList = {}
local enabled = {}
local disabled = {}
self:setAddonsEnabled(false, self.charGUID)
self:enableAddon(addon, true, self.charGUID)
for i, name in ipairs(self.db.searchAddon.justified) do
self:enableAddon(name, true, self.charGUID)
end
for i, name in ipairs(list) do
if childByPName[name] then
enabled[#enabled + 1] = name
self:enableAddon(name, true, self.charGUID)
elseif hasParentByName[name] then
disabled[#disabled + 1] = name
else
actualList[#actualList + 1] = name
end
end
local half = #actualList / 2
for i, name in ipairs(actualList) do
if i <= half then
self:enableAddon(name, true, self.charGUID)
enabled[#enabled + 1] = name
else
disabled[#disabled + 1] = name
end
end
self.db.searchAddon.enabled = enabled
self.db.searchAddon.disabled = disabled
ReloadUI()
end