1
0
mirror of https://github.com/kepler155c/opus synced 2024-06-23 13:43:21 +00:00
opus/sys/apis/packages.lua

53 lines
1.0 KiB
Lua
Raw Normal View History

2018-10-21 00:35:48 +00:00
local Util = require('util')
local fs = _G.fs
2018-11-03 22:13:41 +00:00
local textutils = _G.textutils
2018-10-21 00:35:48 +00:00
local PACKAGE_DIR = 'packages'
local Packages = { }
function Packages:installed()
self.cache = { }
if fs.exists(PACKAGE_DIR) then
for _, dir in pairs(fs.list(PACKAGE_DIR)) do
local path = fs.combine(fs.combine(PACKAGE_DIR, dir), '.package')
self.cache[dir] = Util.readTable(path)
end
end
return self.cache
end
function Packages:list()
2018-11-03 22:13:41 +00:00
if self.packageList then
return self.packageList
end
self.packageList = Util.readTable('sys/packageList.lua') or { }
return self.packageList
2018-10-21 00:35:48 +00:00
end
function Packages:isInstalled(package)
return self:installed()[package]
end
2018-11-03 22:13:41 +00:00
function Packages:getManifest(package)
2018-11-04 18:00:37 +00:00
local fname = 'packages/' .. package .. '/.package'
2018-11-03 22:13:41 +00:00
if fs.exists(fname) then
return Util.readTable(fname)
end
local list = self:list()
local url = list and list[package]
if url then
local c = Util.httpGet(url) -- will need to call load
if c then
return textutils.unserialize(c)
end
end
end
2018-10-21 00:35:48 +00:00
return Packages