pass program to functions
This commit is contained in:
parent
1d58f51ba4
commit
eec87784de
2 changed files with 40 additions and 41 deletions
|
@ -23,9 +23,9 @@ if #args > 1 then
|
||||||
customPath = shell.resolve(args[2])
|
customPath = shell.resolve(args[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
local function downloadFile(filename)
|
local function downloadFile(program, filename)
|
||||||
print("downloading " .. filename .. "...")
|
print("downloading " .. filename .. "...")
|
||||||
local fileUrl = url .. "/files/" .. programToInstall .. "/" .. filename
|
local fileUrl = url .. "/files/" .. program .. "/" .. filename
|
||||||
|
|
||||||
local result = http.get(fileUrl)
|
local result = http.get(fileUrl)
|
||||||
local resultText = result.readAll()
|
local resultText = result.readAll()
|
||||||
|
@ -54,12 +54,12 @@ local function split(pString, pPattern)
|
||||||
return Table
|
return Table
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getAllFiles()
|
local function getAllFiles(program)
|
||||||
local indexesUrl = url .. "/indexes/" .. programToInstall
|
local indexesUrl = url .. "/indexes/" .. program
|
||||||
|
|
||||||
local result = http.get(indexesUrl)
|
local result = http.get(indexesUrl)
|
||||||
if result == nil then
|
if result == nil then
|
||||||
print("error! getting indexes for " .. programToInstall)
|
print("error! getting indexes for " .. program)
|
||||||
error()
|
error()
|
||||||
end
|
end
|
||||||
local resultText = result.readAll()
|
local resultText = result.readAll()
|
||||||
|
@ -70,7 +70,7 @@ local function getAllFiles()
|
||||||
indexesFile.close()
|
indexesFile.close()
|
||||||
|
|
||||||
local programsFile = fs.open(path .. "programs.dat", "a")
|
local programsFile = fs.open(path .. "programs.dat", "a")
|
||||||
programsFile.write(programToInstall)
|
programsFile.write(program)
|
||||||
programsFile.close()
|
programsFile.close()
|
||||||
|
|
||||||
local finalResult = {}
|
local finalResult = {}
|
||||||
|
@ -81,7 +81,7 @@ local function getAllFiles()
|
||||||
return finalResult
|
return finalResult
|
||||||
end
|
end
|
||||||
|
|
||||||
local function finishInstall(files)
|
local function finishInstall(program, files)
|
||||||
for key, file in ipairs(files) do
|
for key, file in ipairs(files) do
|
||||||
if customPath ~= nil then
|
if customPath ~= nil then
|
||||||
print("moving " .. file .. " to " .. customPath .. "...")
|
print("moving " .. file .. " to " .. customPath .. "...")
|
||||||
|
@ -93,20 +93,20 @@ local function finishInstall(files)
|
||||||
end
|
end
|
||||||
fs.move(temp .. file, customPath .. "/" .. file)
|
fs.move(temp .. file, customPath .. "/" .. file)
|
||||||
else
|
else
|
||||||
print("moving " .. file .. " to " .. path .. programToInstall .. "...")
|
print("moving " .. file .. " to " .. path .. program .. "...")
|
||||||
if not fs.exists(path .. programToInstall) then
|
if not fs.exists(path .. program) then
|
||||||
fs.makeDir(path .. programToInstall)
|
fs.makeDir(path .. program)
|
||||||
end
|
end
|
||||||
if fs.exists(path .. programToInstall .. "/" .. file) then
|
if fs.exists(path .. program .. "/" .. file) then
|
||||||
fs.delete(path .. programToInstall .. "/" .. file)
|
fs.delete(path .. program .. "/" .. file)
|
||||||
end
|
end
|
||||||
fs.move(temp .. file, path .. programToInstall .. "/" .. file)
|
fs.move(temp .. file, path .. program .. "/" .. file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if customPath ~= nil then
|
if customPath ~= nil then
|
||||||
local program = "shell.run(" .. customPath .. "/run.lua)"
|
local program = "shell.run(" .. customPath .. "/run.lua)"
|
||||||
file = fs.open(path .. programToInstall .. "/run.lua")
|
file = fs.open(path .. program .. "/run.lua")
|
||||||
file.write(program)
|
file.write(program)
|
||||||
file.close()
|
file.close()
|
||||||
end
|
end
|
||||||
|
@ -130,11 +130,11 @@ for _, value in ipairs(programsTable) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if shouldInstall then
|
if shouldInstall then
|
||||||
local files = getAllFiles()
|
local files = getAllFiles(programToInstall)
|
||||||
for _, value in ipairs(files) do
|
for _, value in ipairs(files) do
|
||||||
downloadFile(value)
|
downloadFile(programToInstall, value)
|
||||||
end
|
end
|
||||||
finishInstall(files)
|
finishInstall(programToInstall, files)
|
||||||
elseif fs.exists(path .. "updater/update.lua") then
|
elseif fs.exists(path .. "updater/update.lua") then
|
||||||
shell.run(path .. "updater/update.lua " .. programToInstall)
|
shell.run(path .. "updater/update.lua " .. programToInstall)
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,9 +19,9 @@ if #args > 1 then
|
||||||
customPath = shell.resolve(args[2])
|
customPath = shell.resolve(args[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
local function downloadFile(filename)
|
local function downloadFile(program, filename)
|
||||||
print("downloading " .. filename .. "...")
|
print("downloading " .. filename .. "...")
|
||||||
local fileUrl = url .. "/files/" .. programToInstall .. "/" .. filename
|
local fileUrl = url .. "/files/" .. program .. "/" .. filename
|
||||||
|
|
||||||
local result = http.get(fileUrl)
|
local result = http.get(fileUrl)
|
||||||
local resultText = result.readAll()
|
local resultText = result.readAll()
|
||||||
|
@ -50,9 +50,9 @@ local function split(pString, pPattern)
|
||||||
return Table
|
return Table
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getAllFiles()
|
local function getAllFiles(program)
|
||||||
local indexesUrl = url .. "/indexes/" .. programToInstall
|
local indexesUrl = url .. "/indexes/" .. program
|
||||||
local updateUrl = url .. "/updates/" .. programToInstall
|
local updateUrl = url .. "/updates/" .. program
|
||||||
|
|
||||||
local currentFiles = ""
|
local currentFiles = ""
|
||||||
if fs.exists(path .. "indexes.dat") then
|
if fs.exists(path .. "indexes.dat") then
|
||||||
|
@ -63,7 +63,7 @@ local function getAllFiles()
|
||||||
|
|
||||||
local result = http.post(updateUrl, currentFiles)
|
local result = http.post(updateUrl, currentFiles)
|
||||||
if result == nil then
|
if result == nil then
|
||||||
print("error! getting updates for " .. programToInstall)
|
print("error! getting updates for " .. program)
|
||||||
error()
|
error()
|
||||||
end
|
end
|
||||||
local resultText = result.readAll()
|
local resultText = result.readAll()
|
||||||
|
@ -71,7 +71,7 @@ local function getAllFiles()
|
||||||
|
|
||||||
local result2 = http.get(indexesUrl)
|
local result2 = http.get(indexesUrl)
|
||||||
if result2 == nil then
|
if result2 == nil then
|
||||||
print("error! getting indexes for " .. programToInstall)
|
print("error! getting indexes for " .. program)
|
||||||
error()
|
error()
|
||||||
end
|
end
|
||||||
local resultText2 = result2.readAll()
|
local resultText2 = result2.readAll()
|
||||||
|
@ -86,7 +86,7 @@ local function getAllFiles()
|
||||||
local filename = split(value, " ")[1]
|
local filename = split(value, " ")[1]
|
||||||
for key2, value2 in ipairs(resultTable) do
|
for key2, value2 in ipairs(resultTable) do
|
||||||
local valueTable = split(value2, " ")
|
local valueTable = split(value2, " ")
|
||||||
local filePath = path .. programToInstall .. "/" .. valueTable[1]
|
local filePath = path .. program .. "/" .. valueTable[1]
|
||||||
if valueTable[2] == "delete" and fs.exists(filePath) then
|
if valueTable[2] == "delete" and fs.exists(filePath) then
|
||||||
fs.delete(filePath)
|
fs.delete(filePath)
|
||||||
elseif valueTable[2] == "download" then
|
elseif valueTable[2] == "download" then
|
||||||
|
@ -98,7 +98,7 @@ local function getAllFiles()
|
||||||
return finalResult
|
return finalResult
|
||||||
end
|
end
|
||||||
|
|
||||||
local function finishInstall(files)
|
local function finishInstall(program, files)
|
||||||
for key, file in ipairs(files) do
|
for key, file in ipairs(files) do
|
||||||
if customPath ~= nil then
|
if customPath ~= nil then
|
||||||
print("moving " .. file .. " to " .. customPath .. "...")
|
print("moving " .. file .. " to " .. customPath .. "...")
|
||||||
|
@ -110,20 +110,20 @@ local function finishInstall(files)
|
||||||
end
|
end
|
||||||
fs.move(temp .. file, customPath .. "/" .. file)
|
fs.move(temp .. file, customPath .. "/" .. file)
|
||||||
else
|
else
|
||||||
print("moving " .. file .. " to " .. path .. programToInstall .. "...")
|
print("moving " .. file .. " to " .. path .. program .. "...")
|
||||||
if not fs.exists(path .. programToInstall) then
|
if not fs.exists(path .. program) then
|
||||||
fs.makeDir(path .. programToInstall)
|
fs.makeDir(path .. program)
|
||||||
end
|
end
|
||||||
if fs.exists(path .. programToInstall .. "/" .. file) then
|
if fs.exists(path .. program .. "/" .. file) then
|
||||||
fs.delete(path .. programToInstall .. "/" .. file)
|
fs.delete(path .. program .. "/" .. file)
|
||||||
end
|
end
|
||||||
fs.move(temp .. file, path .. programToInstall .. "/" .. file)
|
fs.move(temp .. file, path .. program .. "/" .. file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if customPath ~= nil then
|
if customPath ~= nil then
|
||||||
local program = "shell.run(" .. customPath .. "/run.lua)"
|
local program = "shell.run(" .. customPath .. "/run.lua)"
|
||||||
file = fs.open(path .. programToInstall .. "/run.lua")
|
file = fs.open(path .. program .. "/run.lua")
|
||||||
file.write(program)
|
file.write(program)
|
||||||
file.close()
|
file.close()
|
||||||
end
|
end
|
||||||
|
@ -137,23 +137,22 @@ if programToInstall == nil then
|
||||||
local programsText = programsFile.readAll()
|
local programsText = programsFile.readAll()
|
||||||
local programsTable = split(programsText, "\n")
|
local programsTable = split(programsText, "\n")
|
||||||
for _, value in ipairs(programsTable) do
|
for _, value in ipairs(programsTable) do
|
||||||
programToInstall = value
|
local files = getAllFiles(value)
|
||||||
local files = getAllFiles()
|
for _, value2 in ipairs(files) do
|
||||||
for _, value in ipairs(files) do
|
downloadFile(value, value2)
|
||||||
downloadFile(value)
|
|
||||||
end
|
end
|
||||||
finishInstall(files)
|
finishInstall(files)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("getting updates...")
|
print("getting updates for " .. programToInstall .. "...")
|
||||||
local files = getAllFiles()
|
local files = getAllFiles(programToInstall)
|
||||||
|
|
||||||
if #files == 0 then
|
if #files == 0 then
|
||||||
print("no updates found.")
|
print("no updates found.")
|
||||||
else
|
else
|
||||||
for _, value in ipairs(files) do
|
for _, value in ipairs(files) do
|
||||||
downloadFile(value)
|
downloadFile(programToInstall, value)
|
||||||
end
|
end
|
||||||
finishInstall(files)
|
finishInstall(programToInstall, files)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue