1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-15 13:14:49 +00:00
opus/sys/apis/config.lua

48 lines
971 B
Lua
Raw Normal View History

2016-12-11 19:24:52 +00:00
local Util = require('util')
2018-01-04 08:30:59 +00:00
local fs = _G.fs
local shell = _ENV.shell
2017-10-08 21:45:01 +00:00
2016-12-11 19:24:52 +00:00
local Config = { }
2018-01-04 08:30:59 +00:00
function Config.load(fname, data)
2017-05-20 22:27:26 +00:00
local filename = 'usr/config/' .. fname
2016-12-11 19:24:52 +00:00
2017-05-20 22:27:26 +00:00
if not fs.exists('usr/config') then
2018-01-24 22:39:38 +00:00
fs.makeDir('usr/config')
2016-12-11 19:24:52 +00:00
end
if not fs.exists(filename) then
2018-01-24 22:39:38 +00:00
Util.writeTable(filename, data)
2016-12-11 19:24:52 +00:00
else
2018-10-21 08:46:40 +00:00
local contents = Util.readTable(filename) or
error('Configuration file is corrupt:' .. filename)
Util.merge(data, contents)
2016-12-11 19:24:52 +00:00
end
end
2018-01-04 08:30:59 +00:00
function Config.loadWithCheck(fname, data)
local filename = 'usr/config/' .. fname
if not fs.exists(filename) then
2018-01-24 22:39:38 +00:00
Config.load(fname, data)
print()
print('The configuration file has been created.')
print('The file name is: ' .. filename)
print()
_G.printError('Press enter to configure')
_G.read()
shell.run('edit ' .. filename)
2018-01-04 08:30:59 +00:00
end
2018-01-24 22:39:38 +00:00
Config.load(fname, data)
2018-01-04 08:30:59 +00:00
end
function Config.update(fname, data)
2017-05-20 22:27:26 +00:00
local filename = 'usr/config/' .. fname
2016-12-11 19:24:52 +00:00
Util.writeTable(filename, data)
end
2018-01-04 08:30:59 +00:00
return Config