-
Notifications
You must be signed in to change notification settings - Fork 7
/
export.lua
390 lines (334 loc) · 10.9 KB
/
export.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
local project, branch, filter = ...
--luacheck: globals require assert pcall type
--luacheck: globals tostring setmetatable
--luacheck: globals table io next os package
local function write(text, ...)
_G.print(text:format(...))
end
local projects = {
retail = "wow",
classic = "wow_classic",
bcc = "wow_classic",
wrath = "wow_classic",
classic_era = "wow_classic_era",
vanilla = "wow_classic_era",
}
local branches = {
live = "",
ptr = "t",
ptr2 = "xptr",
beta = "_beta",
-- Classic PTR
ptrC = "_ptr",
}
local fileTypes = {
all = true,
code = "Code",
art = "Art",
}
if project then
if branches[project] then
branch, filter = project, branch
project = "retail"
end
if fileTypes[project] then
filter = project
project = "retail"
branch = "live"
end
if fileTypes[branch] then
filter = branch
branch = "live"
end
if project ~= "retail" and branch == "ptr" then
branch = "ptrC"
end
else
project, branch, filter = "retail", "live", "all"
end
local convertBLP = false
if filter == "png" then
convertBLP = true
filter = "art"
end
filter = filter or "all"
--[[
TODO: Add and `latest` branch that will search
all branches for the newest version.
]]
write("Extracting %s from %s %s...", filter, project, branch)
local product = projects[project] .. branches[branch]
package.path = package.path .. ";libs/?.lua;libs/?/init.lua;InterfaceExport/libs/?.lua;InterfaceExport/libs/?/init.lua"
local casc = require("casc")
local plat = require("casc.platform")
local dbc = require("dbc")
local csv = pcall(require, "csv")
local WOWDIR = "E:/World of Warcraft"
local CACHE_DIR = "./InterfaceExport/Cache/" .. product
local REGION = "us"
local PATCH_BASE = ("http://%s.patch.battle.net:1119/%s"):format(REGION, product)
local FILEID_PATH_MAP = {
["DBFilesClient/ManifestInterfaceData.db2"] = 1375801,
["DBFilesClient/GlobalStrings.db2"] = 1394440,
["DBFilesClient/UiTextureAtlas.db2"] = 897470,
["DBFilesClient/UiTextureAtlasMember.db2"] = 897532,
-- These _may_ have proper names, but they're not known at present.
["Interface/ui-code-list.txt"] = 6067012,
["Interface/ui-code-doc-list.txt"] = 6076661,
}
local rmdir, convert do
-- Based on code from casc.platform
local dir_sep = package and package.config and package.config:sub(1,1) or "/"
local command = "rmdir %s"
if dir_sep == '/' then
-- *nix
command = "rm -r %s"
end
local function execute(...)
local ok, status, sig = os.execute(...)
if ok == true and status == "exit" or status == "signal" then
return sig
else
return ok or sig or ok, status, sig
end
end
local function shellEscape(s)
return '"' .. s:gsub('"', '"\\\\""') .. '"'
end
function rmdir(path)
return execute(command:format(shellEscape(path)))
end
-- ./libs/BLPConverter/BLPConverter UI-AbilityPanel-BotLeft
function convert(path)
write("Convert file: %s", path)
return execute(("./libs/BLPConverter/BLPConverter %s"):format(shellEscape(path)))
end
end
local fileHandle do
local function selectBuild(buildInfo)
for i = 1, #buildInfo do
--print(buildInfo[i].Product, buildInfo[i].Active)
if buildInfo[i].Product == product and buildInfo[i].Active == 1 then
return i
end
assert(0)
end
end
local base = WOWDIR .. "/Data"
local buildKey, cdn, ckey, version = casc.localbuild(WOWDIR .. "/.build.info", selectBuild)
if version then
write("Product: %s Build: %s", product, tostring(version))
else
write("Local build not found, checking CDN...")
buildKey, cdn, ckey, version = casc.cdnbuild(PATCH_BASE, REGION)
if version then
write("CDN Product: %s Build: %s", product, tostring(version))
base = CACHE_DIR
else
write("Product %s not found", product)
return
end
end
local versionBuild = ("%s (%s)"):format(version:match("(%d+.%d+.%d).(%d*)"))
if versionBuild then
local file = assert(io.open("version.txt", "w"))
file:write(versionBuild, "\n")
end
plat.mkdir(CACHE_DIR)
local conf = {
bkey = buildKey,
base = base,
cdn = cdn,
ckey = ckey,
cache = CACHE_DIR,
cacheFiles = true,
locale = casc.locale.US,
requireRootFile = false,
--verifyHashes = false,
--log = print
}
fileHandle = assert(casc.open(conf))
end
local GetFileList do
local fileFilter = {
xml = "code",
lua = "code",
toc = "code",
xsd = "code",
blp = "art"
}
local params = {
header = true,
}
local l = setmetatable({}, {__index=function(s, a) s[a] = a:lower() return s[a] end})
local function SortPath(a, b)
return l[a.fullPath] < l[b.fullPath]
end
local function CheckFile(fileType, files, id, path, name)
--print(_, path, name)
if fileFilter[(name:match("%.(...)$") or ""):lower()] == fileType then
path = path:gsub("[/\\]+", "/")
--print("CheckFile", path)
files[#files + 1] = {
path = path,
id = id,
fullPath = path .. name,
}
end
end
local function HasTextualManifest(fileType)
local data
-- At present art exports still use the old manifest.
if fileType == "code" then
data = fileHandle:readFile("Interface/ui-toc-list.txt")
end
return data ~= nil
end
local function CheckFileList(fileType, files, listData)
if listData == nil then
return
end
for filePath in listData:gmatch("[^\r\n]+") do
local fileDir, fileName = filePath:match("^(.+[\\/])(.-)$")
local fileID = fileHandle.root:getFileID(filePath)
CheckFile(fileType, files, fileID, fileDir, fileName)
end
end
function GetFileList(fileType)
local files = {}
if csv and io.open("manifestinterfacedata.csv", "r")then
-- from wow.tools table browser
local csvFile = csv.open("manifestinterfacedata.csv", params)
for fields in csvFile:lines() do
CheckFile(fileType, files, fields.ID, fields.FilePath, fields.FileName)
end
elseif HasTextualManifest(fileType) then
fileHandle.root:addFileIDPaths(FILEID_PATH_MAP)
CheckFileList(fileType, files, fileHandle:readFile("Interface/ui-toc-list.txt"))
CheckFileList(fileType, files, fileHandle:readFile("Interface/ui-code-list.txt"))
CheckFileList(fileType, files, fileHandle:readFile("Interface/ui-code-doc-list.txt"))
else
fileHandle.root:addFileIDPaths(FILEID_PATH_MAP)
local fileData = assert(fileHandle:readFile("DBFilesClient/ManifestInterfaceData.db2"))
for id, path, name in dbc.rows(fileData, "ss") do
if path:match("^[Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee][\\/_]") then
CheckFile(fileType, files, id, path, name)
end
end
end
table.sort(files, SortPath)
return files
end
end
local progress = 0
local function UpdateProgress(current)
--if collectgarbage("count") > gcLimit then
-- collectgarbage()
--end
if (current - progress) > 0.1 then
write("%d%%", current * 100)
progress = current
end
if current == 1 then
write("Done!")
progress = 0
end
end
local CreateDirectories do
function CreateDirectories(files, root)
local dirs = {}
for i = 1, #files do
local path = files[i].fullPath
for endPoint in path:gmatch("()/") do
local subPath = path:sub(1, endPoint - 1)
local subLower = subPath:lower()
if not dirs[subLower] then
--print("dir", path, subPath, subLower)
dirs[subLower] = subPath
end
end
end
local makeDirs = {}
for _, subPath in next, dirs do
table.insert(makeDirs, subPath)
end
table.sort(makeDirs)
write("Creating %d folders...", #makeDirs)
plat.mkdir(root)
for i = 1, #makeDirs do
if plat.mkdir(plat.path(root, makeDirs[i])) then
write("Create folder: %s", makeDirs[i])
else
write("Could not create folder: %s", makeDirs[i])
end
UpdateProgress(i / #makeDirs)
end
return dirs
end
end
local ExtractFiles do
function ExtractFiles(fileType)
local files = GetFileList(fileType)
local root = "./"
if filter == "all" then
root = "BlizzardInterface" .. fileTypes[fileType]
end
local dirs = CreateDirectories(files, root)
local file, filePath, fixedCase
local function FixCase(b)
local s = filePath:sub(1, b - 1)
--print("fixedCase", filePath, b, s)
return dirs[s:lower()]:match("([^/]+/)$")
end
local pathStatus, w, h, err = {}
write("Creating %d files...", #files)
for i = 1, #files do
file = files[i]
filePath = file.fullPath
fixedCase = (filePath:gsub("[^/]+()/", FixCase))
if not pathStatus[file.path] then
pathStatus[file.path] = 0
end
w = fileHandle:readFile(file.fullPath)
if w then
write("Create file: %s", fixedCase)
h, err = io.open(plat.path(root, fixedCase), "wb")
if h then
h:write(w)
h:close()
pathStatus[file.path] = pathStatus[file.path] + 1
if convertBLP then
convert(plat.path(root, file.path))
end
else
write("Could not open file %s: %s", filePath, err)
end
else
write("No data for file %s", filePath)
end
UpdateProgress(i / #files)
end
local emptyDirs = {}
for path, total in next, pathStatus do
if total <= 0 then
table.insert(emptyDirs, path)
end
end
table.sort(emptyDirs, function(a, b)
return a > b
end)
write("Cleaning up empty directories...")
for i = 1, #emptyDirs do
local _, status = rmdir(plat.path(root, emptyDirs[i]))
if not status then
write("Removed: %s", emptyDirs[i])
end
end
end
end
if filter == "all" then
ExtractFiles("code")
ExtractFiles("art")
else
ExtractFiles(filter)
end