Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fso = fs.open
- local fsd = fs.delete
- local fsc = fs.copy
- local lock = true
- local totalSize = 0
- local maxSize = 512
- local init = false
- function loadSize()
- file = fs.open("size","r")
- totalSize = tonumber(file.readLine())
- file.close()
- init = true
- end
- function saveSize()
- if not init then return end
- lock = false
- file = fs.open("size","w")
- file.write(totalSize)
- file.close()
- lock = true
- end
- function fs.delete(file)
- if fs.exists(file) then
- totalSize = totalSize - fs.getSize(file)
- saveSize()
- end
- return fsd(file)
- end
- function fs.copy(file,nfile)
- if fs.exists(file) then
- if fs.getSize(file) + totalSize >= maxSize then
- error("Disk full.")
- else
- totalSize = totalSize + fs.getSize(file)
- end
- end
- fsc(file,nfile)
- end
- function fs.open(file,mode)
- if ( mode == "w" or mode == "a" or mode == "wb" or mode == "ab" ) then
- if file == "size" then
- if lock then
- return nil
- else
- return fso(file,mode)
- end
- end
- end
- local fSize = nil
- if fs.exists(file) then
- fSize = fs.getSize(file)
- end
- local tabl = fso(file,mode)
- if tabl then
- if mode == "w" or mode == "wb" then
- if fSize ~= nil then
- totalSize = totalSize - fSize
- end
- end
- if tabl.write then
- local otabwrite = tabl.write
- tabl.write = function(_sText)
- if string.len(_sText) + totalSize >= maxSize then
- error("Disk full.")
- else
- totalSize = totalSize + string.len(_sText)
- otabwrite(_sText)
- end
- end
- end
- end
- saveSize()
- return (tabl or nil)
- end
- local function fsunlock()
- lock = false
- end
- local function fslock()
- lock = true
- end
- loadSize()
Advertisement
Add Comment
Please, Sign In to add comment