Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 enter 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement