Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Update the server for ShadOS update server by PaymentOption --
- VERSION = "Alpha 0.0.1"
- -----------------------------------------------------------------
- rednet.open("top")
- rednet.open("left")
- rednet.open("right")
- rednet.open("back")
- rednet.open("bottom")
- -- VARS --
- serverID = 488
- bNewFile = false
- selection = 1
- ----------
- -- Helper Functions --
- function cPrint(height, string)
- local w,h = term.getSize()
- local xPos = w/2 - string.len(string)/2
- term.setCursorPos(xPos, height)
- term.write(string)
- end
- function rPrint(height, string)
- local w,h = term.getSize()
- local xPos = w - string.len(string)
- term.setCursorPos(xPos, height)
- term.write(string)
- end
- function printBorder()
- local w,h = term.getSize()
- write(" ".. string.rep('*', w-2).."\n")
- for i=1, h-2 do write(" "..'*'..string.rep(" ", w-4)..'*'.."\n") end
- write(" ".. string.rep('*', w-2))
- end
- function readFile(sPath)
- local file = fs.open(tostring(sPath), "r")
- local fileContents = file.readAll(); file.close(); return fileContents
- end
- function clear() term.clear(); term.setCursorPos(1,1) end
- ----------------------
- -- Menues and other screens --
- function printLogo()
- cPrint(4, " -_-/ ,, |\\ ,-||-, -_-/ ")
- cPrint(5, " (_ / || _ \\\\ ('||| ) (_ / ")
- cPrint(6, "(_ --_ ||/\\\\ < \\, / \\\\ (( |||--)) (_ --_ ")
- cPrint(7, " --_ ) || || /-|| || || (( |||--)) --_ ) ")
- cPrint(8, " _/ )) || || (( || || || ( / | ) _/ )) ")
- cPrint(9, "(_-_- \\\\ |/ \\/\\\\ \\\\/ -____- (_-_- ")
- cPrint(10, " _/ ")
- end
- function printMenu()
- cPrint(2, "ShadOS Master Update")
- rPrint(15, "Version: "..VERSION)
- end
- function printOptions()
- if selection == 1 then cPrint(7, "[Yes] No ")
- else cPrint(7, " Yes [No]") end
- end
- ------------------------------
- -- File related functions --
- function getNewFile()
- local w,h = term.getSize()
- while true do
- term.setCursorPos(1,6); term.clearLine()
- term.setCursorPos(1, 6); term.clearLine();
- term.setCursorPos(1, 6); term.clearLine(); write(" *"..string.rep(" ", w-4).."* ")
- cPrint(6, "Any new files?"); printOptions()
- event, key = os.pullEvent("key")
- if key == 205 and selection == 1 then selection = 2
- elseif key == 203 and selection == 2 then selection = 1
- elseif key == 28 and selection == 1 then bNewFile = true; break
- elseif key == 28 and selection == 2 then bNewFile = false; break
- end
- end
- if bNewFile == true then
- clear(); term.setCursorPos(3, 16); write("*That includes directories!")
- term.setCursorPos(6, 6); write("New File Path: "); sPath = read()
- file = fs.open(tostring(sPath), "r"); fileContents = file.readAll(); file.close()
- return tostring(sPath), tostring(fileContents)
- else
- clear(); printBorder(); cPrint(6, "All done! :D"); sleep(2); return false
- end
- end
- function updateFiles()
- rednet.send(serverID, "upload")
- local file = ""; local fileContents = ""; local sPath = nil
- sender, message = rednet.receive(0.8)
- cPrint(6, "Sending files from startup and ShadOS/ ...")
- if sender == serverID and message == "ready" then
- file = fs.open("startup", "r")
- fileContents = file.readAll()
- file.close()
- rednet.send(serverID, fileContents); sleep(0.1)
- fileContents = readFile("ShadOS/main")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/change"); rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/originalos"); rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Programs/calc")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Programs/irc")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Programs/menu")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Games/laserblast")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Games/rpg")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Games/shadomon")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Games/menu")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- fileContents = readFile("ShadOS/Movies/menu")
- rednet.send(serverID, tostring(fileContents)); sleep(0.1)
- repeat
- path, message = getNewFile()
- rednet.send(serverID, tostring(path))
- if path ~= false then rednet.send(serverID, message)
- else rednet.send(serverID, "false") end
- until path == false
- clear(); printBorder(); cPrint(6, "Success!"); sleep(1.3); clear()
- else cPrint(6, "Failure: Request not acknowledged"); sleep(1.3); clear() end --]]
- end
- ----------------------------
- clear(); printLogo(); clear()
- printBorder(); printMenu(); updateFiles()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement