Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function split( _sInput, _sDelimiter )
- local tReturn = {}
- local delimiter = string.gsub( _sDelimiter, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1" )
- local searchPattern = "([^"..delimiter.."]+)"..delimiter.."?"
- for match in string.gmatch( _sInput, searchPattern ) do
- table.insert( tReturn, match )
- end
- return tReturn
- end
- local function getLines(dir)
- local lines = {}
- if fs.exists(dir) then
- local file = fs.open(dir, "r")
- local line = file.readLine()
- while line ~= nil do
- lines[#lines + 1] = line
- line = file.readLine()
- end
- file.close()
- end
- return lines
- end
- local function writeFile(output, dir)
- local lines = getLines(dir)
- if #lines > 0 then
- local d = string.gsub(dir, "/", "___")
- d = string.gsub(d, " ", "_sSs_")
- d = string.gsub(d, "%.", "_dDd_")
- output.writeLine("local "..d.." = ")
- output.writeLine("{")
- for i=1,#lines do
- local ln = string.gsub(lines[i], '"', "#_#")
- ln = '"'..ln..'"'
- if i ~= #lines then ln = ln.."," end
- output.writeLine(ln)
- end
- output.writeLine("}")
- end
- end
- local function writeCode(dirs, output)
- output.writeLine("local file")
- for i=2,#dirs do
- local dir = string.gsub(dirs[i], "/", "___")
- dir = string.gsub(dir, " ", "_sSs_")
- dir = string.gsub(dir, "%.", "_dDd_")
- output.writeLine("if fs.exists('"..dirs[i].."') then fs.delete('"..dirs[i].."') end")
- output.writeLine("file = fs.open('"..dirs[i].."', 'a')")
- output.writeLine("for i=1,#"..dir.." do")
- local speech = '"'
- output.writeLine(" file.writeLine("..dir.."[i]:gsub('#_#', '"..speech.."'))")
- output.writeLine("end")
- output.writeLine("file.close()")
- end
- end
- local stuff = {...}
- local str = ""
- for i=1,#stuff do
- if i == 1 then
- str = stuff[i]
- else
- str = str.." "..stuff[i]
- end
- end
- local dirs = split(str, ":")
- if #dirs > 1 then
- local output = dirs[1]
- if fs.exists(output) then fs.delete(output) end
- local out = fs.open(output, "a")
- for i=2,#dirs do
- writeFile(out, dirs[i])
- end
- writeCode(dirs, out)
- out.close()
- else
- print("Not enough directories, usage:")
- print(" pack output:dir1:dir2:dir3 etc.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement