8 for i, a in ipairs({...}) do
9 local mode, option = select(3, string.find(a, "^([%+%-]?)(.*)$"))
13 if option == "zip" then archive_zip = mode
14 elseif option == "7z" then archive_7z = mode
15 elseif option == "compile" then compile = mode
16 elseif option == "external" then external = mode
18 print("Unknown option: "..option)
24 local cache_loader = loadfile("build-cache.lua")
30 if not cache.removed then cache.removed = {} end
31 if not cache.known then cache.known = {} end
32 if not cache.ignored then cache.ignored = {} end
33 if not cache.uid then cache.uid = {} end
36 for uid, data in pairs(cache.uid) do file2uid[data.file] = uid end
38 loadfile("dump.lua")()
39 loadfile("fileutil.lua")()
40 loadfile("../upgrade.lua")()
41 loadfile("compiler.lua")()
42 --loadfile("external.lua")()
44 QuestHelper_BuildZoneLookup()
47 FileUtil.updateSVNRepo("http://svn.esamynn.org/astrolabe/trunk", "../Astrolabe")
48 FileUtil.updateSVNRepo("http://svn.wowace.com/wowace/trunk/ChatThrottleLib", "../ChatThrottleLib")
52 local function saveCache()
53 local stream = io.open("build-cache.lua", "w")
54 local buffer, prebuf = CreateBuffer(), CreateBuffer()
55 DumpVariable(buffer, prebuf, cache, "cache")
56 stream:write(DumpingComplete(buffer, prebuf))
60 local all_input_files, unknown_input_files = {}, {}
62 FileUtil.forEachFile("LocalInput", function (name)
63 if FileUtil.extension(name) == "lua" or
64 FileUtil.extension(name) == "bak" then
65 local hash = FileUtil.fileHash(name)
66 if cache.ignored[hash] then return end
67 cache.ignored[hash] = true
69 local input = loadfile(name)
74 if not (data.QuestHelper_Locale and data.QuestHelper_Objectives) then
75 print("! "..name.." isn't a QuestHelper SavedVariables file.")
79 local tempname = os.tmpname()
80 local stream = io.open(tempname, "w")
82 print("Copying/Sorting "..name)
83 stream:write(ScanAndDumpVariable(data, nil, true) or "")
85 hash = FileUtil.fileHash(tempname)
87 local input_name = "Input/"..hash..".lua"
88 if not cache.removed[input_name] then
89 if not cache.known[input_name] then
90 FileUtil.copyFile(tempname, input_name)
91 unknown_input_files[input_name] = name
93 cache.known[input_name] = name
96 cache.removed[input_name] = name
99 print("!!! Can't get hash of "..tempname..", for "..name)
101 FileUtil.unlinkFile(tempname)
104 print("!!! "..name.." couldn't be executed.")
107 print("!!! "..name.." couldn't be loaded.")
112 FileUtil.forEachFile("Input", function (name)
113 if cache.removed[name] then
114 print("!!! Obsolete: ", cache.removed[name].." ("..name..")")
117 if not cache.known[name] then
118 unknown_input_files[name] = unknown_input_files[name] or name
121 all_input_files[name] = cache.known[name] or unknown_input_files[name]
125 local function ProcessObjective(category, name, objective, result)
126 local istring = "obj."..category.."."..name
128 if category ~= "item" then
130 if objective.pos then for i, pos in pairs(objective.pos) do
134 result[istring..".seen"] = (result[istring..".seen"] or 0) + seen
137 if objective.vendor then
138 result[istring..".vend"] = (result[istring..".vend"] or 0) + #objective.vendor
141 if objective.drop then for monster, count in pairs(objective.drop) do
142 result[istring] = (result[istring] or 0) + count
146 local function ProcessQuest(faction, level, name, quest, result)
147 local qstring = "quest."..faction.."."..level.."."..name
148 result[qstring] = (result[qstring] or 0)+((quest.finish or quest.pos) and 1 or 0)
150 if quest.item then for item_name, data in pairs(quest.item) do
151 ProcessObjective("item", item_name, data, result)
154 if quest.alt then for _, quest2 in pairs(quest.alt) do
155 ProcessQuest(faction, level, name, quest2, result)
159 local function LoadFile(file)
160 local data = loadfile(file)
164 setfenv(data, loaded)
167 QuestHelper_UpgradeDatabase(loaded)
169 if loaded.QuestHelper_UID then
170 result.uid = loaded.QuestHelper_UID
171 result.time = loaded.QuestHelper_SaveDate
173 if type(loaded.QuestHelper_Quests) == "table" then for faction, levels in pairs(loaded.QuestHelper_Quests) do
174 if type(levels) == "table" then for level, quest_list in pairs(levels) do
175 if type(quest_list) == "table" then for name, quest in pairs(quest_list) do
176 ProcessQuest(faction, level, name, quest, result)
181 if type(loaded.QuestHelper_Objectives) == "table" then for category, objectives in pairs(loaded.QuestHelper_Objectives) do
182 if type(objectives) == "table" then for name, objective in pairs(objectives) do
183 ProcessObjective(category, name, objective, result)
192 local function ObsoletedBy(data1, data2)
193 if data1.uid or data2.uid then
194 return data1.loc == data2.loc and data1.uid == data2.uid and (data1.time or 0) >= (data2.time or 0)
197 for key, value in pairs(data1) do
198 local value2 = data2[key]
199 if value2 == nil or value2 < value then
209 for new_name, original_name in pairs(unknown_input_files) do
210 print("Checking: ", original_name)
211 local data = file_data[new_name]
213 data = LoadFile(new_name)
214 file_data[new_name] = data
216 cache.known[new_name] = original_name
217 checked[new_name] = true
219 local uid, last_save = data.uid, data.time
222 local existing = cache.uid[uid]
224 cache.uid[uid] = {file=new_name, save=last_save}
225 file2uid[new_name] = uid
227 if existing.save >= last_save then
228 print("!!! Obsolete: ", original_name)
229 print("!!! By: ", all_input_files[existing.file])
232 file_data[new_name] = nil
233 all_input_files[new_name] = nil
234 cache.removed[new_name] = original_name
235 cache.known[new_name] = nil
236 unknown_input_files[new_name] = nil
238 print("!!! Obsolete: ", all_input_files[existing.file])
239 print("!!! By: ", original_name)
242 os.remove(existing.file)
243 file_data[existing.file] = nil
244 file2uid[existing.file] = nil
245 file2uid[new_name] = uid
246 cache.removed[existing.file] = all_input_files[existing.file]
247 all_input_files[existing.file] = nil
248 cache.known[existing.file] = nil
249 existing.file = new_name
253 for existing_name, existing_original_name in pairs(all_input_files) do
254 if not checked[existing_name] and not file2uid[existing_name] then
255 local data2 = file_data[existing_name]
257 data2 = LoadFile(existing_name)
258 file_data[existing_name] = data2
261 if not data2.uid then
262 if ObsoletedBy(data, data2) then
263 print("!!! Obsolete: ", original_name)
264 print("!!! By: ", existing_original_name)
268 file_data[new_name] = nil
269 all_input_files[new_name] = nil
270 cache.removed[new_name] = original_name
271 cache.known[new_name] = nil
272 unknown_input_files[new_name] = nil
274 elseif ObsoletedBy(data2, data) then
275 print("!!! Obsolete: ", existing_original_name)
276 print("!!! By: ", original_name)
279 os.remove(existing_name)
280 file_data[existing_name] = nil
281 all_input_files[existing_name] = nil
282 cache.removed[existing_name] = existing_original_name
283 cache.known[existing_name] = nil
284 unknown_input_files[existing_name] = nil
292 checked, file_data = nil, nil
296 --print("Compiling Lightheaded/eql3 data. . .")
299 for name, origin in pairs(all_input_files) do
300 print("Compiling: ", origin)
301 CompileInputFile(name)
304 print("Writing: ../static.lua")
306 local stream = io.open("../static.lua", "w")
307 stream:write(ScanAndDumpVariable(CompileFinish(), "QuestHelper_StaticData"))
309 elseif not FileUtil.fileExists("../static.lua") then
310 print("../static.lua doesn't exist; you can't skip the compile step.")
314 print("Creating: Icons.tga")
315 if not FileUtil.fileExists("../Art/Icons.tga") then
316 print("You'll need to manually create Art/Icons.tga, ImageMagick's SVG support seems to have been broken recently.")
318 --FileUtil.convertImage("Data/art.svg", "../Art/Icons.tga")
320 if archive_zip or archive_7z then
321 FileUtil.unlinkFile("QuestHelper")
323 FileUtil.createDirectory("QuestHelper")
324 FileUtil.createDirectory("QuestHelper/Art")
325 FileUtil.createDirectory("QuestHelper/Astrolabe")
326 FileUtil.createDirectory("QuestHelper/ChatThrottleLib")
328 FileUtil.forEachFile("..", function (file)
329 local ext = FileUtil.extension(file)
331 FileUtil.copyFile(file, "QuestHelper")
332 elseif ext == "toc" then
333 -- Modify the version to include the date and hash of the most recent commit.
336 local stream = io.popen("git-log -1 --pretty=\"format:, %h, %ai\"", "r")
338 info = stream:read("*line")
342 FileUtil.copyFile(file, "QuestHelper", "^(##%s-Version%s-:.*)$", "%1"..(info or ", unknown revision"))
346 FileUtil.forEachFile("../Art", function (file)
347 local ext = FileUtil.extension(file)
348 if ext == "blp" or ext == "tga" then
349 FileUtil.copyFile(file, "QuestHelper/Art")
353 for i, dir in ipairs({"Astrolabe", "ChatThrottleLib"}) do
354 FileUtil.forEachFile("../"..dir, function (file)
355 FileUtil.copyFile(file, "QuestHelper/"..dir)
360 print("Creating QuestHelper.zip")
361 FileUtil.unlinkFile("../QuestHelper.zip")
362 FileUtil.createZipArchive("QuestHelper", "../QuestHelper.zip")
366 print("Creating QuestHelper.7z")
367 FileUtil.unlinkFile("../QuestHelper.7z")
368 FileUtil.create7zArchive("QuestHelper", "../QuestHelper.7z")
371 FileUtil.unlinkFile("QuestHelper")