@ -6,7 +6,6 @@ local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require ( " ui/widget/container/inputcontainer " )
local Menu = require ( " ui/widget/menu " )
local Screen = require ( " device " ) . screen
local SetDefaults = require ( " apps/filemanager/filemanagersetdefaults " )
local UIManager = require ( " ui/uimanager " )
local lfs = require ( " libs/libkoreader-lfs " )
local logger = require ( " logger " )
@ -56,6 +55,12 @@ local function findcalibre(root)
if mode == " file " then
if entity == calibre or entity == " . " .. calibre then
t = root .. " / " .. entity
-- If we got so far, SEARCH_LIBRARY_PATH is either empty or bogus, so, re-set it,
-- so that we actually can convert a book's relative path to its absolute path.
-- NOTE: No-one should actually rely on that, as the value is *NEVER* saved to the defaults.
-- (SetDefaults can only do that with values modified from within its own advanced menu).
_G [ ' SEARCH_LIBRARY_PATH ' ] = root .. " / "
logger.info ( " FMSearch: Found a SEARCH_LIBRARY_PATH @ " , SEARCH_LIBRARY_PATH )
end
elseif mode == " directory " then
t = findcalibre ( fullPath )
@ -75,12 +80,10 @@ function Search:getCalibre()
self.metafile_1 = findcalibre ( " /mnt " )
if not self.metafile_1 then
self.error = _ ( " SEARCH_LIBRARY_PATH should be defined in DEFAULTS.LUA. " )
else
SetDefaults.settings_changed = true
end
else
if string.sub ( SEARCH_LIBRARY_PATH , string.len ( SEARCH_LIBRARY_PATH ) ) ~= " / " then
SEARCH_LIBRARY_PATH = SEARCH_LIBRARY_PATH .. " / " -- luacheck: ignore
_G[ ' SEARCH_LIBRARY_PATH' ] = SEARCH_LIBRARY_PATH .. " / "
end
if io.open ( SEARCH_LIBRARY_PATH .. calibre , " r " ) == nil then
if io.open ( SEARCH_LIBRARY_PATH .. " . " .. calibre , " r " ) == nil then
@ -98,16 +101,13 @@ function Search:getCalibre()
UIManager : show ( InfoMessage : new { text = _ ( " You must specify at least one field to search at! (SEARCH_XXX = true in defaults.lua) " ) } )
elseif self.metafile_1 == nil then
self.metafile_1 = findcalibre ( " /mnt " )
if self.metafile_1 then
SetDefaults.settings_changed = true
end
end
end
-- check 2nd file
local dummy
if string.sub ( SEARCH_LIBRARY_PATH2 , string.len ( SEARCH_LIBRARY_PATH2 ) ) ~= " / " then
SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. " / " -- luacheck: ignore
_G[ ' SEARCH_LIBRARY_PATH2' ] = SEARCH_LIBRARY_PATH2 .. " / "
end
if io.open ( SEARCH_LIBRARY_PATH2 .. calibre , " r " ) == nil then
if io.open ( SEARCH_LIBRARY_PATH2 .. " . " .. calibre , " r " ) ~= nil then
@ -127,13 +127,15 @@ function Search:getCalibre()
if self.metafile_1 then
pcall ( lfs.mkdir ( " temp " ) )
if io.open ( koreaderfile , " r " ) then
if lfs.attributes ( koreaderfile ). modification > lfs.attributes ( self.metafile_1 ) . modification then
if lfs.attributes ( koreaderfile , " modification " ) > lfs.attributes ( self.metafile_1 , " modification " ) then
if self.metafile_2 then
if lfs.attributes ( koreaderfile ). modification > lfs.attributes ( self.metafile_2 ) . modification then
if lfs.attributes ( koreaderfile , " modification " ) > lfs.attributes ( self.metafile_2 , " modification " ) then
self.use_own_metadata_file = true
logger.info ( " FMSearch: Using our own simplified metadata file as it's newer than " , self.metafile_2 )
end
else
self.use_own_metadata_file = true
logger.info ( " FMSearch: Using our own simplified metadata file as it's newer than " , self.metafile_1 )
end
end
end
@ -153,7 +155,7 @@ function Search:ShowSearch()
enabled = true ,
callback = function ( )
self.search_value = self.search_dialog : getInputText ( )
if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == " series " then
if self.search_value == dummy and self.lastsearch == " series " then
self.use_previous_search_results = true
else
self.use_previous_search_results = false
@ -167,7 +169,7 @@ function Search:ShowSearch()
enabled = true ,
callback = function ( )
self.search_value = self.search_dialog : getInputText ( )
if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == " tags " then
if self.search_value == dummy and self.lastsearch == " tags " then
self.use_previous_search_results = true
else
self.use_previous_search_results = false
@ -191,7 +193,7 @@ function Search:ShowSearch()
enabled = true ,
callback = function ( )
self.search_value = self.search_dialog : getInputText ( )
if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == " find " then
if self.search_value == dummy and self.lastsearch == " find " then
self.use_previous_search_results = true
else
self.use_previous_search_results = false
@ -346,6 +348,8 @@ function Search:find(option)
self.browse_tags [ string.sub ( j , 2 ) ] = ( self.browse_tags [ string.sub ( j , 2 ) ] or 0 ) + 1
end
end
-- NOTE: This skips kePubs downloaded by nickel, because they don't have a file extension,
-- they're stored as .kobo/kepub/<UUID>
if DocumentRegistry : hasProvider ( self.data [ i ] [ self.path ] ) then
if upsearch ~= " " then
if string.find ( search_content , upsearch , nil , true ) then
@ -375,10 +379,11 @@ function Search:find(option)
end
end
if not self.use_own_metadata_file then
logger.info ( " FMSearch: Writing our own simplified metadata file . . . " )
local g = io.open ( koreaderfile , " w " )
g : write ( " #metadata.koreader Version 1.1 \n " )
f = io.open ( self.metafile_1 )
f = io.open ( self.metafile_1 , " r " )
line = f : read ( )
while line do
if line == " }, " or line == " } " then
@ -448,20 +453,20 @@ function Search:find(option)
firstrun = false
if self.metafile_2 then
f = io.open ( self.metafile_2 )
f = io.open ( self.metafile_2 , " r " )
line = f : read ( )
end
end
end
g.close ( )
if lfs.attributes ( koreaderfile ). modification < lfs.attributes ( self.metafile_1 ) . modification then
if lfs.attributes ( koreaderfile , " modification " ) < lfs.attributes ( self.metafile_1 , " modification " ) then
lfs.touch ( koreaderfile ,
lfs.attributes ( self.metafile_1 ). modification + 1 ,
lfs.attributes ( self.metafile_1 ). modification + 1 )
lfs.attributes ( self.metafile_1 , " modification " ) + 1 ,
lfs.attributes ( self.metafile_1 , " modification " ) + 1 )
end
if self.metafile_2 then
if lfs.attributes ( koreaderfile ). modification < lfs.attributes ( self.metafile_2 ) . modification then
lfs.touch ( koreaderfile , lfs.attributes ( self.metafile_2 ). modification + 1 , lfs.attributes ( self.metafile_2 ) . modification + 1 )
if lfs.attributes ( koreaderfile , " modification " ) < lfs.attributes ( self.metafile_2 , " modification " ) then
lfs.touch ( koreaderfile , lfs.attributes ( self.metafile_2 , " modification " ) + 1 , lfs.attributes ( self.metafile_2 , " modification " ) + 1 )
end
end
end
@ -487,7 +492,7 @@ function Search:onMenuHold(item)
if item.notchecked then
item.info = item.info .. item.path
local f = io.open ( item.path )
local f = io.open ( item.path , " r " )
if f == nil then
item.info = item.info .. " \n " .. _ ( " File not found! " )
else