Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wolf.MsgN("Loading filesystem....")
- wolffs={
- mounted={}
- }
- local FS={}
- function FS:FileExists(dir)
- return false
- end
- function FS:FileOpen(dir)
- return false
- end
- function FS:FileRead(dir)
- return ""
- end
- function FS:FileWrite(dir, stringcontent)
- return false
- end
- function FS:IsFile(path)
- return false
- end
- function FS:IsDir(path)
- return false
- end
- function FS:MakeFile(path)
- return false
- end
- function FS:MakeDir(path)
- return false
- end
- function FS:TraverseDir(path)
- return {}
- end
- function wolffs.Init()
- dofile("fs/"..wolf.game..".lua")
- wolffs.Main=wolffs.MountDir("data/wolfengine")
- PrintTable(wolffs.TraverseDir("awol"))
- end
- function wolffs.MountDir(dir,root)
- local mt=setmetatable({basedir=dir,root=root},{__index=wolffs.Base})
- table.insert(wolffs.mounted,mt)
- return mt
- end
- function wolffs.Mount(fs,root)
- table.insert(wolffs.mounted,setmetatable({root=root},{__index=fs}))
- end
- function wolffs.NewFS()
- return wolf.CopyTable(FS)
- end
- local function foreachmounted(callback)
- for k,v in pairs(wolffs.mounted) do
- local ret=callback(v,v.root~=nil and v.root or "")
- if ret then return ret end
- end
- return false
- end
- local function isInDir(path1, path2)
- if(path2=="") then return true end--its at the root
- local subdirs1=path1:split("/")
- local subdirs2=path2:split("/")
- --get rid of last one as its a filename
- table.remove(subdirs1,#subdirs1)
- --2nd one is a root dir, not a filename
- for k,v in pairs(subdirs1) do
- if(subdirs2[k]:lower()~=v:lower()) then return false end
- end
- return true
- end
- --print(isInDir("data/test/aids.txt","data/test"))
- -------------
- function wolffs.FileExists(dir)
- return foreachmounted(function(fs,root)
- if(not isInDir(dir, root)) then return end
- if(fs:FileExists(dir:sub(#root+1))) then
- return true
- end
- end)
- end
- function wolffs.FileRead(dir)
- return foreachmounted(function(fs,root)
- if(not isInDir(dir, root)) then return end
- if(fs:FileExists(dir:sub(#root+1))) then
- return fs:FileRead(dir:sub(#root+1))
- end
- end)
- end
- function wolffs.FileWrite(dir,data)
- return wolffs.Main:FileWrite(dir,data)
- end
- function wolffs.TraverseDir(dir)
- local total={}
- foreachmounted(function(fs,root)
- if(not isInDir(dir, root)) then return end
- if(fs:IsDir(dir:sub(#root+1))) then
- local traversed=fs:TraverseDir(dir:sub(#root+1))
- for k,v in pairs(traversed) do
- local exit
- for k2,v2 in pairs(total) do if(v2==v) then exit=true break end end
- if not exit then
- table.insert(total,v)
- end
- end
- end
- end)
- return total
- --return wolffs.Main:FileWrite(dir,data)
- end
- -------------
- wolffs.Init()
Advertisement
Add Comment
Please, Sign In to add comment