Advertisement
incinirate

Universal Updater

Jun 28th, 2013
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.19 KB | None | 0 0
  1. client="Update Client"
  2. server="Update Server"
  3. self="Update Self"
  4.  
  5. clientsel="* Update Client *"
  6. serversel="* Update Server *"
  7. selfsel="* Update Self *"
  8.  
  9. uptx="Checking for update..."
  10. futx="Found Update! Press Y to update or N to cancel"
  11. lvtx="Script already at latest version!"
  12. cutx="Updating..."
  13. catx="Canceled!"
  14. extxt=" Press Delete To Exit! "
  15. cuctx="Updated!"
  16.  
  17. clgtx="Closing..."
  18. cldtx="Closed."
  19.  
  20. clientcode="g7AmTvM8"
  21. servercode="43NXRhFi"
  22. selfcode="6UwqyDkP"
  23.  
  24. selected=1
  25.  
  26. shell.run("clear")
  27. path = shell.resolve("")
  28.  
  29. screenx,screeny=term.getSize()
  30.  
  31. color = colors.red
  32. incolor = colors.blue
  33.  
  34. function setPos(x,y)
  35.   term.setCursorPos(x,y)
  36. end
  37.  
  38. function drawBox(mask,xmin,ymin,xmax,ymax)
  39.   if term.isColor() then
  40.           term.setBackgroundColor(color)
  41.       screenx,screeny=term.getSize()
  42.       setPos(xmin,ymin)
  43.       for i=1,(xmax+1)-xmin do
  44.         write(" ")
  45.         setPos((xmin-1)+i,ymax)
  46.         write(" ")
  47.         setPos(xmin+i,ymin)
  48.       end
  49.           term.setBackgroundColor(incolor)
  50.           for i=2,ymax-1 do
  51.           for j=1,(xmax+2)-xmin do
  52.             setPos(xmin+j,(ymin-1)+i)
  53.             write(" ")
  54.           end
  55.           end
  56.           term.setBackgroundColor(color)
  57.       for i=1,((ymax+1)-ymin)-2 do
  58.         setPos(xmin,ymin+i)
  59.         write(" ")
  60.         setPos(xmax,ymin+i)
  61.         write(" ")
  62.       end
  63.           term.setBackgroundColor(incolor)
  64.   else
  65.       screenx,screeny=term.getSize()
  66.       setPos(xmin,ymin)
  67.       for i=1,(xmax+1)-xmin do
  68.         write(mask)
  69.         setPos((xmin-1)+i,ymax)
  70.         write(mask)
  71.         setPos(xmin+i,ymin)
  72.       end
  73.       for i=1,((ymax+1)-ymin)-2 do
  74.         setPos(xmin,ymin+i)
  75.         write(mask)
  76.         setPos(xmax,ymin+i)
  77.         write(mask)
  78.       end
  79.   end
  80. end
  81.  
  82. function draw()
  83.   screenx,screeny=term.getSize()
  84.   shell.run("clear")
  85.   drawBox("#",1,1,screenx,screeny)
  86.     if term.isColor() then
  87.     term.setCursorPos(screenx-5,3)
  88.     if term.isColor() then term.setBackgroundColor(colors.orange) end
  89.     write("Exit")
  90.     if term.isColor() then term.setBackgroundColor(incolor) end
  91.     end
  92.   if selected==1 then
  93.     term.setCursorPos((screenx/2)-(string.len(clientsel)/2),screeny/3-2)
  94.     write(clientsel)
  95.     term.setCursorPos((screenx/2)-(string.len(server)/2),screeny/3*2-2)
  96.     write(server)
  97.     term.setCursorPos((screenx/2)-(string.len(self)/2),screeny/3*3-3)
  98.     write(self)
  99.   else if selected==2 then
  100.     term.setCursorPos((screenx/2)-(string.len(client)/2),screeny/3-2)
  101.     write(client)
  102.     term.setCursorPos((screenx/2)-(string.len(serversel)/2),screeny/3*2-2)
  103.     write(serversel)
  104.     term.setCursorPos((screenx/2)-(string.len(self)/2),screeny/3*3-3)
  105.     write(self)
  106.   else if selected==3 then
  107.     term.setCursorPos((screenx/2)-(string.len(client)/2),screeny/3-2)
  108.     write(client)
  109.     term.setCursorPos((screenx/2)-(string.len(server)/2),screeny/3*2-2)
  110.     write(server)
  111.     term.setCursorPos((screenx/2)-(string.len(selfsel)/2),screeny/3*3-3)
  112.     write(selfsel)
  113.   end
  114.   end
  115.   end
  116.   if term.isColor() then
  117.     term.setBackgroundColor(color)
  118.   end
  119.   term.setCursorPos((screenx/2)-(string.len(extxt)/2),screeny)
  120.   write(extxt)
  121.   if term.isColor() then
  122.     term.setBackgroundColor(incolor)
  123.   end
  124. end
  125.  
  126. draw()
  127.  
  128. function checkForUpdate(pbcode,scname)
  129.   atf=false
  130.   if fs.exists(path.."/"..scname) then
  131.     h=http.get("http://pastebin.com/raw.php?i="..pbcode)
  132.     hsc=h.readAll()
  133.     c=fs.open(path.."/"..scname,"r")
  134.     csc=c.readAll()
  135.     if hsc==csc then atf=false else atf=true end
  136.     h.close()
  137.     c.close()
  138.     return atf
  139.   else
  140.     return true
  141.   end
  142. end
  143.  
  144. function updateclient()
  145.   shell.run("clear")
  146. drawBox("#",1,1,screenx,screeny)
  147.   term.setCursorPos((screenx/2)-(string.len(uptx)/2),screeny/2)
  148.  
  149.   write(uptx)
  150.   if checkForUpdate(clientcode,"chat") then
  151.     shell.run("clear")
  152. drawBox("#",1,1,screenx,screeny)
  153.     term.setCursorPos((screenx/2)-(string.len(futx)/2)+1,screeny/2)
  154.    
  155.     write(futx)
  156.     while slup==nil do
  157.       e,par1=os.pullEvent()
  158.       if e == "key" then
  159.         if tostring(par1) == "21" then
  160.           shell.run("clear")
  161. drawBox("#",1,1,screenx,screeny)
  162.           term.setCursorPos((screenx/2)-(string.len(cutx)/2),screeny/2)
  163.          
  164.           write(cutx)
  165.   h=http.get("http://pastebin.com/raw.php?i=g7AmTvM8")
  166.   hsc=h.readAll()
  167.   c=fs.open(path.."/chat","w")
  168.   c.write(hsc)
  169.   h.close()
  170.   c.close()
  171.   shell.run("clear")
  172. drawBox("#",1,1,screenx,screeny)
  173.   term.setCursorPos((screenx/2)-(string.len(cuctx)/2),screeny/2)
  174.  
  175.   write(cuctx)
  176.           sleep(2.5)
  177.           return
  178.         else if tostring(par1) == "49" then
  179.           shell.run("clear")
  180. drawBox("#",1,1,screenx,screeny)
  181.           term.setCursorPos((screenx/2)-(string.len(catx)/2),screeny/2)
  182.          
  183.           write(catx)
  184.           sleep(2.5)
  185.           return
  186.         end
  187.       end
  188.     end
  189.     end
  190.   else
  191.     shell.run("clear")
  192. drawBox("#",1,1,screenx,screeny)
  193.     term.setCursorPos((screenx/2)-(string.len(lvtx)/2),screeny/2)
  194.    
  195.     write(lvtx)
  196.     sleep(1.5)
  197.   end
  198. end
  199.  
  200. function updateserver()
  201.   shell.run("clear")
  202. drawBox("#",1,1,screenx,screeny)
  203.   term.setCursorPos((screenx/2)-(string.len(uptx)/2),screeny/2)
  204.  
  205.   write(uptx)
  206.   if checkForUpdate(servercode,"server") then
  207.     shell.run("clear")
  208. drawBox("#",1,1,screenx,screeny)
  209.     term.setCursorPos((screenx/2)-(string.len(futx)/2)+1,screeny/2)
  210.    
  211.     write(futx)
  212.     while slup==nil do
  213.       e,par1=os.pullEvent()
  214.       if e == "key" then
  215.         if tostring(par1) == "21" then
  216.           shell.run("clear")
  217. drawBox("#",1,1,screenx,screeny)
  218.           term.setCursorPos((screenx/2)-(string.len(cutx)/2),screeny/2)
  219.          
  220.           write(cutx)
  221.   h=http.get("http://pastebin.com/raw.php?i=43NXRhFi")
  222.   hsc=h.readAll()
  223.   c=fs.open(path.."/server","w")
  224.   c.write(hsc)
  225.   h.close()
  226.   c.close()
  227.   shell.run("clear")
  228. drawBox("#",1,1,screenx,screeny)
  229.   term.setCursorPos((screenx/2)-(string.len(cuctx)/2),screeny/2)
  230.  
  231.   write(cuctx)
  232.           sleep(2.5)
  233.           return
  234.         else if tostring(par1) == "49" then
  235.           shell.run("clear")
  236. drawBox("#",1,1,screenx,screeny)
  237.           term.setCursorPos((screenx/2)-(string.len(catx)/2),screeny/2)
  238.          
  239.           write(catx)
  240.           sleep(2.5)
  241.           return
  242.         end
  243.       end
  244.     end
  245.     end
  246.   else
  247.     shell.run("clear")
  248. drawBox("#",1,1,screenx,screeny)
  249.     term.setCursorPos((screenx/2)-(string.len(lvtx)/2),screeny/2)
  250.    
  251.     write(lvtx)
  252.     sleep(1.5)
  253.   end
  254. end
  255.  
  256. function updateself()
  257.   shell.run("clear")
  258. drawBox("#",1,1,screenx,screeny)
  259.   term.setCursorPos((screenx/2)-(string.len(uptx)/2),screeny/2)
  260.  
  261.   write(uptx)
  262.   if checkForUpdate(selfcode,"updater") then
  263.     shell.run("clear")
  264. drawBox("#",1,1,screenx,screeny)
  265.     term.setCursorPos((screenx/2)-(string.len(futx)/2)+1,screeny/2)
  266.    
  267.     write(futx)
  268.     while slup==nil do
  269.       e,par1=os.pullEvent()
  270.       if e == "key" then
  271.         if tostring(par1) == "21" then
  272.           shell.run("clear")
  273. drawBox("#",1,1,screenx,screeny)
  274.           term.setCursorPos((screenx/2)-(string.len(cutx)/2),screeny/2)
  275.          
  276.           write(cutx)
  277.   h=http.get("http://pastebin.com/raw.php?i=6UwqyDkP")
  278.   hsc=h.readAll()
  279.   c=fs.open(path.."/updater","w")
  280.   c.write(hsc)
  281.   h.close()
  282.   c.close()
  283.   shell.run("clear")
  284. drawBox("#",1,1,screenx,screeny)
  285.   term.setCursorPos((screenx/2)-(string.len(cuctx)/2),screeny/2)
  286.  
  287.   write(cuctx)
  288.           sleep(2.5)
  289.           exitscr()
  290.   sleep(2.5)
  291.   term.setBackgroundColor(colors.black)
  292.   shell.run("clear")
  293.   error()
  294.  
  295.           return
  296.         else if tostring(par1) == "49" then
  297.           shell.run("clear")
  298. drawBox("#",1,1,screenx,screeny)
  299.           term.setCursorPos((screenx/2)-(string.len(catx)/2),screeny/2)
  300.          
  301.           write(catx)
  302.           sleep(2.5)
  303.           return
  304.         end
  305.       end
  306.     end
  307.     end
  308.   else
  309.     shell.run("clear")
  310. drawBox("#",1,1,screenx,screeny)
  311.     term.setCursorPos((screenx/2)-(string.len(lvtx)/2),screeny/2)
  312.    
  313.     write(lvtx)
  314.     sleep(1.5)
  315.   end
  316. end
  317.  
  318. function exitscr()
  319.   shell.run("clear")
  320. drawBox("#",1,1,screenx,screeny)
  321.   term.setCursorPos((screenx/2)-(string.len(clgtx)/2),screeny/2)
  322.  
  323.   write(clgtx)
  324.   sleep(1.5)
  325.   shell.run("clear")
  326. drawBox("#",1,1,screenx,screeny)
  327.   term.setCursorPos((screenx/2)-(string.len(cldtx)/2),screeny/2)
  328.  
  329.   write(cldtx)
  330.   sleep(1.5)
  331.   term.setBackgroundColor(colors.black)
  332.   shell.run("clear")
  333.   error()
  334. end
  335.  
  336. while true do
  337.   e,par1,par2,par3=os.pullEvent()
  338.   if e=="key" then
  339.   print(par1)
  340.   if par1==nil then
  341.     print("NIL")
  342.   else if par1==205 or par1==208 then
  343.     if selected==3 then
  344.       selected=1
  345.     else
  346.       selected=selected+1
  347.     end
  348.   else if par1==200 or par1==203 then
  349.     if selected==1 then
  350.       selected=3
  351.     else
  352.       selected=selected-1
  353.     end
  354.   else if tostring(par1)=="28" then
  355.     if selected==1 then
  356.       updateclient()
  357.     else if selected==2 then
  358.       updateserver()
  359.     else if selected==3 then
  360.       updateself()
  361.     end
  362.     end
  363.     end
  364.     else if par1==211 then
  365.       exitscr()
  366.     end
  367.     end
  368.     end
  369.   end
  370.   draw()
  371.   sleep(0.25)
  372.   end
  373. else if e=="mouse_click" then
  374.   if par2 <= screenx-2 then
  375.     if par2 >= screenx-5 then
  376.       if par3 == 3 then
  377.         exitscr()
  378.       end
  379.     end
  380.   end
  381. end
  382. end
  383. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement