Advertisement
Thunder7102

updater

May 24th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. --Will download programs from a file and set them up
  2. --This will download the pastebin URL listed in the tables and name from the first value
  3.  
  4. --Will keep track of needed programs
  5. local downLst
  6.  
  7. function downloadLst()
  8.     print("Downloading program list...")
  9.     if fs.exists("utils/list") then fs.delete("utils/list") end
  10.     shell.run("pastebin","get","z94j1v3R", "utils/list")
  11.     os.loadAPI("utils/list")
  12.     downLst = list.getList()
  13.     os.unloadAPI("utils/list")
  14.     print("Download complete and new list acquired.")
  15. end
  16.  
  17. function downloadLoop()
  18.     print("Downloading program list...")
  19.     for name, url in pairs(downLst) do
  20.         print("Downloading "..name.."...")
  21.        
  22.         --Just in case I need to delete
  23.         if fs.exists(name) then
  24.             print("Deleting old "..name.."...")
  25.             fs.delete(name)
  26.         end
  27.        
  28.         shell.run("pastebin", "get", url, name)
  29.         print(name.." complete!")
  30.     end
  31. end
  32.  
  33. function checkVersion()
  34.     --Downloads list file and checks if programs need updating
  35.     if not fs.exists("utils/list") then
  36.         downloadLst()
  37.         downloadLoop()
  38.     end
  39.    
  40.     os.loadAPI("utils/list")
  41.     local oldVersion = list.getVersion()
  42.     os.unloadAPI("utils/list")
  43.     downloadLst()
  44.     os.loadAPI("utils/list")
  45.    
  46.     --If they don't match then a change has been made
  47.     if oldVersion ~= list.getVersion() then
  48.         downloadLoop()
  49.     end
  50.     os.unloadAPI("utils/list")
  51. end
  52.  
  53. if checkVersion() then
  54.     downloadLst()
  55.     downloadLoop()
  56.     print("Update finished!")
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement