Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _fileName = "chemin/vers/votre/logiciel"
- _currVers = 0
- _lastVers = 0
- _urlUpdate = "http://pastebin.com/raw?i=CodePastebinLogiciel"
- _urlVers = "http://pastebin.com/raw?i=CodePastebinVersion"
- function checkUpdate (version)
- _currVers = tonumber(version)
- if (not http) then
- print("No HTTP. Can't autoupdate !")
- return
- end
- req1 = http.get(_urlVers)
- if (req1) then
- _lastVers = tonumber(req1.readAll())
- if (_lastVers == _currVers) then
- prt("You're up to date !")
- prt("")
- return
- else
- bool = true
- print("An update is avaliable, would you do it ? (Y/N)")
- while bool do
- ev, key = os.pullEvent("key")
- if (key == 21) then
- bool = false
- a = parallel.waitForAny(text, upd)
- print(a)
- elseif (key == 49) then
- prt ("Update cancelled !")
- return
- end
- end
- end
- end
- end
- function prt (txt)
- term.clear()
- term.setCursorPos(1, 1)
- term.write(txt)
- os.sleep(0.5)
- end
- function text ()
- while true do
- prt("Updating")
- prt("Updating .")
- prt("Updating ..")
- prt("Updating ...")
- end
- end
- function upd ()
- fs.delete(_fileName)
- req2 = http.get(_urlUpdate)
- if (req2) then
- test = req2.readAll()
- print(test)
- file = fs.open(_fileName, "w")
- file.write(test)
- file.close()
- term.clear()
- term.setCursorPos (1, 1)
- print("Update done !")
- os.sleep(1)
- prt("")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment