Lion4ever

file protector

Mar 16th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. local ending = "_f"
  2.  
  3. local orfa = {} --original fake mapping
  4. local faor = {}
  5.  
  6. local used = false
  7.  
  8. for i,j in pairs(fs.list("/")) do
  9. local k = string.match(j,"(.*)"..ending.."$")
  10. while k do
  11. orfa[k..ending] = k
  12. faor[k] = k..ending
  13. used = true
  14. k=string.match(k,"(.*)"..ending.."$")
  15. end
  16. end
  17.  
  18. local args = {...}
  19.  
  20. if #args % 2 == 1  or (not used and #args == 0) then
  21. print(shell.getRunningProgram().." <actualFile> <displayName> [<actualFile>] <displayName> ...")
  22. return
  23. end
  24.  
  25. for i=1,#args,2 do
  26. faor[args[i+1]] = args[i]
  27. orfa[args[i]] = args[i+1]
  28. end
  29.  
  30. local ofs = {combine=true,getDrive=true,getDir=true,getName=true}
  31. local nfs = {}
  32. for i,j in pairs(fs) do
  33. if not ofs[i] then
  34. nfs[i] = j
  35. end
  36. end
  37. for i in pairs(nfs) do
  38. fs[i] = nil
  39. end
  40.  
  41. local mt ={__index = function(t,k)
  42. if not nfs[k] then
  43. return
  44. end
  45. return function(...)
  46. local pars = {...}
  47. for i,file in ipairs(pars) do
  48. if orfa[file] then
  49. faor[file] = file..ending
  50. orfa[file..ending] = file
  51. end
  52. if faor[file] then
  53. pars[i] = faor[file]
  54. end
  55. end
  56. local r = nfs[k](unpack(pars))
  57. if k == "list" or k == "find" then
  58. local n = {}
  59. for i,file in ipairs(r) do
  60. if orfa[file] then
  61. table.insert(n,orfa[file])
  62. elseif not faor[file] then
  63. table.insert(n,file)
  64. end
  65. end
  66. r=n
  67. end
  68. return r
  69. end
  70. end,__metatable="nil"}
  71.  
  72. setmetatable(fs,mt)
Advertisement
Add Comment
Please, Sign In to add comment