1
0
mirror of https://github.com/kepler155c/opus synced 2025-02-06 04:00:03 +00:00
opus/sys/apis/config.lua

50 lines
992 B
Lua
Raw Normal View History

2016-12-11 14:24:52 -05:00
local Util = require('util')
2018-01-04 03:30:59 -05:00
local fs = _G.fs
local shell = _ENV.shell
2017-10-08 17:45:01 -04:00
2016-12-11 14:24:52 -05:00
local Config = { }
2018-01-04 03:30:59 -05:00
function Config.load(fname, data)
2017-05-20 18:27:26 -04:00
local filename = 'usr/config/' .. fname
2016-12-11 14:24:52 -05:00
2017-05-20 18:27:26 -04:00
if not fs.exists('usr/config') then
2018-01-24 17:39:38 -05:00
fs.makeDir('usr/config')
2016-12-11 14:24:52 -05:00
end
if not fs.exists(filename) then
2018-01-24 17:39:38 -05:00
Util.writeTable(filename, data)
2016-12-11 14:24:52 -05:00
else
2018-10-21 04:46:40 -04:00
local contents = Util.readTable(filename) or
error('Configuration file is corrupt:' .. filename)
Util.merge(data, contents)
2016-12-11 14:24:52 -05:00
end
2018-11-09 15:07:55 -05:00
return data
2016-12-11 14:24:52 -05:00
end
2018-01-04 03:30:59 -05:00
function Config.loadWithCheck(fname, data)
local filename = 'usr/config/' .. fname
if not fs.exists(filename) then
2018-01-24 17:39:38 -05: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 03:30:59 -05:00
end
2018-11-09 15:07:55 -05:00
return Config.load(fname, data)
2018-01-04 03:30:59 -05:00
end
function Config.update(fname, data)
2017-05-20 18:27:26 -04:00
local filename = 'usr/config/' .. fname
2016-12-11 14:24:52 -05:00
Util.writeTable(filename, data)
end
2018-01-04 03:30:59 -05:00
return Config