Advertisement
gravitowl

UpdateCode

Dec 4th, 2021 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function writeFile(dir,data)
  2. local file = fs.open(dir, "w")
  3. file.write(data)
  4. file.close()
  5. return true
  6. end
  7.  
  8. function readFile(dir)
  9. if fs.exists(dir) then
  10. local file = fs.open(dir,"r")
  11. local fileData = file.readAll()
  12. file.close()
  13. return fileData, true
  14. else
  15. return false
  16. end
  17. end
  18.  
  19. function update(pastebin,dir)
  20. resp = http.get("https://pastebin.com/raw/" .. pastebin)
  21.  
  22. if resp then
  23. resp = resp.readAll()
  24.  
  25. curFile = readFile(dir)
  26.  
  27. if(resp ~= curFile) then
  28. local succes = writeFile(dir)
  29.  
  30. if(succes == true) then
  31. print("Updated program!")
  32. error()
  33. else
  34. print("Couldn't update, proceeding to run old version...")
  35. end
  36. end
  37. end
  38. end
  39.  
  40. update("q2SAhS22", shell.getRunningProgram())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement