Advertisement
Ulthean

startup

Jan 15th, 2013
12,775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. -- SPLITS A STRING INTO TWO PARTS, BEFORE AND AFTER THE DELIMITER
  2. function splitString(string, delimiter)
  3.   local parts={}
  4.   parts[1]=string:sub(0, (string:find(delimiter))-1)
  5.   parts[2]=string:sub((string:find(delimiter))+1)
  6.   return parts
  7. end
  8.  
  9.  
  10. -- CHECKS IF THE PROGRAM REQUIRES UPDATING
  11. function requiresUpdate(newestVersion)
  12.   -- IF THERE IS NO CHANGELOG: UPDATE
  13.   local file=io.open("changelog", "r")
  14.   if file == nil then
  15.     return true
  16.   end
  17.   -- IF IT IS OF AN OLDER VERSION: UPDATE
  18.   local versionLine=file:read()
  19.   local versionInfo=splitString(versionLine, "=")[2]
  20.   file:close()
  21.   if versionInfo~=newestVersion then
  22.     return true
  23.   end
  24.   return false
  25. end
  26.  
  27. -- MAIN UPDATE CODE
  28. local updateConfig = http.get("https://raw.github.com/Ulthean/MLG_Mining/master/updateList")
  29. if not updateConfig then
  30.   print("Error connecting to server")
  31.   return false
  32. end
  33. local newestVersionInfo=splitString(updateConfig.readLine(), "=")[2]
  34. if requiresUpdate(newestVersionInfo) then
  35.   -- BUILD THE LIST OF PROGRAMS TO UPDATE
  36.   local numPrograms=tonumber(splitString(updateConfig.readLine(), "=")[2])
  37.   local programs={}
  38.   for i=1, numPrograms do
  39.     local programInfo = updateConfig.readLine()
  40.     programs[splitString(programInfo, "=")[1]]=splitString(programInfo, "=")[2]
  41.   end
  42.   -- REMOVE ALL PROGRAMS, EXCEPT FOR THE CONFIG FILE
  43.   for k, v in pairs(programs) do
  44.     if k~="config" then
  45.       shell.run("rm", k)
  46.     end
  47.   end
  48.   -- ADD THE UPDATED PROGRAMS
  49.   for k, v in pairs(programs) do
  50.     shell.run("pastebin", "get", v, k)
  51.   end
  52.   -- PROVIDE UPDATE INFO
  53.   local impact=splitString(updateConfig.readLine(), "=")[2]
  54.   local advise=splitString(updateConfig.readLine(), "=")[2]
  55.   print("---------------------------")
  56.   print("MLG MINING: PROGRAM UPDATED")
  57.   print("IMPACT: "..impact)
  58.   print("ADVISE: "..advise)
  59.   print("---------------------------")
  60. else
  61.   print("---------------------------")
  62.   print("MLG MINING: NO UPDATE FOUND")
  63.   print("---------------------------")
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement