diff options
author | William Wilgus <me.theuser@yahoo.com> | 2019-09-06 19:24:26 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2019-09-07 03:10:59 +0200 |
commit | 267d04d2bd2a7681c8bbcfbb655612101440b765 (patch) | |
tree | a518b4c10244cc77a5eee636132031c5a542c00a /apps/plugins/lua_scripts/dump_rbsettings.lua | |
parent | a3cbd86a5193e5227344db360f45f114fda10aab (diff) | |
download | rockbox-267d04d2bd2a7681c8bbcfbb655612101440b765.tar.gz rockbox-267d04d2bd2a7681c8bbcfbb655612101440b765.zip |
Lua add metadata and settings reading helper module
Adds example scripts for reading track metadata + dumping albumart
and rockbox settings
settings are now stored as a table of strings rather than a table of tables
as it saves ~15 kb of ram without adding much complexity
Change-Id: I611c312b2a60ab96e595e4710b17aedbd6c0689b
Diffstat (limited to 'apps/plugins/lua_scripts/dump_rbsettings.lua')
-rw-r--r-- | apps/plugins/lua_scripts/dump_rbsettings.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/apps/plugins/lua_scripts/dump_rbsettings.lua b/apps/plugins/lua_scripts/dump_rbsettings.lua new file mode 100644 index 0000000000..2811d27487 --- /dev/null +++ b/apps/plugins/lua_scripts/dump_rbsettings.lua | |||
@@ -0,0 +1,49 @@ | |||
1 | require("rbsettings") | ||
2 | require("settings") | ||
3 | rb.metadata = nil -- remove track metadata settings | ||
4 | ------------------------------------------------------------------------------- | ||
5 | |||
6 | local function print_setting_table(t_tbl, s_sep) | ||
7 | s_sep = s_sep or "" | ||
8 | local str = "" | ||
9 | local function pfunct(t, sep, s, n) -- recursive print function | ||
10 | local vtype | ||
11 | for k, v in pairs(t) do | ||
12 | vtype = type(v) | ||
13 | if vtype == "table" then | ||
14 | local f = string.format("%s[%s]", n, k) | ||
15 | s = pfunct(v, sep, s, f) | ||
16 | elseif vtype == "boolean" then | ||
17 | v = v and "true" or "false" | ||
18 | s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep) | ||
19 | elseif v then | ||
20 | s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep) | ||
21 | end | ||
22 | end | ||
23 | return s | ||
24 | end | ||
25 | return pfunct(t_tbl, s_sep, str, "") | ||
26 | end | ||
27 | |||
28 | local filename = "/settings.txt" | ||
29 | local file = io.open(filename, "w+") -- overwrite | ||
30 | local t_settings | ||
31 | |||
32 | if not file then | ||
33 | rb.splash(rb.HZ, "Error writing " .. filename) | ||
34 | return | ||
35 | end | ||
36 | |||
37 | t_settings = rb.settings.dump('global_settings', "system") | ||
38 | file:write("global_settings:\n") | ||
39 | file:write(print_setting_table(t_settings, "\n")) | ||
40 | file:write("\n\n") | ||
41 | |||
42 | t_settings = rb.settings.dump('global_status', "system") | ||
43 | file:write("global_status:\n") | ||
44 | file:write(print_setting_table(t_settings, "\n")) | ||
45 | file:write("\n\n") | ||
46 | |||
47 | file:close() | ||
48 | |||
49 | rb.splash(100, "rb settings dumped: " .. filename) | ||