2017-07-01 10:11:44 +00:00
|
|
|
--[[--
|
|
|
|
This module contains miscellaneous helper functions for FileManager
|
|
|
|
]]
|
|
|
|
|
|
|
|
local Device = require("device")
|
2017-09-22 16:24:38 +00:00
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
local util = require("ffi/util")
|
2019-10-21 12:24:29 +00:00
|
|
|
local _ = require("gettext")
|
2017-07-01 10:11:44 +00:00
|
|
|
|
|
|
|
local filemanagerutil = {}
|
|
|
|
|
|
|
|
function filemanagerutil.getDefaultDir()
|
2020-06-19 07:41:50 +00:00
|
|
|
return Device.home_dir or "."
|
2017-07-01 10:11:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function filemanagerutil.abbreviate(path)
|
2018-07-28 18:44:55 +00:00
|
|
|
if not path then return "" end
|
2019-10-21 12:24:29 +00:00
|
|
|
if G_reader_settings:nilOrTrue("shorten_home_dir") then
|
2017-07-01 10:11:44 +00:00
|
|
|
local home_dir = G_reader_settings:readSetting("home_dir") or filemanagerutil.getDefaultDir()
|
2019-10-21 12:24:29 +00:00
|
|
|
if path == home_dir then
|
|
|
|
return _("Home")
|
|
|
|
end
|
2017-07-01 10:11:44 +00:00
|
|
|
local len = home_dir:len()
|
|
|
|
local start = path:sub(1, len)
|
2019-11-19 20:06:03 +00:00
|
|
|
if start == home_dir and path:sub(len+1, len+1) == "/" then
|
2019-10-21 12:24:29 +00:00
|
|
|
return path:sub(len+2)
|
2017-07-01 10:11:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return path
|
|
|
|
end
|
|
|
|
|
2021-11-07 18:29:53 +00:00
|
|
|
-- Purge doc settings in sidecar directory
|
2017-09-22 16:24:38 +00:00
|
|
|
function filemanagerutil.purgeSettings(file)
|
|
|
|
local file_abs_path = util.realpath(file)
|
|
|
|
if file_abs_path then
|
2021-10-21 20:43:05 +00:00
|
|
|
DocSettings:open(file_abs_path):purge()
|
2017-09-22 16:24:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-07 18:29:53 +00:00
|
|
|
-- Purge doc settings except kept
|
|
|
|
function filemanagerutil.resetDocumentSettings(file)
|
|
|
|
local settings_to_keep = {
|
|
|
|
bookmarks = true,
|
|
|
|
bookmarks_sorted = true,
|
2022-02-10 10:08:51 +00:00
|
|
|
bookmarks_sorted_20220106 = true,
|
2021-11-07 18:29:53 +00:00
|
|
|
bookmarks_version = true,
|
|
|
|
cre_dom_version = true,
|
|
|
|
highlight = true,
|
|
|
|
highlights_imported = true,
|
|
|
|
last_page = true,
|
|
|
|
last_xpointer = true,
|
|
|
|
}
|
|
|
|
local file_abs_path = util.realpath(file)
|
|
|
|
if file_abs_path then
|
|
|
|
local doc_settings = DocSettings:open(file_abs_path)
|
|
|
|
for k in pairs(doc_settings.data) do
|
|
|
|
if not settings_to_keep[k] then
|
|
|
|
doc_settings:delSetting(k)
|
|
|
|
end
|
|
|
|
end
|
2022-02-10 10:08:51 +00:00
|
|
|
doc_settings:makeTrue("docsettings_reset_done") -- for readertypeset block_rendering_mode
|
2021-11-07 18:29:53 +00:00
|
|
|
doc_settings:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-01 10:11:44 +00:00
|
|
|
return filemanagerutil
|