Advertisement
Freack100

Untitled

Jul 24th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. local copy = function(t)
  2. local tt = {}
  3. for k,v in pairs(t) do
  4. tt[k]=v
  5. end
  6. return tt
  7. end
  8.  
  9. local function protectTable(t,index)
  10. return setmetatable({},{
  11. __index=t and t or index,
  12. __newindex = function(a,b,c) error("Nope",2) end,
  13. __metatable = false
  14. })
  15. end
  16.  
  17. local invisibleFiles = {["startup"] = true}
  18. local renamedFiles = {["startup_fake"] = "startup"}
  19.  
  20. local _fs = copy(_G.fs)
  21. local m = copy(_fs) --m stands for "mod" I'm just too lazy to write fs_mod every time xD
  22.  
  23. local function preparePath(...)
  24. local prepared = {}
  25. local function innerPrepare(path)
  26. local absolute = shell.resolve(path)
  27. local _path = path
  28. if(renamedFiles[absolute]) then
  29. _path = path:replace(absolute, renamedFiles[absolute])
  30. end
  31. return _path
  32. end
  33.  
  34. local args = {...}
  35.  
  36. for k,v in pairs(args) do
  37. prepared[#prepared+1] = innerPrepare(v)
  38. end
  39.  
  40. return unpack(prepared)
  41.  
  42. end
  43.  
  44. function m.open(file, mode)
  45. return _fs.open(preparePath(file),mode)
  46. end
  47.  
  48. function m.list(path)
  49. local list = _fs.list(path)
  50. for k,v in pairs(list) do
  51.  
  52. if(invisibleFiles[v] and renamedFiles[v] == nil) then
  53. list[k] = nil
  54. end
  55. if(renamedFiles[v]) then
  56. list[k] = renamedFiles[v]
  57. end
  58. end
  59. return list
  60. end
  61.  
  62. function m.copy(from,to)
  63. return _fs.copy(preparePath(from,to))
  64. end
  65.  
  66. function m.move(from,to)
  67. return _fs.move(preparePath(from,to))
  68. end
  69.  
  70. _fs = protectTable(_fs)
  71. m = protectTable(m,_fs)
  72.  
  73. _G.fs = copy(m)
  74. _G.fs = protectTable(_G.fs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement