Advertisement
chezpaul

Minecraft Periodic Table

Oct 26th, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. -- installer/updater for the periodic table program
  2.  
  3. local github = "https://raw.github.com/InputUsername/Periodic-table/master/files/"
  4.  
  5. local files = {
  6. "ptable.lua",
  7. "ptable_elements.lua",
  8. "ptable_extra.lua",
  9. "ptable_image",
  10. "ptable_legend"
  11. }
  12.  
  13. fs.delete("/periodic_table")
  14. fs.makeDir("/periodic_table")
  15.  
  16. local function getf(f)
  17. local getfile = http.get(github..f)
  18. if (getfile) then
  19. local contents = getfile.readAll()
  20. if (contents) then
  21. if (string.find(f,"%.")) then
  22. f = string.match(f,"(.+)%.")
  23. end
  24. local destination = fs.open("/periodic_table/"..f,"w")
  25. destination.write(contents)
  26. destination.close()
  27. getfile.close()
  28. return true
  29. else
  30. getfile.close()
  31. return nil,"error while installing "..f
  32. end
  33. else
  34. return nil,"error while downloading "..f
  35. end
  36. end
  37.  
  38. local errors = 0
  39.  
  40. print("Welcome to the installer for Periodic table.")
  41. print("This will download files from")
  42. printError(github)
  43. print()
  44.  
  45. for i=1,#files do
  46. local ok,err = getf(files[i],files[i])
  47. if not (ok) then
  48. printError(err)
  49. errors = errors+1
  50. else
  51. print("Installed "..files[i])
  52. end
  53. end
  54. print()
  55.  
  56. if (errors > 0) then
  57. printError("There were some errors during installation.")
  58. printError("Would you like to try again? [y/n]")
  59. while true do
  60. local e,c = os.pullEvent("char")
  61. if (c == "y" or c == "Y") then
  62. return shell.run("/pt-update")
  63. else
  64. return
  65. end
  66. end
  67. end
  68.  
  69. print("Would you like to move the main program to the root directory? [y/n]")
  70. while true do
  71. local e,c = os.pullEvent("char")
  72. if (c == "y" or c == "Y") then
  73. return fs.move("/periodic_table/ptable","/ptable")
  74. else
  75. break
  76. end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement