Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- installer/updater for the periodic table program
- local github = "https://raw.github.com/InputUsername/Periodic-table/master/files/"
- local files = {
- "ptable.lua",
- "ptable_elements.lua",
- "ptable_extra.lua",
- "ptable_image",
- "ptable_legend"
- }
- fs.delete("/periodic_table")
- fs.makeDir("/periodic_table")
- local function getf(f)
- local getfile = http.get(github..f)
- if (getfile) then
- local contents = getfile.readAll()
- if (contents) then
- if (string.find(f,"%.")) then
- f = string.match(f,"(.+)%.")
- end
- local destination = fs.open("/periodic_table/"..f,"w")
- destination.write(contents)
- destination.close()
- getfile.close()
- return true
- else
- getfile.close()
- return nil,"error while installing "..f
- end
- else
- return nil,"error while downloading "..f
- end
- end
- local errors = 0
- print("Welcome to the installer for Periodic table.")
- print("This will download files from")
- printError(github)
- print()
- for i=1,#files do
- local ok,err = getf(files[i],files[i])
- if not (ok) then
- printError(err)
- errors = errors+1
- else
- print("Installed "..files[i])
- end
- end
- print()
- if (errors > 0) then
- printError("There were some errors during installation.")
- printError("Would you like to try again? [y/n]")
- while true do
- local e,c = os.pullEvent("char")
- if (c == "y" or c == "Y") then
- return shell.run("/pt-update")
- else
- return
- end
- end
- end
- print("Would you like to move the main program to the root directory? [y/n]")
- while true do
- local e,c = os.pullEvent("char")
- if (c == "y" or c == "Y") then
- return fs.move("/periodic_table/ptable","/ptable")
- else
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement