Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local copy = function(t)
- local tt = {}
- for k,v in pairs(t) do
- tt[k]=v
- end
- return tt
- end
- local function protectTable(t,index)
- return setmetatable({},{
- __index=t and t or index,
- __newindex = function(a,b,c) error("Nope",2) end,
- __metatable = false
- })
- end
- local invisibleFiles = {["startup"] = true}
- local renamedFiles = {["startup_fake"] = "startup"}
- local _fs = copy(_G.fs)
- local m = copy(_fs) --m stands for "mod" I'm just too lazy to write fs_mod every time xD
- local function preparePath(...)
- local prepared = {}
- local function innerPrepare(path)
- local absolute = shell.resolve(path)
- local _path = path
- if(renamedFiles[absolute]) then
- _path = path:replace(absolute, renamedFiles[absolute])
- end
- return _path
- end
- local args = {...}
- for k,v in pairs(args) do
- prepared[#prepared+1] = innerPrepare(v)
- end
- return unpack(prepared)
- end
- function m.open(file, mode)
- return _fs.open(preparePath(file),mode)
- end
- function m.list(path)
- local list = _fs.list(path)
- for k,v in pairs(list) do
- if(invisibleFiles[v] and renamedFiles[v] == nil) then
- list[k] = nil
- end
- if(renamedFiles[v]) then
- list[k] = renamedFiles[v]
- end
- end
- return list
- end
- function m.copy(from,to)
- return _fs.copy(preparePath(from,to))
- end
- function m.move(from,to)
- return _fs.move(preparePath(from,to))
- end
- _fs = protectTable(_fs)
- m = protectTable(m,_fs)
- _G.fs = copy(m)
- _G.fs = protectTable(_G.fs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement