Advertisement
Unbox101

updater

Apr 28th, 2022 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. --pastebin get gxCvryX5 updater
  2.  
  3. local arg1, arg2, arg3 = ...
  4. function saveTable(filePathIn, tableIn)
  5.     local file = fs.open(filePathIn,"w")
  6.     file.write(textutils.serialize(tableIn))
  7.     file.close()
  8. end
  9. function loadTable(filePathIn)
  10.     local file = fs.open(filePathIn,"r")
  11.     local data = file.readAll()
  12.     file.close()
  13.     return textutils.unserialize(data)
  14. end
  15.  
  16.  
  17.  
  18. local sPath = "UpdaterData.save"
  19. local programs = {
  20.     updater = "gxCvryX5"
  21. }
  22.  
  23. if not fs.exists(sPath) then
  24.     saveTable(sPath, programs)
  25. end
  26. programs = loadTable(sPath)
  27.  
  28. local function install(fileName)
  29.     if not programs[fileName] then
  30.         print("no file with name ", fileName)
  31.         return
  32.     end
  33.     if fs.exists(fileName) then
  34.         fs.delete(fileName)
  35.     end
  36.     shell.run("pastebin", "get", programs[fileName], fileName)
  37. end
  38.  
  39. local function updateAll()
  40.     for i,v in pairs(programs) do
  41.         if fs.exists(i) then
  42.             print("Updating program \""..tostring(i).."\" "..tostring(v))
  43.             install(i)
  44.             print()
  45.         else
  46.             print("Installing program \""..tostring(i).."\" "..tostring(v))
  47.             install(i)
  48.             print()
  49.         end
  50.     end
  51. end
  52. print()
  53.  
  54. if arg1 == "install" then
  55.     install(arg2)
  56. elseif arg1 == "list" then
  57.     for i,v in pairs(programs) do
  58.        print("\""..tostring(i).."\"", v)
  59.     end
  60. elseif arg1 == "add" then
  61.     local input1, input2
  62.     if not arg2 then
  63.         print("Please type the name of the program.")
  64.         input1 = read()
  65.     else
  66.         input1 = tostring(arg2)
  67.     end
  68.     if not arg3 then
  69.         print("Please type the pastebin id of the program.")
  70.         input2 = read()
  71.     else
  72.         input2 = tostring(arg3)
  73.     end
  74.    
  75.    
  76.     if input1 and input2 then
  77.         print("Adding new program \""..input1.."\" "..input2.. " to installer.")
  78.         programs[input1] = input2
  79.     else
  80.         print("Failed to add new program \""..tostring(input1).."\" "..tostring(input2))
  81.     end
  82. elseif arg1 == "remove" then
  83.     print("Please type the name of the program.")
  84.     input1 = read()
  85.     if input1 then
  86.         if (programs[input1]) then
  87.             print("Removing \""..input1.."\" from the installer and uninstalling it.")
  88.             if fs.exists(input1) then
  89.                 fs.delete(input1)
  90.             end
  91.             programs[input1] = nil
  92.         else
  93.             print("No program named \""..input1.."\" installed in the updater.")
  94.         end
  95.     else
  96.         print("Failed. Input must not be nil")
  97.     end
  98. else
  99.  
  100.     print("Updating Everything...")
  101.     updateAll()
  102. end
  103. saveTable(sPath, programs)
  104. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement