summaryrefslogtreecommitdiffstats
path: root/apps/plugins/lua_scripts/dump_rbsettings.lua
blob: 2811d2748758e8b4688229de160d1447b1cef6f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require("rbsettings")
require("settings")
rb.metadata = nil -- remove track metadata settings
-------------------------------------------------------------------------------

local function print_setting_table(t_tbl, s_sep)
    s_sep = s_sep or ""
    local str = ""
    local function pfunct(t, sep, s, n) -- recursive print function
        local vtype
        for k, v in pairs(t) do
            vtype = type(v)
            if vtype == "table" then
                local f = string.format("%s[%s]", n, k)
                s = pfunct(v, sep, s, f)
            elseif vtype ==  "boolean" then
                v = v and "true" or "false"
                s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep)
            elseif v then
                s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep)
            end
        end
        return s
    end
    return pfunct(t_tbl, s_sep, str, "")
end

local filename = "/settings.txt"
local file = io.open(filename, "w+") -- overwrite
local t_settings

if not file then
    rb.splash(rb.HZ, "Error writing " .. filename)
    return
end

t_settings = rb.settings.dump('global_settings', "system")
file:write("global_settings:\n")
file:write(print_setting_table(t_settings, "\n"))
file:write("\n\n")

t_settings = rb.settings.dump('global_status', "system")
file:write("global_status:\n")
file:write(print_setting_table(t_settings, "\n"))
file:write("\n\n")

file:close()

rb.splash(100, "rb settings dumped: " .. filename)