Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Updating the Dungeon core files!")
- local all = {}
- if fs.exists(":dungeon/hashes") then
- local open = fs.open(":dungeon/hashes", "r")
- all = open.readAll()
- open.close()
- all = textutils.unserialize(all)
- end
- if not fs.exists(":dungeon/dcore/apis/JSON.lua") then
- local x = http.get("https://raw.githubusercontent.com/wergat/DungeonMap/master/dcore/apis/JSON.lua").readAll()
- local open = fs.open(":dungeon/dcore/apis/JSON.lua", "w")
- open.write(x)
- open.close()
- end
- JSON = assert(loadfile ":dungeon/dcore/apis/JSON.lua")()
- if not http then
- printError("No HTTP!")
- error()
- end
- local files_updated = 0
- local function downloadFromDir(url)
- local x = http.get(url)
- if x then
- x = x.readAll()
- else
- local now = http.get("http://www.timeapi.org/utc/now").readAll()
- now = now:sub(15,16)
- now = tonumber(now)
- local minutes = 60 - now
- local pstr = "minutes"
- if minutes == 1 then
- pstr = "minute"
- end
- printError("Oops! It looks like you've installed the DungeonMap files too much recently. Try again in about " .. minutes .. " " .. pstr .. "!")
- error()
- end
- x = JSON:decode(x)
- for i = 1, #x do
- local f = x[i]
- local path = f["path"]
- if f["sha"] == all[path] then
- print("Found file that doesn't need to be updated.")
- elseif f["type"] == "dir" then
- print("Downloading directory " .. f["sha"])
- all[path] = f["sha"]
- downloadFromDir(f["url"])
- else
- print("Downloading file " .. f["sha"])
- local xt = http.get(f["download_url"]).readAll()
- local open = fs.open("dungeon/" .. path, "w")
- open.write(xt)
- open.close()
- all[path] = f["sha"]
- files_updated = files_updated + 1
- end
- end
- end
- downloadFromDir("https://api.github.com/repos/wergat/DungeonMap/contents/")
- print("Finished updating! " .. files_updated .. " files have been updated.")
- local open = fs.open(":dungeon/hashes", "w")
- open.write(textutils.serialize(all))
- open.close()
Advertisement
Add Comment
Please, Sign In to add comment