diff options
Diffstat (limited to 'apps/plugins/lua_scripts.lua')
-rw-r--r-- | apps/plugins/lua_scripts.lua | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/apps/plugins/lua_scripts.lua b/apps/plugins/lua_scripts.lua deleted file mode 100644 index 43593d96b0..0000000000 --- a/apps/plugins/lua_scripts.lua +++ /dev/null | |||
@@ -1,173 +0,0 @@ | |||
1 | --[[ | ||
2 | /*************************************************************************** | ||
3 | * __________ __ ___. | ||
4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | * \/ \/ \/ \/ \/ | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Copyright (C) 2017 William Wilgus | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | ]] | ||
23 | |||
24 | local scrpath = rb.current_path() .. "/lua_scripts/" | ||
25 | |||
26 | package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path | ||
27 | require("printmenus") | ||
28 | |||
29 | rb.actions = nil | ||
30 | package.loaded["actions"] = nil | ||
31 | |||
32 | local excludedsrc = ";filebrowse.lua;fileviewers.lua;printmenu.lua;dbgettags.lua;" | ||
33 | -------------------------------------------------------------------------------- | ||
34 | local Icon_Plugin = 0x9 | ||
35 | |||
36 | |||
37 | local function get_files(path, norecurse, finddir, findfile, f_t, d_t) | ||
38 | |||
39 | local quit = false | ||
40 | |||
41 | local files = f_t or {} | ||
42 | local dirs = d_t or {} | ||
43 | |||
44 | local function f_filedir(name) | ||
45 | --default find function | ||
46 | -- example: return name:find(".mp3", 1, true) ~= nil | ||
47 | if name:len() <= 2 and (name == "." or name == "..") then | ||
48 | return false | ||
49 | end | ||
50 | if string.find(excludedsrc, ";" .. name .. ";") then | ||
51 | return false | ||
52 | end | ||
53 | if string.sub(name, -4) == ".lua" then | ||
54 | return true | ||
55 | end | ||
56 | return false | ||
57 | end | ||
58 | local function d_filedir(name) | ||
59 | --default discard function | ||
60 | return false | ||
61 | end | ||
62 | |||
63 | if finddir == nil then | ||
64 | finddir = f_filedir | ||
65 | elseif type(finddir) ~= "function" then | ||
66 | finddir = d_filedir | ||
67 | end | ||
68 | |||
69 | if findfile == nil then | ||
70 | findfile = f_filedir | ||
71 | elseif type(findfile) ~= "function" then | ||
72 | findfile = d_filedir | ||
73 | end | ||
74 | |||
75 | local function _get_files(path, cancelbtn) | ||
76 | local sep = "" | ||
77 | if string.sub(path, - 1) ~= "/" then sep = "/" end | ||
78 | for fname, isdir in luadir.dir(path) do | ||
79 | |||
80 | if isdir and finddir(fname) then | ||
81 | table.insert(dirs, path .. sep ..fname) | ||
82 | elseif not isdir and findfile(fname) then | ||
83 | table.insert(files, path .. sep ..fname) | ||
84 | end | ||
85 | |||
86 | if rb.get_plugin_action(0) == cancelbtn then | ||
87 | return true | ||
88 | end | ||
89 | end | ||
90 | end | ||
91 | |||
92 | local function cmp_alphanum (op1, op2) | ||
93 | local type1= type(op1) | ||
94 | local type2 = type(op2) | ||
95 | |||
96 | if type1 ~= type2 then | ||
97 | return type1 < type2 | ||
98 | else | ||
99 | if type1 == "string" then | ||
100 | op1 = op1:upper() | ||
101 | op2 = op2:upper() | ||
102 | end | ||
103 | return op1 < op2 | ||
104 | end | ||
105 | end | ||
106 | |||
107 | table.insert(dirs, path) -- root | ||
108 | |||
109 | for key,value in pairs(dirs) do | ||
110 | --luadir.dir may error out so we need to do the call protected | ||
111 | _, quit = pcall(_get_files, value, CANCEL_BUTTON) | ||
112 | |||
113 | if quit == true or norecurse then | ||
114 | break; | ||
115 | end | ||
116 | end | ||
117 | |||
118 | table.sort(files, cmp_alphanum) | ||
119 | table.sort(dirs, cmp_alphanum) | ||
120 | |||
121 | return dirs, files | ||
122 | end -- get_files | ||
123 | -------------------------------------------------------------------------------- | ||
124 | |||
125 | function icon_fn(item, icon) | ||
126 | if item ~= 0 then | ||
127 | icon = Icon_Plugin | ||
128 | else | ||
129 | icon = -1 | ||
130 | end | ||
131 | return icon | ||
132 | end | ||
133 | |||
134 | -- uses print_table and get_files to display simple file browser | ||
135 | function script_choose(dir, title) | ||
136 | local dstr | ||
137 | local hstr = title | ||
138 | |||
139 | local norecurse = true | ||
140 | local f_finddir = false -- function to match directories; nil all, false none | ||
141 | local f_findfile = nil -- function to match files; nil all, false none | ||
142 | local t_linedesc = {show_icons = true, icon_fn = icon_fn} | ||
143 | local p_settings = {wrap = true, hasheader = true, justify = "left", linedesc = t_linedesc} | ||
144 | local files = {} | ||
145 | local dirs = {} | ||
146 | local item = 1 | ||
147 | rb.lcd_clear_display() | ||
148 | |||
149 | while item > 0 do | ||
150 | dirs, files = get_files(dir, norecurse, f_finddir, f_findfile, dirs, files) | ||
151 | for i=1, #dirs do dirs[i] = nil end -- empty table for reuse | ||
152 | table.insert(dirs, 1, hstr) | ||
153 | for i = 1, #files do | ||
154 | table.insert(dirs, "\t" .. string.gsub(files[i], ".*/","")) | ||
155 | end | ||
156 | --print_menu(menu_t, func_t, selected, settings, copy_screen) | ||
157 | _, item = print_menu(dirs, nil, 0, p_settings) | ||
158 | |||
159 | -- If item was selected follow directory or return filename | ||
160 | item = item or -1 | ||
161 | if item > 0 then | ||
162 | dir = files[item - 1] | ||
163 | if not rb.dir_exists("/" .. dir) then | ||
164 | return dir | ||
165 | end | ||
166 | end | ||
167 | |||
168 | end | ||
169 | end -- file_choose | ||
170 | -------------------------------------------------------------------------------- | ||
171 | |||
172 | local script_path = script_choose(scrpath, "lua scripts") | ||
173 | if script_path then rb.restart_lua(script_path) end | ||