Advertisement
omr__

[WIP] Auto-updater

Nov 20th, 2022 (edited)
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | Gaming | 0 0
  1. local module = {}
  2.  
  3. module.getRemoteData = function (id)
  4.     local file = http.get("http://pastebin.com/raw.php?i=" .. id)
  5.    
  6.     if file then
  7.         local data = httpResponce.readAll()
  8.         httpResponce.close()
  9.         return data
  10.     else
  11.         error('No file with id "'..id..'" found')
  12.     end
  13. end
  14.  
  15. module.getLocalData = function (name)
  16.     local file = fs.open(name, "r")
  17.     local data = file.readAll()
  18.     file.close()
  19.     return data
  20. end
  21.  
  22. module.getVersion = function (data)
  23.     local _, versionIndex = string.find(data, 'K_VERSION *= *')
  24.    
  25.     if (versionIndex) then return tonumber(string.match(data, '%d+[%.?%d*]*', versionIndex + 1))
  26.     else return 0 end
  27. end
  28.  
  29. module.run = function ()
  30.     local id = 'QKPAfPkU'
  31.     local name = 'startup'
  32.     local remoteVersion = getVersion(getRemoteData(id))
  33.     local localVersion = getVersion(getLocalData(name))
  34.     print(remoteVersion, localVersion)
  35. end
  36.  
  37. return module
Tags: minecraft lua
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement