pepeknamornik

Update api

Jun 29th, 2021 (edited)
2,261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. verze = "21.1010.R4"
  2. local tArgs = { ... }
  3. local w,h = term.getSize()
  4. cur = 0
  5. upd = 0
  6. nan = 0
  7. local gui = true
  8. local noface = false
  9. local setting = false
  10.  
  11. if #tArgs > 0 then
  12.     if (tArgs[1] == "nogui") then
  13.     gui = false
  14.     term.setCursorPos(1,-5)
  15.     elseif(tArgs[1] == "noFace") then
  16.     gui = false
  17.     noface = true
  18.     term.setCursorPos(1,-5)
  19.     elseif(tArgs[1] == "setting") then
  20.     gui = false
  21.     noface = true
  22.     setting = true
  23.     term.setCursorPos(1,-5)
  24.     end
  25. end
  26.  
  27. if fs.exists("/C/system/RAM/UpdateList.txt") then fs.delete("/C/system/RAM/UpdateList.txt") end
  28.  
  29. if fs.exists("/C/system/.core/.Registry/.disableUpdate") and not setting then error() end
  30.  
  31. shell.run ("pastebin get kXX84wM3 /C/system/RAM/UpdateList.txt")
  32.  
  33. if fs.exists("/C/system/RAM/online") then
  34.     local data = fs.open("/C/system/RAM/online", "r")
  35.     local Conser = data.readLine()
  36.         if (Conser == "pastebin.com") then PastebinMode = true  DevbinMode = false
  37.         elseif (Conser == "devbin.dev") then DevbinMode = true PastebinMode = false
  38.         else DevbinMode = false PastebinMode = false end
  39.     data.close()
  40. else DevbinMode = false PastebinMode = false end
  41.  
  42. local function logo()
  43. term.setBackgroundColor(colors.white)
  44. term.setTextColor(colors.blue)
  45. term.setCursorPos(w/2-5,h-1)
  46. write"  Pepek"
  47. term.setCursorPos(w/2+3,h-1)
  48. write"Soft  "
  49. term.setCursorPos(w/2+2,h-1)
  50. term.setTextColor(colors.lime)
  51. write"@"
  52. end
  53.  
  54.  
  55. local function prc(text, y)
  56.   local w = term.getSize()
  57.   local _, cy = term.getCursorPos()
  58.   term.setCursorPos(math.ceil((w-#text)/2), y or cy)
  59.   write(text)
  60. end
  61.  
  62.  function vycistit()
  63. term.setBackgroundColor(colors.white)
  64. term.setTextColor(colors.black)
  65. term.clear()
  66. prc ("Update some system files !", 5)
  67. prc ("Please wait...", h/2)
  68. prc ("Don't turn off your computer!", h/2+2)
  69. logo()
  70. end
  71.  
  72. function updateCore(path, verze, Pcode, Dcode)
  73.     if fs.exists(path) then
  74.             local data = fs.open(path, "r")
  75.             Current = data.readLine()
  76.             data.close()
  77.        
  78.         if (string.find(Current, verze) ~= nil) then
  79.             cur = cur + 1
  80.         else
  81.             upd = upd + 1
  82.             if not noface then vycistit() end
  83.             term.setCursorPos(1,-5)
  84.             fs.delete(path)
  85.             shell.run("pastebin get "..Pcode.." "..path)
  86.             if (path == "/startup.lua") then shell.run("/startup.lua reboot") end
  87.         end
  88.     else   
  89.             nan = nan + 1
  90.     end
  91. end
  92.  
  93. function check()
  94.     if fs.exists("/C/system/RAM/UpdateList.txt") then
  95.         local data = fs.open("/C/system/RAM/UpdateList.txt", "r")
  96.         repeat
  97.         cesta = data.readLine()
  98.         verze = data.readLine()
  99.         Pcode = data.readLine()
  100.         Dcode = data.readLine()
  101.         local nic = data.readLine()
  102.         if cesta ~= nil and (string.sub(cesta,1,1) == "/") then updateCore(cesta, verze, Pcode, Dcode) end
  103.         until cesta == nil
  104.         data.close()
  105.     end
  106.     if gui and not noface then
  107.     print("Soubory: "..(cur+upd+nan))
  108.     print("Aktualni: "..cur)
  109.     print("Aktualizovat: "..upd)
  110.     print("Neexistuje: "..nan)
  111.     end
  112.     if setting then
  113.     if fs.exists("/C/system/RAM/UpdateList.tmp") then fs.delete("/C/system/RAM/UpdateList.tmp") end
  114.     local data = fs.open ("/C/system/RAM/UpdateList.tmp", "w")
  115.     data.writeLine("Total files:    "..(cur+upd))
  116.     data.writeLine("Current files:  "..cur)
  117.     data.writeLine("Updated files:  "..upd)
  118.     data.close()
  119.     end
  120.     if fs.exists("/C/system/RAM/UpdateList.txt") then fs.delete("/C/system/RAM/UpdateList.txt") end
  121. end
  122.  
  123. check()
Add Comment
Please, Sign In to add comment