From 78c34e60fad6faa60a48bcb91a3b321139bad971 Mon Sep 17 00:00:00 2001 From: yparitcher Date: Sat, 6 Mar 2021 13:31:39 -0500 Subject: [PATCH] FileSearcher: Do not crash on space, show unsupported files if enabled. (#7362) --- .../filemanager/filemanagerfilesearcher.lua | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/frontend/apps/filemanager/filemanagerfilesearcher.lua b/frontend/apps/filemanager/filemanagerfilesearcher.lua index a5898af7a..117c7c133 100644 --- a/frontend/apps/filemanager/filemanagerfilesearcher.lua +++ b/frontend/apps/filemanager/filemanagerfilesearcher.lua @@ -30,6 +30,9 @@ local FileSearcher = InputContainer:new{ } function FileSearcher:readDir() + local FileManager = require("apps/filemanager/filemanager") + local ReaderUI = require("apps/reader/readerui") + local show_unsupported = G_reader_settings:isTrue("show_unsupported") self.dirs = {self.path} self.files = {} while #self.dirs ~= 0 do @@ -43,10 +46,10 @@ function FileSearcher:readDir() -- Don't traverse hidden folders if we're not showing them if attributes.mode == "directory" and f ~= "." and f ~= ".." and (G_reader_settings:isTrue("show_hidden") or not util.stringStartsWith(f, ".")) then table.insert(new_dirs, fullpath) - table.insert(self.files, {name = f, path = fullpath, attr = attributes}) + table.insert(self.files, {name = f, text = f.."/", attr = attributes, callback = function() FileManager:showFiles(fullpath) end}) -- Always ignore macOS resource forks, too. - elseif attributes.mode == "file" and not util.stringStartsWith(f, "._") and DocumentRegistry:hasProvider(fullpath) then - table.insert(self.files, {name = f, path = fullpath, attr = attributes}) + elseif attributes.mode == "file" and not util.stringStartsWith(f, "._") and (show_unsupported or DocumentRegistry:hasProvider(fullpath)) then + table.insert(self.files, {name = f, text = f, attr = attributes, callback = function() ReaderUI:showReader(fullpath) end}) end end end @@ -55,30 +58,14 @@ function FileSearcher:readDir() end function FileSearcher:setSearchResults() - local FileManager = require("apps/filemanager/filemanager") - local ReaderUI = require("apps/reader/readerui") local keywords = self.search_value self.results = {} - if keywords == " " then -- one space to show all files + if keywords == "*" then -- one * to show all files self.results = self.files else for __,f in pairs(self.files) do if string.find(string.lower(f.name), string.lower(keywords)) and string.sub(f.name,-4) ~= ".sdr" then - if f.attr.mode == "directory" then - f.text = f.name.."/" - f.name = nil - f.callback = function() - FileManager:showFiles(f.path) - end - table.insert(self.results, f) - else - f.text = f.name - f.name = nil - f.callback = function() - ReaderUI:showReader(f.path) - end - table.insert(self.results, f) - end + table.insert(self.results, f) end end end