Advertisement
PaymentOption

updatetheserver

May 1st, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.96 KB | None | 0 0
  1. -- Update the server for ShadOS update server by PaymentOption --
  2. VERSION = "Alpha 0.0.1"
  3. -----------------------------------------------------------------
  4.  
  5. rednet.open("top")
  6. rednet.open("left")
  7. rednet.open("right")
  8. rednet.open("back")
  9. rednet.open("bottom")
  10.  
  11. -- VARS --
  12. serverID = 488
  13. bNewFile = false
  14. selection = 1
  15. ----------
  16.  
  17. -- Helper Functions --
  18. function cPrint(height, string)
  19.     local w,h = term.getSize()
  20.     local xPos = w/2 - string.len(string)/2
  21.    
  22.     term.setCursorPos(xPos, height)
  23.     term.write(string)
  24. end
  25.  
  26. function rPrint(height, string)
  27.     local w,h = term.getSize()
  28.     local xPos = w - string.len(string)
  29.    
  30.     term.setCursorPos(xPos, height)
  31.     term.write(string)
  32. end
  33.  
  34. function printBorder()
  35.     local w,h = term.getSize()
  36.     write(" ".. string.rep('*', w-2).."\n")
  37.     for i=1, h-2 do write(" "..'*'..string.rep(" ", w-4)..'*'.."\n") end
  38.     write(" ".. string.rep('*', w-2))
  39. end
  40.  
  41. function readFile(sPath)
  42.     local file = fs.open(tostring(sPath), "r")
  43.     local fileContents = file.readAll(); file.close(); return fileContents
  44. end
  45.  
  46. function clear() term.clear(); term.setCursorPos(1,1) end
  47. ----------------------
  48.  
  49. -- Menues and other screens --
  50. function printLogo()
  51.     cPrint(4, "  -_-/  ,,           |\\     ,-||-,     -_-/  ")
  52.     cPrint(5, " (_ /   ||      _     \\\\   ('|||  )   (_ /   ")
  53.     cPrint(6, "(_ --_  ||/\\\\  < \\,  / \\\\ (( |||--)) (_ --_  ")
  54.     cPrint(7, "  --_ ) || ||  /-|| || || (( |||--))   --_ ) ")
  55.     cPrint(8, " _/  )) || || (( || || ||  ( / |  )   _/  )) ")
  56.     cPrint(9, "(_-_-   \\\\ |/  \\/\\\\  \\\\/    -____-   (_-_-   ")
  57.     cPrint(10, "          _/                                 ")
  58. end
  59.  
  60. function printMenu()
  61.     cPrint(2, "ShadOS Master Update")
  62.     rPrint(15, "Version: "..VERSION)
  63. end
  64.  
  65. function printOptions()
  66.     if selection == 1 then cPrint(7, "[Yes] No ")
  67.     else                   cPrint(7, " Yes [No]") end
  68. end
  69. ------------------------------
  70.  
  71. -- File related functions --
  72. function getNewFile()
  73.     local w,h = term.getSize()
  74.     while true do
  75.             term.setCursorPos(1,6); term.clearLine()
  76.             term.setCursorPos(1, 6); term.clearLine();
  77.             term.setCursorPos(1, 6); term.clearLine(); write(" *"..string.rep(" ", w-4).."* ")
  78.             cPrint(6, "Any new files?"); printOptions()
  79.            
  80.             event, key = os.pullEvent("key")
  81.             if key == 205 and selection == 1 then selection = 2
  82.             elseif key == 203 and selection == 2 then selection = 1
  83.             elseif key == 28 and selection == 1 then bNewFile = true; break
  84.             elseif key == 28 and selection == 2 then bNewFile = false; break
  85.             end
  86.         end
  87.        
  88.         if bNewFile == true then
  89.             clear(); term.setCursorPos(3, 16); write("*That includes directories!")
  90.             term.setCursorPos(6, 6); write("New File Path: "); sPath = read()
  91.             file = fs.open(tostring(sPath), "r"); fileContents = file.readAll(); file.close()
  92.             return tostring(sPath), tostring(fileContents)
  93.         else
  94.             clear(); printBorder(); cPrint(6, "All done! :D"); sleep(2); return false
  95.         end
  96. end
  97.  
  98. function updateFiles()
  99.     rednet.send(serverID, "upload")
  100.     local file = ""; local fileContents = ""; local sPath = nil
  101.     sender, message = rednet.receive(0.8)
  102.     cPrint(6, "Sending files from startup and ShadOS/ ...")
  103.    
  104.     if sender == serverID and message == "ready" then
  105.         file = fs.open("startup", "r")
  106.         fileContents = file.readAll()
  107.         file.close()
  108.         rednet.send(serverID, fileContents); sleep(0.1)
  109.        
  110.         fileContents = readFile("ShadOS/main")
  111.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  112.        
  113.         fileContents = readFile("ShadOS/change"); rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  114.        
  115.         fileContents = readFile("ShadOS/originalos"); rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  116.        
  117.         fileContents = readFile("ShadOS/Programs/calc")
  118.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  119.        
  120.         fileContents = readFile("ShadOS/Programs/irc")
  121.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  122.        
  123.         fileContents = readFile("ShadOS/Programs/menu")
  124.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  125.        
  126.         fileContents = readFile("ShadOS/Games/laserblast")
  127.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  128.        
  129.         fileContents = readFile("ShadOS/Games/rpg")
  130.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  131.        
  132.         fileContents = readFile("ShadOS/Games/shadomon")
  133.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  134.        
  135.         fileContents = readFile("ShadOS/Games/menu")
  136.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  137.        
  138.         fileContents = readFile("ShadOS/Movies/menu")
  139.         rednet.send(serverID, tostring(fileContents)); sleep(0.1)
  140.        
  141.         repeat
  142.             path, message = getNewFile()
  143.             rednet.send(serverID, tostring(path))
  144.             if path ~= false then rednet.send(serverID, message)
  145.             else rednet.send(serverID, "false") end
  146.         until path == false
  147.         clear(); printBorder(); cPrint(6, "Success!"); sleep(1.3); clear()
  148.     else cPrint(6, "Failure: Request not acknowledged"); sleep(1.3); clear() end --]]
  149. end
  150. ----------------------------
  151.  
  152. clear(); printLogo(); clear()
  153. printBorder(); printMenu(); updateFiles()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement