installer first pass

This commit is contained in:
jane 2021-06-05 23:32:27 -04:00
parent 762c17026c
commit bdb3b39d4c

View file

@ -1,6 +1,6 @@
args = {...}
url = "https://lua.gaywine.org"
url = "http://lua.gaywine.org"
path = "bin/"
if not fs.exists(path) then
@ -18,8 +18,49 @@ if #args > 1 then
customPath = shell.resolve(args[2])
end
function arrayAppend(array, value)
array[#array + 1] = value
function downloadFile(filename)
fileUrl = url .. "/files/" .. programToInstall .. "/" .. filename
result = http.get(fileUrl)
resultText = result.readAll()
file = fs.open(temp .. filename, "w")
file.write(resultText)
file.close()
end
function split(pString, pPattern)
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
function getAllFiles()
indexesUrl = url .. "/indexes/" .. programToInstall
result = http.get(indexesUrl)
resultText = result.readAll()
resultTable = split(resultText, "\n")
finalResult = {}
for key, value in ipairs(resultTable) do
finalResult[key] = split(value, " ")[1]
end
return finalResult
end
function finishInstall(files)
@ -40,3 +81,9 @@ function finishInstall(files)
fs.delete(temp)
end
local files = getAllFiles()
for _,value in ipairs(files) do
downloadFile(value)
end
finishInstall(files)