mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
read document configuration files from history dir
this feature was introduced by @NuPogodi in old KPV
This commit is contained in:
@@ -1,8 +1,36 @@
|
||||
DocSettings = {}
|
||||
|
||||
function DocSettings:getHistoryPath(fullpath)
|
||||
local i = #fullpath - 1
|
||||
-- search for last slash
|
||||
while i > 0 do
|
||||
if fullpath:sub(i,i) == "/" then
|
||||
break
|
||||
end
|
||||
i = i - 1
|
||||
end
|
||||
-- construct path to configuration file in history dir
|
||||
local filename = fullpath:sub(i+1, -1)
|
||||
local basename = fullpath:sub(1, i)
|
||||
return "./history/["..basename:gsub("/","#").."] "..filename..".lua"
|
||||
end
|
||||
|
||||
function DocSettings:open(docfile)
|
||||
local new = { file = docfile..".kpdfview.lua", data = {} }
|
||||
local ok, stored = pcall(dofile,new.file)
|
||||
local conf_path = nil
|
||||
if docfile == ".reader" then
|
||||
-- we handle reader setting as special case
|
||||
conf_path = "settings.reader.lua"
|
||||
else
|
||||
conf_path = self:getHistoryPath(docfile)
|
||||
end
|
||||
-- construct settings obj
|
||||
local new = { file = conf_path, data = {} }
|
||||
local ok, stored = pcall(dofile, new.file)
|
||||
if not ok then
|
||||
-- try legacy conf path, for backward compatibility. this also
|
||||
-- takes care of reader legacy setting
|
||||
ok, stored = pcall(dofile, docfile..".kpdfview.lua")
|
||||
end
|
||||
if ok then
|
||||
new.data = stored
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require "ui/menu"
|
||||
FileChooser = Menu:new{
|
||||
height = Screen:getHeight(),
|
||||
width = Screen:getWidth(),
|
||||
path = ".",
|
||||
path = lfs.currentdir(),
|
||||
parent = nil,
|
||||
show_hidden = false,
|
||||
filter = function(filename) return true end,
|
||||
|
||||
Reference in New Issue
Block a user