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