-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbdump.lua
More file actions
70 lines (66 loc) · 1.6 KB
/
dbdump.lua
File metadata and controls
70 lines (66 loc) · 1.6 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
local product = arg[1] or 'wow'
local dbtoexport = arg[2]
local handle, version = (function()
local casc = require('casc')
local url = 'http://us.patch.battle.net:1119/' .. product
local bkey, cdn, ckey, version = casc.cdnbuild(url, 'us')
assert(bkey)
print('loading ' .. version)
local handle = casc.open({
bkey = bkey,
cache = 'cache',
cacheFiles = true,
cdn = cdn,
ckey = ckey,
locale = casc.locale.US,
log = print,
})
return handle, version
end)()
local dbds = require('luadbd').dbds
local function process(dbd, cb)
local tn = dbd.name
local data = handle:readFile(dbd.fdid)
if not data then
print('no data for ' .. tn)
return
end
local build = dbd:build(version)
if not build then
print('no build for ' .. tn)
return
end
print('reading ' .. tn .. ':' .. build.sig .. ':' .. dbd.fdid)
local success, iterfn, iterdata = pcall(function()
return build:rows(data)
end)
if not success then
print('failed to get row iterator on ' .. tn .. ': ' .. iterfn)
return
end
local itersuccess, err = pcall(function()
local rows = 0
for t in iterfn, iterdata do
rows = rows + 1
cb(build.fields, t)
end
print(rows .. ' rows')
end)
if not itersuccess then
print('failed to iterate through ' .. tn .. ': ' .. err)
return
end
end
if dbtoexport then
process(dbds[dbtoexport], function(fields, t)
local toprint = {}
for f, i in pairs(fields) do
toprint[f] = t[i]
end
require('pl.pretty').dump(toprint)
end)
else
for _, dbd in pairs(dbds) do
process(dbd, function() end)
end
end