Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- BrainStone's APIs autoupdater
- -- Version 3.0
- --
- -- If you need your own startup script name it "startup.custom"
- --
- -- This script will automatically install and update BrainStone's APIs
- if not http then
- printError( "Pastebin requires http API" )
- printError( "Set http_enable to true in ComputerCraft.cfg" )
- return
- end
- function pastebin(id, name)
- local URI = "http://pastebin.com/raw.php?i=" .. textutils.urlEncode(id)
- local path = "api/" .. name
- local response = http.get(URI)
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( path, "w" )
- file.write( sResponse )
- file.close()
- else
- printError( "Failed." )
- end
- end
- function split(str)
- local t = {}
- local function helper(word) table.insert(t, word) return "" end
- if not str:gsub("[%w\\.]+", helper):find"%S" then return t end
- end
- function parseList()
- local list = {}
- local file = fs.open("api/list", "r")
- if file ~= nil then
- local line = file.readLine()
- local id, name, version
- while line do
- id, name, version = unpack(split(line) or {})
- if id ~= nil and id ~= "--" and name ~= nil and version ~= nil then
- list[name] = {id = id, version = version}
- end
- line = file.readLine()
- end
- file.close()
- end
- return list
- end
- if not fs.exists("updateBSAPIs") then
- local handle = fs.open("updateBSAPIs", "w")
- handle.writeLine("-- This script makes it easy to update")
- handle.writeLine("-- the BrainStone APIs")
- handle.writeLine("")
- handle.writeLine("shell.run(\"pastebin run V2uDhBFU update\")")
- handle.close()
- end
- local oldList = parseList()
- fs.delete("api/list")
- print("Fetching API list")
- pastebin("H2s81Dd0", "list")
- local newList = parseList()
- for name, val in pairs(newList) do
- if
- oldList[name] == nil or
- val.version ~= oldList[name].version or
- not fs.exists("api/" .. name) then
- print("Fetching " .. name)
- pastebin(val.id, name)
- end
- oldList[name] = nil
- end
- for name, _ in pairs(oldList) do
- print("Deleting " .. name)
- fs.delete("api/" .. name)
- end
- if fs.exists("startup.custom") then
- shell.run("startup.custom")
- end
- -- DO NOT REMOVE THIS THESE TWO LINES
- -- 4024a1f38967b6f8d01e32a34688b43a
Advertisement
Add Comment
Please, Sign In to add comment