dacman9

DacLauncher

Aug 23rd, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. --Variables
  2. local x,y = term.getSize()
  3. local myfiletable = nil
  4. if fs.exists("updates") then
  5. local f = fs.open("updates","r")
  6. myfiletable = textutils.unserialize(f.readAll())
  7. f.close()
  8. else
  9. local f = fs.open("updates","w")
  10. f.write("{}")
  11. myfiletable = {}
  12. f.close()
  13. end
  14. --Functions
  15. local fadein = function()
  16. paintutils.drawFilledBox(1,1,x,y,colors.gray)
  17. sleep(0.1)
  18. paintutils.drawFilledBox(1,1,x,y,colors.lightGray)
  19. sleep(0.1)
  20. paintutils.drawFilledBox(1,1,x,y,colors.white)
  21. end
  22. local centertext = function(t,m,p)
  23. local x,y = term.getSize()
  24. if t == 1 then
  25. term.setCursorPos((x-string.len(m))/2+1,p)
  26. term.write(m)
  27. elseif t == 2 then
  28. term.setCursorPos((x-string.len(m))/2+1,(y/2)+1)
  29. term.write(m)
  30. end
  31. end
  32. local loadingbar = function()
  33. local counter = 0
  34. while true do
  35. counter = counter + 1
  36. if counter == 5 then
  37. counter = 0
  38. end
  39. term.setCursorPos(3,4)
  40. for i = 3,x-2 do
  41. if math.fmod(term.getCursorPos()+counter,5) == 0 then
  42. term.blit("=","d","8")
  43. else
  44. term.blit("=","7","8")
  45. end
  46. end
  47. sleep(0.2)
  48. end
  49. end
  50. local filetable = nil
  51. local manageFiles = function()
  52. term.setBackgroundColor(colors.white)
  53. term.setTextColor(colors.gray)
  54. term.setCursorPos(3,6)
  55. term.write("Checking File Servers...")
  56. local files = http.get("https://raw.githubusercontent.com/TheDacinator/DacLauncher/master/updates")
  57. filetable = textutils.unserialize(files.readAll())
  58. files.close()
  59. if #myfiletable < #filetable then
  60. for i = #myfiletable+1,#filetable do
  61. myfiletable[i] = {filetable[i][1],filetable[i][2],0}
  62. end
  63. local f = fs.open("updates","w")
  64. f.write(textutils.serialize(myfiletable))
  65. f.close()
  66. end
  67. for i = 1,#myfiletable do
  68. if not fs.exists(myfiletable[i][2]) then
  69. myfiletable[i][3] = 0
  70. end
  71. end
  72. local f = fs.open("updates","w")
  73. f.write(textutils.serialize(myfiletable))
  74. f.close()
  75. while true do
  76. paintutils.drawFilledBox(1,5,x,y,colors.white)
  77. term.setBackgroundColor(colors.white)
  78. term.setTextColor(colors.gray)
  79. term.setCursorPos(3,6)
  80. for i = 1,#filetable do
  81. if myfiletable[i][3] == 0 then
  82. term.blit("0 ","ee","00")
  83. elseif myfiletable[i][3] < filetable[i][3] then
  84. term.blit("0 ","44","00")
  85. elseif myfiletable[i][3] == filetable[i][3] then
  86. term.blit("0 ","55","00")
  87. end
  88. term.write(filetable[i][2])
  89. term.setCursorPos(3,6+i)
  90. end
  91. term.setTextColor(colors.red)
  92. term.write("Exit")
  93. local e,a,b,c = os.pullEvent("mouse_click")
  94. if c > 5 and c < #filetable+6 and myfiletable[c-5][3] < filetable[c-5][3] then
  95. paintutils.drawFilledBox(1,5,x,y,colors.white)
  96. term.setCursorPos(3,6)
  97. term.setTextColor(colors.gray)
  98. term.write("Update? (y/n)")
  99. local e,f = os.pullEvent("char")
  100. if f == "y" then
  101. term.setCursorPos(3,6)
  102. term.write("Updating... ")
  103. local file = http.get(filetable[c-5][1])
  104. local program = file.readAll()
  105. file.close()
  106. file = fs.open(filetable[c-5][2],"w")
  107. file.write(program)
  108. file.close()
  109. myfiletable[c-5][3] = filetable[c-5][3]
  110. local file = fs.open("updates","w")
  111. file.write(textutils.serialize(myfiletable))
  112. file.close()
  113. sleep(1)
  114. term.setCursorPos(3,6)
  115. term.setTextColor(colors.lime)
  116. term.write("Done! ")
  117. sleep(1)
  118. end
  119. elseif c == #filetable+6 then
  120. break
  121. end
  122. end
  123. end
  124. --Code
  125. fadein()
  126. term.setBackgroundColor(colors.white)
  127. term.setTextColor(colors.green)
  128. centertext(1,"DacLauncher",2)
  129. paintutils.drawFilledBox(1,4,x,4,colors.lightGray)
  130. parallel.waitForAny(loadingbar,manageFiles)
  131. term.setTextColor(colors.white)
  132. term.setBackgroundColor(colors.black)
  133. term.clear()
  134. term.setCursorPos(1,1)
Add Comment
Please, Sign In to add comment