Advertisement
Guest User

ccsa

a guest
Nov 1st, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. --For ComputerCraft 1.5+
  2. --Computer Craft Shell Archiver
  3.  
  4. local dirname
  5. local tFiles = {}
  6. local arcname
  7. local archandler
  8.  
  9. os.loadAPI("astapi")
  10. if astapi.version < 2 then
  11.     print("Old ASTAPI,please update it")
  12.     print("Hold Ctrl+T to exit")
  13.     while true do sleep(1) end
  14. end
  15.  
  16. function parseDir(d)
  17.     local fff = fs,list(d)
  18.     for i = 1, #fff do
  19.         if fs.isDir(fff[i]) then
  20.             parseDir(astapi.chp(d) + fff[i])
  21.         else
  22.             tFiles[#tFiles+1] = {}
  23.             tFiles[#tFiles]["n"] = fff[i]
  24.             tFiles[#tFiles]["d"] = astapi.chp(d)
  25.         end
  26.     end
  27. end
  28.  
  29. function writeFileInfo(f,n,d)
  30.     local file = io.open(f)
  31.     local fsp = astapi.split(f,"/")
  32.     local fn = fsp[#fsp]
  33.     local l ={}
  34.     write("Reading file "..f.."...")
  35.     for line in file:lines do
  36.         table.insert(l,line)
  37.     end
  38.     file:close()
  39.     local x,y = term.getCursorPos()
  40.     for i = 1, #l do
  41.         term.clearLine()
  42.         term.setCursorPos(1,y)
  43.         write("Refactoring line "..tostring(i).." of "..tostring(#l))
  44.         l[i] = string.gsub(l[i],"\"", "\\\"")
  45.     end
  46.     y = y + 2
  47.     print("Refactored!")
  48.     h:write("local " .. fn .."_h = io.open(\""..d.."/"..fn.."\", \"w\")\n")
  49.     term.setCursorPos(1,y)
  50.     for i = 1, #l do
  51.         term.clearLine()
  52.         term.setCursorPos(1,y)
  53.         write("Writing line " .. tostring(i) .. " of ".. tostring(#l))
  54.         h:write(fn.."_h:write(\""..l[i].."\")\n")
  55.     end
  56.     h:write(fn.."_h:close()")
  57. end
  58.  
  59.  
  60. term.print("ShAr v 1.0. packaging tool")
  61. print("Enter the folder you want to archivate")
  62. write(">")
  63. dirname = read()
  64. print("Enter archive name")
  65. write(">")
  66. arcname = read()
  67. print("Reading file list")
  68. parseDir(dirname)
  69. local archandler = io.open(shell.resolve(arcname), "w")
  70. for a = 1, #tFiles do
  71.     print("Archivating file " .. tostring(a).." of ".. tostring(#tFiles))
  72.     writeFileInfo(tFiles[i]["n"], archandler, tFiles[i]["d"])
  73.     print("OK!")
  74. end
  75. print("Complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement