Knux14

AutoUpdater

Jul 11th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1.     _fileName = "chemin/vers/votre/logiciel"
  2.     _currVers = 0
  3.     _lastVers = 0
  4.     _urlUpdate = "http://pastebin.com/raw?i=CodePastebinLogiciel"
  5.     _urlVers = "http://pastebin.com/raw?i=CodePastebinVersion"
  6.      
  7.     function checkUpdate (version)
  8.       _currVers = tonumber(version)
  9.       if (not http) then
  10.         print("No HTTP. Can't autoupdate !")
  11.         return
  12.       end
  13.      
  14.       req1 = http.get(_urlVers)
  15.       if (req1) then
  16.         _lastVers = tonumber(req1.readAll())
  17.         if (_lastVers == _currVers) then
  18.           prt("You're up to date !")
  19.           prt("")
  20.           return
  21.         else
  22.           bool = true
  23.           print("An update is avaliable, would you do it ? (Y/N)")
  24.           while bool do
  25.             ev, key = os.pullEvent("key")
  26.             if (key == 21) then
  27.                bool = false
  28.                a = parallel.waitForAny(text, upd)
  29.                print(a)
  30.             elseif (key == 49) then
  31.               prt ("Update cancelled !")
  32.               return
  33.             end
  34.           end
  35.         end
  36.       end
  37.     end
  38.      
  39.     function prt (txt)
  40.       term.clear()
  41.       term.setCursorPos(1, 1)
  42.       term.write(txt)
  43.       os.sleep(0.5)
  44.     end
  45.      
  46.     function text ()
  47.       while true do
  48.         prt("Updating")
  49.         prt("Updating .")
  50.         prt("Updating ..")
  51.         prt("Updating ...")
  52.       end
  53.     end
  54.      
  55.     function upd ()
  56.         fs.delete(_fileName)
  57.         req2 = http.get(_urlUpdate)
  58.         if (req2) then
  59.            test = req2.readAll()
  60.            print(test)
  61.            file = fs.open(_fileName, "w")
  62.            file.write(test)
  63.            file.close()
  64.            term.clear()
  65.            term.setCursorPos (1, 1)
  66.            print("Update done !")
  67.            os.sleep(1)
  68.            prt("")
  69.         end
  70.     end
Advertisement
Add Comment
Please, Sign In to add comment