Advertisement
Le_JuiceBOX

[OS] update.lua

Mar 29th, 2024 (edited)
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. -- mcCTKyRS
  2.  
  3. function Main()
  4.     local progs = require("pastes")
  5.     -- remove deleted scripts from pastebinScripts before we update existing
  6.     -- ones; whithout this, deleted scripts would reappear on update
  7.     settings.load()
  8.     local deletedScripts = {}
  9.     local existingPasteScripts = {}
  10.     for _,pasteScript in pairs(settings.get("PastebinScripts",{})) do
  11.         if fs.exists(pasteScript.FilePath..pasteScript.FileName) then
  12.             table.insert(existingPasteScripts,pasteScript)
  13.         else
  14.             table.insert(deletedScripts,pasteScript)
  15.         end
  16.     end
  17.     settings.set("PastebinScripts",existingPasteScripts)
  18.     settings.save()
  19.     if #deletedScripts > 0 then
  20.         term.clear()
  21.         term.setCursorPos(1,1)
  22.         print("Deleted "..tostring(#deletedScripts).." from PastebinScripts because\ntheir files have been deleted.\n")
  23.         for i,pasteScript in pairs(deletedScripts) do
  24.             print(" "..tostring(i).." - "..pasteScript.FilePath..pasteScript.FileName.." ("..pasteScript.PasteId..")")
  25.         end
  26.         print("\nPress Enter to continue...")
  27.         io.read()
  28.         term.clear()
  29.         term.setCursorPos(1,1)
  30.     end
  31.     -- translate paste scripts into something this script handles
  32.     for _,pasteScript in pairs(settings.get("PastebinScripts",{})) do
  33.         table.insert(progs,{
  34.             Name = pasteScript.FilePath..pasteScript.FileName,
  35.             Id = pasteScript.PasteId
  36.         })
  37.     end
  38.  
  39.     for i,data in pairs(progs) do
  40.         term.clear()
  41.         term.setCursorPos(1,1)
  42.         print("Updating ~")
  43.         print()
  44.         print("ID: "..data.Id)
  45.         print("File: "..data.Name)
  46.         print()
  47.         if fs.exists(data.Name) then fs.delete(data.Name); end
  48.         shell.run("pastebin get "..data.Id.." "..data.Name)
  49.         term.clear()
  50.     end
  51.     os.reboot()
  52. end
  53.  
  54. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement