Created
March 3, 2016 04:24
-
-
Save Gethe/1342d8c5c9c4a60c926e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local casc = require("casc") | |
casc.GetImpl() | |
local filter, root = {} do | |
local code = arg[1] == 'code' or arg[1] == 'both' or arg[1] == nil | |
local art = arg[1] == 'art' or arg[1] == 'both' | |
root = "BlizzardInterface" .. (code and "Code" or art and "Art") | |
filter.xml, filter.lua, filter.toc, filter.xsd = code, code, code, code | |
filter.blp = art | |
end | |
print("If you have a local WoW installation, you can specify the path to its Data directory to avoid downloading redundant data.") | |
local localBase, ch, err = arg[2] or io.stdout:write("Local Data/ path: ") and io.read("*l") | |
print("localBase", type(localBase), localBase) | |
if localBase and localBase ~= "" then | |
ch, err = casc.open(localBase, {locale="US", log = print}) | |
else | |
ch, err = assert(casc.open("http://us.patch.battle.net/wowb/#us", {cache="./cache"})) | |
end | |
if not ch then | |
return print(err) | |
end | |
local dbcFileData = ch:readFile("DBFilesClient/FileData.dbc") | |
local dbc, files = require("casc.dbc"), {} | |
for i, name, path in dbc.rows(dbcFileData, '.ss') do | |
if path:match("^[Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee][\\/]") and filter[(name:match("%.(...)$") or ""):lower()] then | |
files[#files+1] = (path .. name):gsub("[/\\]+", "/") | |
end | |
end | |
local l = setmetatable({}, {__index=function(s, a) s[a] = a:lower() return s[a] end}) | |
table.sort(files, function(a, b) return l[a] < l[b] end) | |
local dirs = {} | |
for i=1,#files do | |
local p = files[i] | |
for ep in p:gmatch("()/") do | |
local p = p:sub(1,ep-1) | |
local lc, _, tc = p:lower(), p:match("[^/]+$"):gsub("[A-Z][a-z]", "%0") | |
if (dirs[lc] and dirs[lc][1] or -1) < tc then | |
dirs[lc] = {tc, p} | |
end | |
end | |
end | |
local plat, makeDirs = require("casc.platform"), {} | |
for k, v in pairs(dirs) do | |
table.insert(makeDirs, v[2]) | |
end | |
table.sort(makeDirs, function(a,b) return #a < #b end) | |
plat.mkdir(root) | |
for i=1,#makeDirs do | |
plat.mkdir(plat.path(root, makeDirs[i])) | |
end | |
local fails = {} | |
for i=1,#files do | |
local f = files[i] | |
local fixedCase = (f:gsub("[^/]+()/", function(b) | |
local s = f:sub(1,b-1) | |
--print(s) | |
return dirs[s:lower()][2]:match("([^/]+/)$") | |
end)) | |
local h = io.open(plat.path(root, fixedCase), "wb") | |
local w = ch:readFile(f) | |
if w then | |
h:write(w) | |
h:close() | |
print(fixedCase) | |
else | |
table.insert(fails, fixedCase) | |
print("failed", fixedCase) | |
end | |
end | |
if #fails > 0 then | |
local file = assert(io.open("fails.txt", "w")) | |
for i = 1, #fails do | |
file:write(fails[i], "\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment