Pinkishu

Untitled

Jul 12th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. local fso = fs.open
  2. local fsd = fs.delete
  3. local fsc = fs.copy
  4. local lock = true
  5. local totalSize = 0
  6. local maxSize = 512
  7. local init = false
  8.  
  9. function loadSize()
  10.   file = fs.open("size","r")
  11.   totalSize = tonumber(file.readLine())
  12.   file.close()
  13.   init = true
  14. end
  15.  
  16. function saveSize()
  17.   if not init then return end
  18.   lock = false
  19.   file = fs.open("size","w")
  20.   file.write(totalSize)
  21.   file.close()
  22.   lock = true
  23. end
  24.  
  25. function fs.delete(file)
  26.   if fs.exists(file) then
  27.     totalSize = totalSize - fs.getSize(file)
  28.     saveSize()
  29.   end
  30.   return fsd(file)
  31. end
  32.  
  33. function fs.copy(file,nfile)
  34.   if fs.exists(file) then
  35.     if fs.getSize(file) + totalSize >= maxSize then
  36.       error("Disk full.")
  37.     else
  38.       totalSize = totalSize + fs.getSize(file)
  39.     end
  40.    
  41.   end
  42.   fsc(file,nfile)
  43. end
  44.  
  45. function fs.open(file,mode)
  46.   if ( mode == "w" or mode == "a" or mode == "wb" or mode == "ab" ) then
  47.     if file == "size" then
  48.       if lock then
  49.         return nil
  50.       else
  51.         return fso(file,mode)
  52.       end
  53.     end
  54.   end
  55.   local fSize = nil
  56.   if fs.exists(file) then
  57.     fSize = fs.getSize(file)
  58.   end
  59.   local tabl = fso(file,mode)
  60.   if tabl then
  61.     if mode == "w" or mode == "wb" then
  62.       if fSize ~= nil then
  63.         totalSize = totalSize - fSize
  64.       end
  65.     end
  66.     if tabl.write then
  67.       local otabwrite = tabl.write
  68.       tabl.write = function(_sText)
  69.        
  70.         if string.len(_sText) + totalSize >= maxSize then
  71.           error("Disk full.")
  72.         else
  73.           totalSize = totalSize + string.len(_sText)
  74.           otabwrite(_sText)
  75.         end
  76.       end
  77.     end
  78.   end
  79.  
  80.   saveSize()
  81.   return (tabl or nil)
  82. end
  83.  
  84.  
  85. local function fsunlock()
  86.   lock = false
  87. end
  88.  
  89. local function fslock()
  90.   lock = true
  91. end
  92.  
  93. loadSize()
Advertisement
Add Comment
Please, Sign In to add comment