Advertisement
Krutoy242

Auto-updater

Apr 12th, 2015
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. -- ==============================
  2. -- Auto-update
  3. -- Downloading and replace running file
  4. -- ==============================
  5. K_VERSION = 1.000 -- Version of program. Need for auto-update
  6. local source = "http://pastebin.com/raw.php?i=dsQ8c2UR" -- Source code of programm
  7.  
  8. local function autoUpdate()
  9.   -- Get version of last
  10.   if not http then return end
  11.   local httpResponce = http.get(source)
  12.   local allText = httpResponce.readAll()
  13.   httpResponce.close()
  14.  
  15.   local newVersion = 0
  16.   local _,verPos = string.find(allText, 'K_VERSION *= *')
  17.   if verPos then
  18.     newVersion = tonumber(string.match(allText, '%d+[%.?%d*]*', verPos+1))
  19.   end
  20.  
  21.   -- Compare and replace
  22.   if K_VERSION < newVersion then
  23.     local sFile = shell.getRunningProgram()
  24.     local f = fs.open(sFile, "w")
  25.     f.write(allText)
  26.     f.close()
  27.     os.reboot()
  28.   end
  29. end
  30.  
  31. autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement