But I cant pull my variables from my config file. I get Attempt to index ? (a nil value) on line 67, and Attempt to index ? (a nil value) on line 46 when the apconfig exists.
-- Advanced Updater by Henness
-- Version 1.0 12/15/2012
-- Config
local author = "Henness0666"
local project = "Advanced-Programs"
local branch = "master"
-- Functions
function loadTable(name)
local file = fs.open(name,"r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end
function saveTable(table,name)
local file = fs.open(name,"w")
file.write(textutils.serialize(table))
file.close()
end
function getLink(file)
return "https://raw.github.com/" .. author .. "/" .. project .. "/" .. branch .. "/" .. file
end
function download(file, name)
local data = http.get(getLink(file))
if data then
local file = fs.open(name,"w")
file.write(data.readAll())
file.close()
return true
end
end
function updatePrograms()
term.clear()
term.setCursorPos(1,1)
if fs.exists("apconfig") then
if download("config", "tmpconfig") then
config = loadTable("apconfig")
tmpconfig = loadTable("tmpconfig")
for i=1,tmpconfig.programs do
if tmpconfig[i].version > config[i].version and i <= config.programs then
file = config[i].name
tempfile = tmpconfig[i].name
temppath = tmpconfig[i].path
if fs.exists(file) then
fs.delete(file)
end
download(tempfile, temppath)
elseif tmpconfig.programs > config.programs and i > config.programs then
download(tempfile, temppath)
end
end
fs.delete("apconfig")
saveTable(tmpconfig, "apconfig")
fs.delete("tmpconfig")
else
print("Unable to download config file form GitHub.")
end
else
if download("config", "apconfig") then
config = loadTable("apconfig")
for i=1,config.programs do
file = config[i].name
path = config[i].path
if fs.exists(file) then
fs.delete(file)
end
download(file, path)
print("Program" .. file .. "updated")
end
else
print("Unable to download config file form GitHub.")
end
end
end
-- RUN
updatePrograms()
if fs.exists("orefindergui")then
shell.run("orefindergui")
end
This is my config file that the gets downloaded.
{["advancedgui"]={["name"]="advancedgui",["path"]="advancedgui",["version"]=1,},["advancedtunnel"]={["name"]="advancedtunnel",["path"]="advancedtunnel",["version"]=1,},["advancedorefinder"]={["name"]="advancedguiorefinder",["path"]="advancedorefinder",["version"]=1,},["programs"]=3,}