dacman9

DacLauncher

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