JZTech101

Untitled

Jun 1st, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. local debug=true
  2. local currentVersion="1"
  3. local boxPastebin="VTqiayCe"
  4. local snapPastebin="YzLLYEzm"
  5. local clearSettingsPastebin="aa5cBF43"
  6.  
  7. function toggleUpdates()
  8. if debug==true then
  9. print("In toggleUpdates")
  10. end
  11. print[[Do you wish to receive automatic updates?
  12. 1. Yes
  13. 2. No]]
  14. local choice=io.read()
  15.  
  16. if choice=="1" then
  17. changeUpdates(true)
  18. else
  19. changeUpdates(false)
  20. end
  21. end
  22.  
  23. function changeUpdates(updates)
  24. if debug==true then
  25. print(string.format ( "in changeUpdates - updates= %s", updates and "true" or "false" ))
  26. end
  27. fs.delete("updating")
  28. if updates==true then
  29. local file = fs.open("updating","w")
  30. file.write("A fish swam into a wall - OW - DAMN")
  31. file.close()
  32. end
  33. end
  34.  
  35. function doWeCheckUpdates()
  36. local file = fs.open("updating","r")
  37. if file==nil then
  38. return false
  39. else
  40. file.close()
  41. return true
  42. end
  43.  
  44. end
  45.  
  46. function firstRun()
  47. if debug==true then
  48. print("In firstRun")
  49. end
  50.  
  51. --see if we have a first run file
  52. local file = fs.open("firstRun","r")
  53. if file==nil then
  54. if debug==true then
  55. print("First time program is run - creating firstRun file")
  56. end
  57. toggleUpdates()
  58. local file = fs.open("firstRun","w")
  59. file.write("Why are you even looking in here :)")
  60. file.close()
  61. else
  62. file.close()
  63. end
  64.  
  65. end
  66.  
  67. function createCurrentFile()
  68. if debug==true then
  69. print("in createCurrentFile()")
  70. end
  71. local file = fs.open("currentLauncherVersion","r")
  72. if file==nil then
  73. print("No Version File Found - Creating with version "..currentVersion)
  74. local file = fs.open("currentLauncherVersion","w")
  75. file.write(currentVersion)
  76. file.close()
  77. else
  78. file.close()
  79. end
  80.  
  81. end
  82.  
  83. function updateLauncher()
  84. if debug==true then
  85. print("In updateLauncher")
  86. end
  87. print("Updates Found - Updating Launcher")
  88. fs.delete("startup")
  89. shell.run("rom/programs/http/pastebin", "get P65y2rkJ startup")
  90. fs.delete("currentLauncherVersion")
  91. print("Update complete. Please restart the program. Closing in 5 seconds")
  92. sleep(5)
  93. os.reboot()
  94. end
  95.  
  96. function checkForUpdates()
  97. if doWeCheckUpdates()==true then
  98. print("Checking for updates..")
  99. --check for the newest version number
  100. fs.delete("newestLauncherVersion")
  101. shell.run("rom/programs/http/pastebin", "get ZD3HcUC8 newestLauncherVersion")
  102. local file = fs.open("newestLauncherVersion","r")
  103. local newest = file.readAll()
  104. file.close()
  105. --get the current version number
  106. local file = fs.open("currentLauncherVersion","r")
  107. local current = file.readAll()
  108. file.close()
  109. if newest>current then
  110. updateLauncher()
  111. else
  112. print("No updates found...you are running the current version")
  113. end
  114. end
  115. end
  116.  
  117. function checkForLastChoice()
  118. local lastChoice=nil
  119. if debug==true then
  120. print("In lastChoice")
  121. end
  122. local file = fs.open("lastChoice","r")
  123. if file~=nil then
  124. lastChoice = file.readAll()
  125. file.close()
  126. end
  127. return lastChoice
  128. end
  129.  
  130. function resumeLastChoice()
  131. local choice=checkForLastChoice()
  132. if choice=="Box" then
  133. runBox()
  134. elseif choice=="Snap" then
  135. runSnap()
  136. end
  137. end
  138.  
  139. function setLastChoice(choice)
  140. local file = fs.open("lastChoice","w")
  141. file.write(choice)
  142. file.close()
  143. end
  144.  
  145. function runBox()
  146. if doWeCheckUpdates()==true then
  147. downloadFile("box",boxPastebin)
  148. downloadFile("clearsettings",clearSettingsPastebin)
  149. end
  150. if fs.exists("box")==false then
  151. downloadFile("box",boxPastebin)
  152. downloadFile("clearsettings",clearSettingsPastebin)
  153. end
  154. shell.run("box")
  155. end
  156.  
  157. function runSnap()
  158. if doWeCheckUpdates()==true then
  159. downloadFile("snap",snapPastebin)
  160. end
  161. if fs.exists("snap")==false then
  162. downloadFile("snap",snapPastebin)
  163. end
  164. shell.run("snap")
  165. end
  166.  
  167. function downloadFile(filename,pastebin)
  168. fs.delete(filename)
  169. shell.run("rom/programs/http/pastebin", "get "..pastebin.." "..filename)
  170. end
  171.  
  172. function mainMenu()
  173. if checkForLastChoice()~=nil then
  174. resumeLastChoice()
  175. end
  176.  
  177. if debug==true then
  178. print("In mainMenu")
  179. end
  180. print [[------Psyestorm's Turtle Launcher------
  181. 1. Box - Mining Turtle
  182. 2. Snap - Engineering Turtle
  183. 0. Toggle Automatic Updates]]
  184.  
  185. local choice=nil
  186. while choice==nil do
  187. choice=io.read()
  188. if choice=="1" then
  189. setLastChoice("Box")
  190. runBox()
  191. elseif choice=="2" then
  192. setLastChoice("Snap")
  193. runSnap()
  194. elseif choice=="0" then
  195. toggleUpdates()
  196. else
  197. choice=nil
  198. end
  199. print(choice)
  200. end
  201. end
  202.  
  203. --check if this is the first time the launcher has been run
  204. firstRun()
  205. createCurrentFile()
  206. checkForUpdates()
  207. mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment