1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-26 16:40:27 +00:00
opus/sys/apis/config.lua

45 lines
903 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
fs.makeDir('usr/config')
2016-12-11 19:24:52 +00:00
end
if not fs.exists(filename) then
Util.writeTable(filename, data)
else
Util.merge(data, Util.readTable(filename) or { })
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
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)
end
Config.load(fname, data)
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