Posted 03 February 2014 - 09:30 PM
I created this package-creating program and i keep getting 26:attempt to index nil value, i don't understand why it doesn't work. Here's the code:
--[[
lzip is a custom file type which will self-expand
it allows users to compress any number of files into one!
]]--
local tArgs = {...}
function getInfo()
shell.run(tArgs[3].." I")
term.setTextColor(colors.yellow)
print(tArgs[3])
print("Created on computer: "..compid..", "..complabel)
print("At: "..time)
print("On: "..date)
term.setTextColor(colors.white)
end
function compress(nme)
local x = 1
if nme == nil then
w = fs.open(tArgs[2]..".lzip", "a")
else
w = fs.open(tArgs[2], "a")
end
w.writeLine("local tArgs = {...}")
w.write("doc = {")
for name, data in pairs(tArgs) do
if x > 2 then
local r = fs.open(data, "r")
local read = r.readAll()
r.close()
if nme == nil then
local w = fs.open(tArgs[2]..".lzip", "a")
else
local w = fs.open(tArgs[2], "a")
end
if x == 3 then
w.write(data)
w.write(","..read)
else
w.write(","..data)
w.write(","..read)
end
w.close()
end
x = x + 1
end
if nme == nil then
local w = fs.open(tArgs[2]..".lzip", "a")
else
local w = fs.open(tArgs[2], "a")
end
w.writeLine("}")
w.close()
if nme == nil then
local w = fs.open(tArgs[2]..".lzip", "a")
else
local w = fs.open(tArgs[2], "a")
end
local compid = os.getComputerID()
local compla = os.getComputerLabel()
w.writeLine("local x = 1")
w.writeLine("if tArgs[1] == "..[["]].."I"..[["]].." then")
w.writeLine("compid = "..compid)
w.writeLine("complabel = "..compla)
local time = os.time()
w.writeLine("time = "..time)
local date = os.date()
w.writeLine("date = "..date)
w.writeLine("else")
w.writeLine("for name, data in pairs(doc) do")
w.writeLine("if x == 1 then")
w.writeLine("local w = fs.open(data, "..[["]].."a"..[["]]..")")
w.writeLine("if tArgs[2] ~= "..[["]].."Install"..[["]].." then")
w.writeLine("term.write("..[["]].."Expanding: "..[["]].."..".."data"..".."..[["]].."......."..[["]]..")")
w.writeLine("end")
w.writeLine("x = x + 1")
w.writeLine("else")
w.writeLine("w.write(data)")
w.writeLine("w.close()")
w.writeLine("if tArgs[2] ~= "..[["]].."Install"..[["]].." then")
w.writeLine("print("..[["]].."Success!"..[["]]..")")
w.writeLine("end")
w.writeLine("x = x - 1")
w.writeLine("end")
w.writeLine("if tArgs[2] == "..[["]].."Install"..[["]].." then")
if nme == nil then
w.writeLine("fs.delete("..[["]]..tArgs[2]..".lzip"..[["]]..")")
else
w.writeLine("fs.delete("..[["]]..tArgs[2]..[["]]..")")
end
w.writeLine("end")
w.writeLine("end")
w.writeLine("end")
w.close()
end
if tArgs[1] == "compress" and tArgs[2] ~= nil and tArgs[3] ~= nil then
local cx = string.find(tArgs[2], ".lzip")
local x = 1
local e = false
if cx == nil then
cc = fs.exists(tArgs[2]..".lzip")
else
cc = fs.exists(tArgs[2])
end
if cc == false then
for name, data in pairs(tArgs) do
if x > 2 then
local c = fs.exists(data)
if c == false then
term.setTextColor(colors.red)
print("Error: File "..[["]]..data..[["]].." does not exist")
term.setTextColor(colors.white)
e = true
end
end
x = x + 1
end
if e == false then
compress(cx)
end
else
term.setTextColor(colors.red)
if cx == nil then
print("Error: File "..[["]]..tArgs[2]..".lzip"..[["]].." exists already!")
else
print("Error: File "..[["]]..tArgs[2]..[["]].." exists already!")
end
term.setTextColor(colors.white)
end
elseif tArgs[1] == "get" and tArgs[2] == "info" then
local cx = string.find(tArgs[3], ".lzip")
if cx == nil then
term.setTextColor(colors.red)
print("Error: File "..[["]]..tArgs[3]..[["]].." is not an 'lzip'")
term.setTextColor(colors.white)
else
local c = fs.exists(tArgs[3])
if c == false then
term.setTextColor(colors.red)
print("Error: File "..[["]]..tArgs[3]..[["]].." does not exist")
term.setTextColor(colors.white)
else
getInfo()
end
end
else
term.setTextColor(colors.red)
print("Usages: compress <zip name> <file 2> <file 3> etc., get info <compressed file>")
term.setTextColor(colors.white)
end