-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbbupdater
65 lines (57 loc) · 1.59 KB
/
rbbupdater
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- 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)
print("Downloading, " .. fname)
local data = http.get(getLink(fname))
if data then
print(file .. " downloaded")
local file = fs.open(name,"w")
file.write(data.readAll())
file.close()
return true
end
end
--~ ##### Original Henness code END #####
function isNewer(oldfile, newfile)
-- I don't want to kill your settings ;)
if oldfile == "config" then
return false
end
fold = fs.open(oldfile, "r")
fnew = fs.open(newfile, "r")
foldversion = fold.readLine()
fnewversion = fnew.readLine()
fold.close()
fnew.close()
foldversion = strsub (foldversion, strfind (foldversion, "="))
fnewversion = strsub (fnewversion, strfind (fnewversion, "="))
return tonumber(foldversion) < tonumber(fnewversion)
end
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 isNewer(dir..fname, dir..fname.."tmp") then
fs.delete(dir..fname)
fs.move(dir..fname.."tmp", dir..fname)
else
fs.delete(dir..fname.."tmp")
end
end
end
downloadAll()
checkAll()