mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 19:13:49 +01:00
Reset logic delete's all uci values and then reset them to the defaults
(Allow setting value to value that is the default)
This commit is contained in:
parent
8dc3be6199
commit
348c088cc9
@ -216,7 +216,7 @@ end
|
|||||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||||
-- @treturn ?string Error message in case first return value is nil (invalid key).
|
-- @treturn ?string Error message in case first return value is nil (invalid key).
|
||||||
function M.set(key, value)
|
function M.set(key, value)
|
||||||
--log:info("settings:set: "..utils.dump(key))
|
log:info("settings:set: "..utils.dump(key).." to: "..utils.dump(value))
|
||||||
key = replaceDots(key)
|
key = replaceDots(key)
|
||||||
|
|
||||||
local r = utils.create(UCI_CONFIG_FILE)
|
local r = utils.create(UCI_CONFIG_FILE)
|
||||||
@ -225,9 +225,6 @@ function M.set(key, value)
|
|||||||
local base = getBaseKeyTable(key)
|
local base = getBaseKeyTable(key)
|
||||||
if not base then return nil,ERR_NO_SUCH_KEY end
|
if not base then return nil,ERR_NO_SUCH_KEY end
|
||||||
|
|
||||||
if M.isDefault(key) and value == nil then return true end -- key is default already
|
|
||||||
--log:info(" not default")
|
|
||||||
|
|
||||||
--log:info(" base.type: "..utils.dump(base.type))
|
--log:info(" base.type: "..utils.dump(base.type))
|
||||||
if base.type == 'bool' then
|
if base.type == 'bool' then
|
||||||
if value ~= "" then
|
if value ~= "" then
|
||||||
@ -248,11 +245,6 @@ function M.set(key, value)
|
|||||||
return nil,m
|
return nil,m
|
||||||
end
|
end
|
||||||
|
|
||||||
--local current = uci:get(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key)
|
|
||||||
local current = M.get(key)
|
|
||||||
--if fromUciValue(current, base.type) == value then return true end
|
|
||||||
if current == value then return true end
|
|
||||||
|
|
||||||
local section = UCI_CONFIG_SECTION;
|
local section = UCI_CONFIG_SECTION;
|
||||||
if base.subSection ~= nil then
|
if base.subSection ~= nil then
|
||||||
section = M.get(base.subSection)
|
section = M.get(base.subSection)
|
||||||
@ -275,13 +267,22 @@ end
|
|||||||
function M.resetAll()
|
function M.resetAll()
|
||||||
log:info("settings:resetAll")
|
log:info("settings:resetAll")
|
||||||
|
|
||||||
|
-- delete all uci sections but system
|
||||||
local allSections = uci:get_all(UCI_CONFIG_NAME)
|
local allSections = uci:get_all(UCI_CONFIG_NAME)
|
||||||
|
|
||||||
for key,value in pairs(allSections) do
|
for key,value in pairs(allSections) do
|
||||||
if key ~= "system" and not key:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
|
if key ~= "system" and not key:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
|
||||||
|
|
||||||
uci:delete(UCI_CONFIG_NAME,key)
|
uci:delete(UCI_CONFIG_NAME,key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- reset all to defaults
|
||||||
|
for k,_ in pairs(baseconfig) do
|
||||||
|
if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
|
||||||
|
M.reset(k)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
uci:commit(UCI_CONFIG_NAME)
|
uci:commit(UCI_CONFIG_NAME)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -291,22 +292,21 @@ end
|
|||||||
-- @string key The key to reset.
|
-- @string key The key to reset.
|
||||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||||
function M.reset(key)
|
function M.reset(key)
|
||||||
--log:info("settings:reset: "..utils.dump(key))
|
log:info("settings:reset: "..utils.dump(key))
|
||||||
|
|
||||||
--uci:foreach(UCI_CONFIG_NAME,UCI_CONFIG_TYPE)
|
|
||||||
--uci:delete(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key)
|
|
||||||
|
|
||||||
|
-- delete
|
||||||
key = replaceDots(key)
|
key = replaceDots(key)
|
||||||
local base = getBaseKeyTable(key)
|
local base = getBaseKeyTable(key)
|
||||||
if not base then return nil,ERR_NO_SUCH_KEY end
|
if not base then return nil,ERR_NO_SUCH_KEY end
|
||||||
|
|
||||||
local section = UCI_CONFIG_SECTION;
|
local section = UCI_CONFIG_SECTION;
|
||||||
if base.subSection ~= nil then
|
if base.subSection ~= nil then
|
||||||
section = M.get(base.subSection)
|
section = M.get(base.subSection)
|
||||||
end
|
end
|
||||||
|
|
||||||
uci:delete(UCI_CONFIG_NAME, section, key)
|
uci:delete(UCI_CONFIG_NAME, section, key)
|
||||||
|
|
||||||
|
-- reuse get logic to retrieve default and set it.
|
||||||
|
M.set(key,M.get(key))
|
||||||
|
|
||||||
uci:commit(UCI_CONFIG_NAME)
|
uci:commit(UCI_CONFIG_NAME)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user