Commit 25c8660b authored by Danny SMc's avatar Danny SMc 🎧

Added updater and file packer

parent 709890ff
-- Written by DannySMc
-- Twitter: @dannysmc95
-- uAPI Version: 1.4
version = 2.1
function getVer()
uVer = "1.4"
......@@ -446,3 +446,98 @@ function decrypt(data,psw) -- args strInput and strPassword
return oData,out,chs
end
-- Checks for uAPI update!
function checkUpdate()
if http then
local getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/uVersions")
local getGit = getGit.readAll()
NVersion = textutils.unserialize(getGit)
if NVersion["uapi"].Version > version then
getGit = http.get(NVersion["uapi"].GitURL)
getGit = getGit.readAll()
local file = fs.open("uapi", "w")
file.write(getGit)
file.close()
return true
end
else
return false
end
end
-- File Compression
local function readFile(filename)
local contents = {}
if fs.exists(filename) then
local file = fs.open(filename, "r")
while true do
line = file.readLine()
if line then
table.insert(contents, line)
else
file.close()
contents.filename = fs.getName(filename)
return contents
end
end
else
error("File doesn't exist.")
end
end
local function prepFiles(dir)
if fs.exists(dir) and fs.isDir(dir) then
local files = fs.list(dir)
local contents = {}
contents.bunch = true
for _,name in pairs(files) do
if fs.isDir(name) == false then
contents[name] = readFile(dir..name)
end
end
return contents
else
error("Not a directory.")
end
end
function unpackFiles(m, dir)
if (fs.exists(dir) == false) and (fs.isDir(dir) == false) then
error("Passed dir is not a dir or doesn't exist")
end
if type(m) == "table" then
if m.bunch then
for name,data in pairs(m) do
if type(data) == "table" then
file = fs.open(dir.. data.filename, "w")
for i = 1, #data do
file.writeLine(data[i])
end
file.close()
end
end
else
file = fs.open(dir.. m.filename, "w")
for i = 1, #m do
file.writeLine(m[i])
end
file.close()
end
else
error("Not a table.")
end
end
function unpackFile(message, dir)
unpackFiles(message, dir)
end
function packFile(filename)
local file = readFile(filename)
return file
end
function packDir(dir)
local filer = prepFiles(dir)
return filer
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment