Something went wrong. Try again.
A modern, network-enabled music player platform built on Rockbox technology. rockboxd.tsiry-sandratraina.com
rust deno navidrome airplay libadwaita zig mpris snapcast mpd rockbox audio subsonic
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151--[[/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * * Copyright (C) 2017 William Wilgus * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/]]if ... == nil then rb.splash(rb.HZ * 3, "use 'require'") endrequire("printtable")local _lcd = require("lcd")local _timer = require("timer")local tmploader = require("temploader")--local get_files = require("get_files")--Using tmploader instead
--------------------------------------------------------------------------------
-- uses print_table and get_files to display simple file browser-- sort_by "date" "name" "size" "type"-- descending true/false-- returns selected file and attribs string if get_attr == truefunction file_choose(dir, title, sort_by, descending, get_attr) local dstr, hstr = "" if not title then dstr = "%d items found in %0d.%02d seconds" else hstr = title end
if not sort_by then sort_by = "name" end sort_by = sort_by:lower()
-- returns whole seconds and remainder local function tick2seconds(ticks) local secs = (ticks / rb.HZ) local csecs = (ticks - (secs * rb.HZ)) return secs, csecs end
local recurse = false local f_finddir = nil -- function to match directories; nil all, false none local f_findfile = nil -- function to match files; nil all, false none
local p_settings = {wrap = true, hasheader = true}
local timer local files = {} local dirs = {} local attrs = {} local item = 1 local cancel_fn = nil
if CANCEL_BUTTON and CANCEL_BUTTON > 0 then cancel_fn = function() if rb.get_plugin_action(0) == CANCEL_BUTTON then rb.splash(0, "Canceled") return true end return false end else cancel_fn = function() if rb.action_userabort(0)then rb.splash(0, "Canceled") return true end return false end end
_lcd:clear() local get_files = tmploader("get_files") while item > 0 do if not title then timer = _timer() end rb.splash(1, "Searching for Files") dirs, files = get_files(dir, recurse, f_finddir, f_findfile, sort_by, cancel_fn, dirs, files)
local ndirs = #dirs local parentdir = dirs[1] for i = 1, ndirs do dirs[i] = "\t" .. dirs[i] end
if not get_attr then if not descending then for i = 1, #files do -- only store file name .. strip attributes from end and parent from beginning table.insert(dirs, "\t" .. string.match(string.match(files[i], "[^/\\]+$") or "?", "[^;]+") or "?") end else for i = #files, 1, -1 do -- only store file name .. strip attributes from end and parent from beginning table.insert(dirs, "\t" .. string.match(string.match(files[i], "[^/\\]+$") or "?", "[^;]+") or "?") end end else -- get_attr == true if not descending then for i = 1, #files do -- only store file name .. strip attributes from end and parent from beginning table.insert(dirs, "\t" .. string.match(string.match(files[i], "[^/\\]+$") or "?", "[^;]+") or "?") table.insert(attrs, string.match(files[i], ";(.+)")) end else for i = #files, 1, -1 do -- only store file name .. strip attributes from end and parent from beginning table.insert(dirs, "\t" .. string.match(string.match(files[i], "[^/\\]+$") or "?", "[^;]+") or "?") table.insert(attrs, string.match(files[i], ";(.+)")) end end end for i=1, #files do files[i] = nil end -- empty table for reuse
if not title then hstr = string.format(dstr, #dirs - 1, tick2seconds(timer:stop())) end
table.insert(dirs, 1, hstr)
item = print_table(dirs, #dirs, p_settings)
-- If item was selected follow directory or return filename if item > 0 then dir = string.gsub(dirs[item], "%c+","") if not rb.dir_exists("/" .. dir) then if (parentdir == "/") then return parentdir .. dir, attrs[item - ndirs - 1] -- -1 for hstr else return parentdir .. "/" .. dir, attrs[item - ndirs - 1] end end end
if dir == parentdir then dir = dir:sub(1, dir:match(".*()/") - 1) if dir == "" then dir = "/" end end for i=1, #dirs do dirs[i] = nil end -- empty table for reuse for i=1, #attrs do attrs[i] = nil end -- empty table for reuse endend -- file_choose--------------------------------------------------------------------------------