Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ccGUI-API Updater by DerKoch AKA RoyalBingBong
- -- Original idea for updater by Henness's "Advanced Updater"
- -- Config
- local author = "RoyalBingBong"
- local project = "ccGUI-API"
- local branch = "master"
- local files = {"guiElements", "helper", "screen", "config"}
- local dir = "RBB/"
- --~ ##### Original Henness code START #####
- function getLink(file)
- return "https://raw.github.com/" .. author .. "/" .. project .. "/" .. branch .. "/" .. file
- end
- function download(fname, name)
- write("Downloading: " .. fname)
- local data = http.get(getLink(fname))
- if data then
- write("\t\tDone\n")
- local file = fs.open(name,"w")
- file.write(data.readAll())
- file.close()
- return true
- end
- return false
- end
- --~ ##### Original Henness code END #####
- -- Checks if newfile is newer than oldfile
- -- Opens each files reads the first line and does some string operations
- -- to get the version number of each
- function isNewer(oldfile, newfile)
- -- I don't want to kill your settings ;)
- if oldfile == dir.."config" then
- return false
- end
- fold = fs.open(oldfile, "r")
- fnew = fs.open(newfile, "r")
- if not fold then
- return true
- end
- foldversion = fold.readLine()
- fnewversion = fnew.readLine()
- fold.close()
- fnew.close()
- local splitpos = string.find (foldversion, "=") + 2
- foldversion = string.sub (foldversion, splitpos)
- local splitpos = string.find (fnewversion, "=") + 2
- fnewversion = string.sub (fnewversion, splitpos)
- return tonumber(foldversion) < tonumber(fnewversion)
- end
- -- Downloads all files
- function downloadAll()
- for _, fname in pairs(files) do
- download(fname, dir .. fname .. "tmp")
- end
- end
- -- Deletes or renames files according to their version number
- function checkAll()
- for _,fname in pairs(files) do
- if fs.exists(dir..fname) then
- if isNewer(dir..fname, dir..fname.."tmp") then
- print("Deleting old " .. fname)
- fs.delete(dir..fname)
- sleep(0.5)
- print("Renaming " .. fname.."tmp" .. " to " .. fname)
- fs.move(dir..fname.."tmp", dir..fname)
- else
- print(fname .. " is newest version")
- fs.delete(dir..fname.."tmp")
- end
- else
- print("Renaming " .. fname.."tmp" .. " to " .. fname)
- fs.move(dir..fname.."tmp", dir..fname)
- end
- end
- end
- -- Just creates the subdirectory for my API
- function setup()
- if not fs.exists(dir) then
- fs.makeDir(dir)
- end
- end
- setup()
- downloadAll()
- checkAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement