forked from m00nyONE/LibCustomIcons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegrity.lua
More file actions
226 lines (179 loc) · 6.55 KB
/
integrity.lua
File metadata and controls
226 lines (179 loc) · 6.55 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
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
-- SPDX-FileCopyrightText: 2025 m00nyONE
-- SPDX-License-Identifier: Artistic-2.0
local lib_name = "LibCustomIcons"
local lib = _G[lib_name]
local s = lib.GetStaticTable()
local a = lib.GetAnimatedTable()
local sLength = 0
local aLength = 0
local EM = EVENT_MANAGER
local LAM = LibAddonMenu2
local WM = GetWindowManager()
local GUIControl = LibCustomIcons_IntegrityCheck
local iconSize = 32
local SCREEN_WIDTH = GuiRoot:GetWidth()
local SCREEN_HEIGHT = GuiRoot:GetHeight()
--local maxColumns = zo_floor(SCREEN_WIDTH / iconSize)
--local maxRows = zo_floor(SCREEN_HEIGHT / iconSize)
local LOAD_DELAY = 5 --5ms
local checkAfter = 0
local unloadAfter = 5000
local reportAfter = 1000
local iconPool = {}
local scannedIcons = 0
local failedList = {}
local function len(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
local function resetValues()
checkAfter = 0
iconPool = {}
scannedIcons = 0
failedList = {}
sLength = 0
aLength = 0
end
local function GetResults()
zo_callLater(function()
local failed = len(failedList)
local integrityFailed = failed > 10
local color = "00FF00"
local status = "passed"
local message = "all fine :-)"
local function colorize(str)
return "|c" .. color .. str .. "|r"
end
if integrityFailed then
color = "FF0000"
status = "failed"
message = colorize(
"\nThere might be an issue with your LibCustomIcons installation.\n" ..
"please consider reinstalling the addon\n"
)
d(colorize("Missing icons:"))
for user, icon in pairs(failedList) do
d(colorize(user .. " (" .. icon .. ")"))
end
d("")
end
d(colorize("summary:"))
d(colorize("icons scanned: " .. scannedIcons))
d(colorize("icons failed: " .. failed))
d("")
PlaySound(SOUNDS.BOOK_COLLECTION_COMPLETED)
if not ZO_Dialogs_IsShowingDialog() then
LAM.util.ShowConfirmationDialog(
"LibCustomIcons Integrity check",
"Integrity check ".. colorize(status) .. "\n" ..
"icons scanned: " .. scannedIcons .. "\n" ..
"icons failed: " .. colorize(failed) .. "\n" ..
message,
nil)
end
end, 1000)
end
local function createTexture(iconNumber, userName, iconPath, left, right, top, bottom)
--local iconColumn = iconNumber % maxColumns
--local iconRow = (zo_floor((iconSize * iconNumber) / SCREEN_WIDTH)) % maxRows
local iconX = zo_floor(math.random(0, SCREEN_WIDTH - iconSize))
local iconY = zo_floor(math.random(0, SCREEN_HEIGHT - iconSize))
local icon = WM:CreateControl( GUIControl:GetName() .. "_" .. GetGameTimeMilliseconds() .. "_Icon_" .. tostring(iconNumber), GUIControl, CT_TEXTURE)
icon.userName = userName
icon.iconPath = iconPath
icon:ClearAnchors()
--icon:SetAnchor( TOPLEFT, GUIControl, TOPLEFT, (iconColumn * iconSize), (iconRow * iconSize))
icon:SetAnchor( TOPLEFT, GUIControl, TOPLEFT, iconX, iconY)
icon:SetTextureReleaseOption(RELEASE_TEXTURE_AT_ZERO_REFERENCES)
icon:SetHidden(false)
icon:SetTexture(iconPath)
icon:SetTextureCoords(left, right, top, bottom)
icon:SetDimensions(iconSize, iconSize)
iconPool[iconNumber] = icon
scannedIcons = scannedIcons + 1
end
local function checkTexture(iconNumber)
local icon = iconPool[iconNumber]
local isLoaded = icon:IsTextureLoaded()
iconPool[iconNumber]:SetTextureCoords(0, 1, 0, 1)
if isLoaded then
iconPool[iconNumber]:SetTexture("LibCustomIcons/assets/check.dds")
else
--table.insert(failedList, icon.userName)
failedList[icon.userName] = icon.iconPath
iconPool[iconNumber]:SetTexture("LibCustomIcons/assets/cross.dds")
end
end
local function deleteTexture(iconNumber)
iconPool[iconNumber]:SetHidden(true)
iconPool[iconNumber]:SetTexture("none")
iconPool[iconNumber] = nil
end
local function calculateCheckTime()
return (sLength + aLength) * LOAD_DELAY
end
local function integrityCheck()
local limit = 9999999
local iconNumber = 1
LibCustomIcons_IntegrityCheck:SetHidden(false)
d("loading animated icons ...")
for userName, userData in pairs(a) do
if iconNumber >= limit then
break
end
local iconPath = userData[1]
createTexture(iconNumber, userName, iconPath, 0, 1, 0 ,1)
iconNumber = iconNumber + 1
end
d("loading static icons ...")
for userName, _ in pairs(s) do
if iconNumber >= limit then
break
end
local iconPath, left, right, top, bottom = lib.GetStatic(userName)
createTexture(iconNumber, userName, iconPath, left, right, top, bottom)
iconNumber = iconNumber + 1
end
d("loaded " .. iconNumber .. " icons")
zo_callLater(function()
d("checking icons...")
for i, _ in pairs(iconPool) do
checkTexture(i)
end
zo_callLater(function()
d("unloading icons ...")
for i, _ in pairs(iconPool) do
deleteTexture(i)
end
zo_callLater(function()
LibCustomIcons_IntegrityCheck:SetHidden(true)
d("writing report ...")
GetResults()
d("done")
end, reportAfter)
end, unloadAfter)
end, checkAfter)
end
function lib.IntegrityCheck()
resetValues()
sLength = len(s)
aLength = len(a)
checkAfter = calculateCheckTime()
local calculatedTime = (reportAfter + unloadAfter + checkAfter) / 1000
d("starting integritycheck")
d("this will take aproximatly " .. calculatedTime .. " seconds")
d("please wait and let it do its thing :-)")
if not ZO_Dialogs_IsShowingDialog() then
LAM.util.ShowConfirmationDialog(
"LibCustomIcons Integrity check",
"Do you want to perform an integrity check? This will take approximately ".. calculatedTime .." seconds",
function() LAM.util.ShowConfirmationDialog(
"LibCustomIcons Integrity check",
"Please do not interrupt the check. Just let it do its thing. You will get the results after it's finished",
function()
zo_callLater(integrityCheck, 250)
end)
end)
end
end