make dir if does not exist

This commit is contained in:
jane 2021-06-06 00:33:47 -04:00
parent 8c2d3acdec
commit 1d58f51ba4
2 changed files with 25 additions and 13 deletions

View file

@ -59,8 +59,8 @@ local function getAllFiles()
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 " .. programToInstall)
error() error()
end end
local resultText = result.readAll() local resultText = result.readAll()
local resultTable = split(resultText, "\n") local resultTable = split(resultText, "\n")
@ -85,14 +85,20 @@ local function finishInstall(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 .. "...")
if not fs.exists(customPath) then
fs.makeDir(customPath)
end
if fs.exists(customPath .. "/" .. file) then if fs.exists(customPath .. "/" .. file) then
fs.delete(customPath .. "/" .. file) fs.delete(customPath .. "/" .. file)
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 .. programToInstall .. "...")
if not fs.exists(path .. programToInstall) then
fs.makeDir(path .. programToInstall)
end
if fs.exists(path .. programToInstall .. "/" .. file) then if fs.exists(path .. programToInstall .. "/" .. file) then
fs.delete(path .. programToInstall .. "/" .. file) fs.delete(path .. programToInstall .. "/" .. file)
end end
fs.move(temp .. file, path .. programToInstall .. "/" .. file) fs.move(temp .. file, path .. programToInstall .. "/" .. file)
end end
@ -109,9 +115,9 @@ local function finishInstall(files)
end end
if not fs.exists(path .. "programs.dat") then if not fs.exists(path .. "programs.dat") then
local file = fs.open(path .. "programs.dat", "w") local file = fs.open(path .. "programs.dat", "w")
file.write("") file.write("")
file.close() file.close()
end end
local programsFile = fs.open(path .. "programs.dat", "r") local programsFile = fs.open(path .. "programs.dat", "r")
local programsText = programsFile.readAll() local programsText = programsFile.readAll()

View file

@ -63,16 +63,16 @@ 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 " .. programToInstall)
error() error()
end end
local resultText = result.readAll() local resultText = result.readAll()
local resultTable = split(resultText, "\n") local resultTable = split(resultText, "\n")
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 " .. programToInstall)
error() error()
end end
local resultText2 = result2.readAll() local resultText2 = result2.readAll()
local resultTable2 = split(resultText2, "\n") local resultTable2 = split(resultText2, "\n")
@ -102,14 +102,20 @@ local function finishInstall(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 .. "...")
if not fs.exists(customPath) then
fs.makeDir(customPath)
end
if fs.exists(customPath .. "/" .. file) then if fs.exists(customPath .. "/" .. file) then
fs.delete(customPath .. "/" .. file) fs.delete(customPath .. "/" .. file)
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 .. programToInstall .. "...")
if not fs.exists(path .. programToInstall) then
fs.makeDir(path .. programToInstall)
end
if fs.exists(path .. programToInstall .. "/" .. file) then if fs.exists(path .. programToInstall .. "/" .. file) then
fs.delete(path .. programToInstall .. "/" .. file) fs.delete(path .. programToInstall .. "/" .. file)
end end
fs.move(temp .. file, path .. programToInstall .. "/" .. file) fs.move(temp .. file, path .. programToInstall .. "/" .. file)
end end