-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAddonFinder.lua
127 lines (121 loc) · 3.05 KB
/
AddonFinder.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
local ADDON_NAME, T = ...
local L = T.L
local C = T.Color
--- @type SimpleAddonManager
local SAM = T.AddonFrame
local module = SAM:RegisterModule("AddonFinder")
function module:StopSearch()
local db = SAM:GetDb()
for addon, v in pairs(db.addonFinder.initialAddons) do
if (v.selected) then
SAM:EnableAddOn(addon)
end
end
db.addonFinder.isSearching = false
end
function module:StartSearch()
local db = SAM:GetDb()
if (db.addonFinder and db.addonFinder.isSearching) then
local searching = db.addonFinder.searchingAddons
SAM:ShowYesNoCancelDialog(
L(
"Search in progress...\nStatus: enabled: ${enabled}, disabled: ${disabled}\nThe addon you are looking for has been disabled?",
{
enabled = (searching.enabled and #searching.enabled) or 0,
disabled = (searching.disabled and #searching.disabled) or 0,
}
),
function()
module:ContinueSearch(true)
return true
end,
function()
module:ContinueSearch(false)
return true
end,
function()
module:StopSearch()
ReloadUI()
end
)
else
SAM:ShowConfirmDialog(
L["Start binary search?\nMake sure to save your profile first, just in case."],
function()
local addons = {}
local activeAddons = {}
for i = 1, SAM.compat.GetNumAddOns() do
local name, _, _, loadable, reason = SAM.compat.GetAddOnInfo(i)
local selected = SAM:IsAddonSelected(name)
addons[name] = {
selected = selected,
}
local isLoaded = loadable or reason == "DEMAND_LOADED"
if (selected and isLoaded) then
table.insert(activeAddons, name)
end
end
db.addonFinder = {
isSearching = true,
initialAddons = addons,
searchingAddons = {
enabled = {},
disabled = {},
}
}
module:BinarySearch(activeAddons)
end
)
end
end
function module:BinarySearch(addons)
if (#addons <= 1) then
return
end
SAM:DisableAllAddOns()
SAM:EnableAddOn(ADDON_NAME)
local half = #addons / 2
local enabled = {}
local disabled = {}
for i, v in ipairs(addons) do
if (i <= half) then
SAM:EnableAddOn(v)
table.insert(enabled, v)
else
table.insert(disabled, v)
end
end
local db = SAM:GetDb()
db.addonFinder.searchingAddons = {
enabled = enabled,
disabled = disabled,
}
ReloadUI()
end
function module:ContinueSearch(answer)
local db = SAM:GetDb()
local addons
if (answer) then
addons = db.addonFinder.searchingAddons.disabled or {}
else
addons = db.addonFinder.searchingAddons.enabled or {}
end
if (#addons <= 1) then
module:StopSearch()
SAM:Update()
SAM:ShowConfirmDialog(
L("Result: ${name}", { name = addons[1] or L["Not Found!"] }) .. "\n" .. L["Your AddOns were restored, reload UI?"],
function()
ReloadUI()
end
)
else
module:BinarySearch(addons)
end
end
SAM:HookScript("OnShow", function()
local db = SAM:GetDb()
if (db.addonFinder and db.addonFinder.isSearching) then
module:StartSearch()
end
end)