Advertisement
Alexr360

Update Broken

Mar 26th, 2024 (edited)
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- List of programs to check for updates
  2. local programs = {
  3.     {name = "Bastion", pastebinCode = "Czt0xUgp"},
  4.     {name = "RBastion", pastebinCode = "YLMd18xC"},
  5.     {name = "FBastion", pastebinCode = "8pF6ds3s"},
  6.     {name = "GPS", pastebinCode = "d8WLzv0U"},
  7.     {name = "Stripmine", pastebinCode = "BkFdvGdv"},
  8.     {name = "Update", pastebinCode = "8w6Ni2U1"},
  9.     {name = "Greeting", pastebinCode = "REfxrLkG"},
  10.     {name = "startup", pastebinCode = "u2ey5fkZ"},
  11.     {name = "CargoGate", pastebinCode = "uDQ9GX0F"},
  12.     {name = "ArtillaryControl", pastebinCode = "BGUJrLzV"},
  13.     {name = "StargateLogs", pastebinCode = "eg0sWHxc"}
  14.     -- Add more programs as needed
  15. }
  16.  
  17. -- Function to check for updates
  18. local function checkForUpdates(program)
  19.     -- Loop through the list of programs
  20.     for i, program in ipairs(programs) do
  21.       -- Check if the file already exists
  22.       if not fs.exists(program.name) then
  23.         -- Open a new file with the current program name
  24.         local file = fs.open(program.name, "w")
  25.  
  26.         -- Write a message to the file
  27.         file.write("This is " .. program.name .. ". The pastebin code is " .. program.pastebinCode)
  28.  
  29.         -- Close the file
  30.         file.close()
  31.       end
  32.     end
  33.     print("Files have been created.")
  34.    
  35.     print("Checking for updates for " .. program.name .. "...")
  36.     local response = http.get("https://pastebin.com/raw/" .. program.pastebinCode)
  37.     if response then
  38.         local remoteVersion = response.readAll()
  39.         response.close()
  40.         local localVersion = fs.exists(program.name) and fs.open(program.name, "r").readAll() or nil
  41.         if localVersion and localVersion ~= remoteVersion then
  42.             print("Updating " .. program.name .. "...")
  43.             local file = fs.open(program.name, "w")
  44.             file.write(remoteVersion)
  45.             file.close()
  46.             print(program.name .. " updated successfully.")
  47.         else
  48.             print(program.name .. " is up to date.")
  49.         end
  50.     else
  51.         print("Failed to check for updates for " .. program.name)
  52.     end
  53. end
  54.  
  55. -- Main function to check for updates for all programs
  56. local function main()
  57.     for _, program in ipairs(programs) do
  58.         checkForUpdates(program)
  59.     end
  60. end
  61.  
  62. -- Run main function
  63. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement