Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --For ComputerCraft 1.5+
- --Computer Craft Shell Archiver
- local dirname
- local tFiles = {}
- local arcname
- local archandler
- os.loadAPI("astapi")
- if astapi.version < 2 then
- print("Old ASTAPI,please update it")
- print("Hold Ctrl+T to exit")
- while true do sleep(1) end
- end
- function parseDir(d)
- local fff = fs,list(d)
- for i = 1, #fff do
- if fs.isDir(fff[i]) then
- parseDir(astapi.chp(d) + fff[i])
- else
- tFiles[#tFiles+1] = {}
- tFiles[#tFiles]["n"] = fff[i]
- tFiles[#tFiles]["d"] = astapi.chp(d)
- end
- end
- end
- function writeFileInfo(f,n,d)
- local file = io.open(f)
- local fsp = astapi.split(f,"/")
- local fn = fsp[#fsp]
- local l ={}
- write("Reading file "..f.."...")
- for line in file:lines do
- table.insert(l,line)
- end
- file:close()
- local x,y = term.getCursorPos()
- for i = 1, #l do
- term.clearLine()
- term.setCursorPos(1,y)
- write("Refactoring line "..tostring(i).." of "..tostring(#l))
- l[i] = string.gsub(l[i],"\"", "\\\"")
- end
- y = y + 2
- print("Refactored!")
- h:write("local " .. fn .."_h = io.open(\""..d.."/"..fn.."\", \"w\")\n")
- term.setCursorPos(1,y)
- for i = 1, #l do
- term.clearLine()
- term.setCursorPos(1,y)
- write("Writing line " .. tostring(i) .. " of ".. tostring(#l))
- h:write(fn.."_h:write(\""..l[i].."\")\n")
- end
- h:write(fn.."_h:close()")
- end
- term.print("ShAr v 1.0. packaging tool")
- print("Enter the folder you want to archivate")
- write(">")
- dirname = read()
- print("Enter archive name")
- write(">")
- arcname = read()
- print("Reading file list")
- parseDir(dirname)
- local archandler = io.open(shell.resolve(arcname), "w")
- for a = 1, #tFiles do
- print("Archivating file " .. tostring(a).." of ".. tostring(#tFiles))
- writeFileInfo(tFiles[i]["n"], archandler, tFiles[i]["d"])
- print("OK!")
- end
- print("Complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement