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