QuickMuffin8783

Compressor (tweaked and shows results)

Jun 21st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.     Filesystem
  3.     explorer
  4.     by Creator
  5. ]]--
  6. local args = {...}
  7. local ignore = {}
  8. if args[3] then
  9.     local file = fs.open(args[3],"r")
  10.     local data = file.readAll()
  11.     file.close()
  12.     for token in string.gmatch(data,"[^\n]+") do
  13.         ignore[#ignore+1] = token
  14.     end
  15. end
  16.  
  17. local filesystem = {}
  18.  
  19. local function readFile(path)
  20.     local file = fs.open(path,"r")
  21.     local variable = file.readAll()
  22.     file.close()
  23.     return variable
  24. end
  25.  
  26. local function isNotBanned(path)
  27.     for i,v in pairs(ignore) do
  28.         if v == path then
  29.             return false
  30.         end
  31.     end
  32.     return true
  33. end
  34.  
  35. local function explore(dir)
  36.     local buffer = {}
  37.     local sBuffer = fs.list(dir)
  38.     for i,v in pairs(sBuffer) do
  39.         sleep(0.05)
  40.         if isNotBanned(dir.."/"..v) then
  41.             if fs.isDir(dir.."/"..v) then
  42.                 if v ~= ".git" then
  43.                     print("Compressing directory: "..dir.."/"..v)
  44.                     buffer[v] = explore(dir.."/"..v)
  45.                 end
  46.             else
  47.                 print("Compressing file: "..dir.."/"..v)
  48.                 buffer[v] = readFile(dir.."/"..v)
  49.             end
  50.         end
  51.     end
  52.     return buffer
  53. end
  54.  
  55. append = [[
  56. local function writeFile(path,content)
  57.     local file = fs.open(path,"w")
  58.     file.write(content)
  59.     file.close()
  60. end
  61. function writeDown(input,dir)
  62.     print("Added \""..dir.."\" as a search directory and searching now...")
  63.     for i,v in pairs(input) do
  64.         if type(v) == "table" then
  65.             print("Adding \""..dir.."/"..i.."\" as a search directory...")
  66.             writeDown(v,dir.."/"..i)
  67.         elseif type(v) == "string" then
  68.             print("Installing file \""..dir.."/"..i.."\"...")
  69.             writeFile(dir.."/"..i,v)
  70.             print("Installed file \""..dir.."/"..i.."\".")
  71.         end
  72.     end
  73. end
  74.  
  75. function getInput(txt)
  76.     term.setTextColor(colors.green)
  77.     write(txt)
  78.     term.setTextColor(colors.lime)
  79.     write("> ")
  80.     term.setTextColor(colors.yellow)
  81.     local input = io.read()
  82.     term.setTextColor(colors.white)
  83.     return input
  84. end
  85.  
  86. print("Please input a destination folder:")
  87. local dir = getInput(shell.getRunningProgram())
  88. print()
  89. writeDown(inputTable,dir)
  90.  
  91.  
  92. ]]
  93.  
  94. local filesystem = explore(args[1])
  95. local file = fs.open(args[2],"w")
  96. file.write("inputTable = "..textutils.serialize(filesystem).."\n\n\n\n\n\n\n\n\n"..append)
  97. file.close()
Add Comment
Please, Sign In to add comment