Posted 15 March 2014 - 04:48 PM
How do you make an updater from http API…
local f = http.get("http://pastebin.com/raw.php?i=PBCODE") --# Opens up the website as if it were a file
local fl = f.readAll() --# Reads the entire contents of the website and places them in a variable
f.close() --# Closes the website
Make sure to replace PBCODE with the code on pastebin, and f and fl with variables of your choice. Then you can simply use:
if u ~= fl then --# Checks to see if u (the file we're updating) and fl (the version on pastebin) are the same if not, the other stuff happens.
fs.delete("file") --# So, if they're not the same, delete the old file,
local nf = fs.open("file","w") --# open it back up,
nf.write(fl) --# write the new code to it,
nf.close() --# and close it again.
end
Make sure to replace u with the variable you used at the start for the contents of the file we're updating, fl to the variable you used for the contents of the file on pastebin, file to the name of the file we're updating and nf to the variable of your choice. Repeat for all files you want to update. When you want to update a file, log in to our pastebin account, go into 'my pastes' and edit it.
local cds = {
file1 = "MKccRkwa";
file2 = "2ZYa5fes";
}
local function updateFile(path,code)
local p = fs.open(path,"r")
local u = p.readAll()
p.close()
local f = http.get("http://pastebin.com/raw.php?i="..code)
local fl = f.readAll()
f.close()
if u ~= fl then
fs.delete(path)
local nf = fs.open(path,"w")
nf.write(fl)
nf.close()
return true
end
return false
end
local fls = fs.list("folder")
for i = 1,#fls do
updateFile("folder/"..fls[i],cds[fls[i]])
end
Again, this can be improved upon in many ways,