fix(inferium-server): create persisted configs file if don't exist
This commit is contained in:
parent
baba577b62
commit
43c936bf3b
@ -1,7 +1,7 @@
|
||||
local net = require('libs/net')
|
||||
local inferium = require('config/inferium')
|
||||
|
||||
local VERSION = "1.1.0"
|
||||
local VERSION = "1.1.1"
|
||||
local INFERIUM_SERVER = 'inferium.com'
|
||||
|
||||
local PERSISTED_CONFIGS = '/data/inferium-configs'
|
||||
@ -9,19 +9,6 @@ local UPGRADE_SCRIPT = '/upgrade.lua'
|
||||
|
||||
local defaultConfig = inferium.defaultConfig or error('no default config provided in config', 0)
|
||||
|
||||
local readPersistedConfigs = function()
|
||||
local file = fs.open(PERSISTED_CONFIGS, 'r')
|
||||
|
||||
if not file then
|
||||
return nil
|
||||
end
|
||||
|
||||
local serializedConfigs = file.readAll()
|
||||
file.close()
|
||||
|
||||
return textutils.unserialize(serializedConfigs)
|
||||
end
|
||||
|
||||
local savePersistedConfigs = function(configs)
|
||||
local file = fs.open(PERSISTED_CONFIGS, 'w')
|
||||
|
||||
@ -33,7 +20,22 @@ local savePersistedConfigs = function(configs)
|
||||
file.close()
|
||||
end
|
||||
|
||||
local LOCAL_CONFIGS = readPersistedConfigs() or {}
|
||||
local readPersistedConfigs = function()
|
||||
local file = fs.open(PERSISTED_CONFIGS, 'r')
|
||||
|
||||
if not file then
|
||||
local initialConfig = {}
|
||||
savePersistedConfigs(initialConfig)
|
||||
return initialConfig
|
||||
end
|
||||
|
||||
local serializedConfigs = file.readAll()
|
||||
file.close()
|
||||
|
||||
return textutils.unserialize(serializedConfigs)
|
||||
end
|
||||
|
||||
local LOCAL_CONFIGS = readPersistedConfigs()
|
||||
|
||||
local function getConfigForComputer(computerId)
|
||||
return LOCAL_CONFIGS[tostring(computerId)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user