mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Wikpedia EPUBs: fix failure saving some files
Since 8815cbe0 and getSafeFilename() taking additional
parameters, and :gsub() returning multiple values,
filesystem type wasn't really checked and replacements
were not ensured, so saving articles like "Portal:Stuff"
failed on VFAT devices as ':' wasn't replaced.
This commit is contained in:
@@ -641,13 +641,14 @@ function ReaderLink:onGoToExternalLink(link_url)
|
||||
-- wikipedia page saved as epub, full of wikipedia links, it's
|
||||
-- too easy to click on links when wanting to change page...)
|
||||
-- But first check if this wikipedia article has been saved as EPUB
|
||||
local epub_filename = util.getSafeFilename(wiki_page:gsub("_", " ")) .. "."..string.upper(wiki_lang)..".epub"
|
||||
local epub_filename = wiki_page .. "."..string.upper(wiki_lang)..".epub"
|
||||
local epub_fullpath
|
||||
-- either in current book directory
|
||||
local last_file = G_reader_settings:readSetting("lastfile")
|
||||
if last_file then
|
||||
local current_book_dir = last_file:match("(.*)/")
|
||||
local epub_path = current_book_dir .. "/" .. epub_filename
|
||||
local safe_filename = util.getSafeFilename(epub_filename, current_book_dir):gsub("_", " ")
|
||||
local epub_path = current_book_dir .. "/" .. safe_filename
|
||||
if util.pathExists(epub_path) then
|
||||
epub_fullpath = epub_path
|
||||
end
|
||||
@@ -658,7 +659,8 @@ function ReaderLink:onGoToExternalLink(link_url)
|
||||
if not dir then dir = G_reader_settings:readSetting("home_dir") end
|
||||
if not dir then dir = require("apps/filemanager/filemanagerutil").getDefaultDir() end
|
||||
if dir then
|
||||
local epub_path = dir .. "/" .. epub_filename
|
||||
local safe_filename = util.getSafeFilename(epub_filename, dir):gsub("_", " ")
|
||||
local epub_path = dir .. "/" .. safe_filename
|
||||
if util.pathExists(epub_path) then
|
||||
epub_fullpath = epub_path
|
||||
end
|
||||
|
||||
@@ -355,10 +355,6 @@ function DictQuickLookup:update()
|
||||
-- if forced_lang was specified, it may not be in our wiki_languages,
|
||||
-- but ReaderWikipedia will have put it in result.lang
|
||||
local lang = self.lang or self.wiki_languages_copy[1]
|
||||
-- Just to be safe (none of the invalid chars, except ':' for uninteresting
|
||||
-- Portal: or File: wikipedia pages, should be in lookup_word)
|
||||
local cleaned_lookupword = util.getSafeFilename(self.lookupword:gsub("_", " "))
|
||||
local filename = cleaned_lookupword .. "."..string.upper(lang)..".epub"
|
||||
-- Find a directory to save file into
|
||||
local dir
|
||||
if G_reader_settings:isTrue("wikipedia_save_in_book_dir") and not self:isDocless() then
|
||||
@@ -376,6 +372,10 @@ function DictQuickLookup:update()
|
||||
})
|
||||
return
|
||||
end
|
||||
-- Just to be safe (none of the invalid chars, except ':' for uninteresting
|
||||
-- Portal: or File: wikipedia pages, should be in lookupword)
|
||||
local filename = self.lookupword .. "."..string.upper(lang)..".epub"
|
||||
filename = util.getSafeFilename(filename, dir):gsub("_", " ")
|
||||
local epub_path = dir .. "/" .. filename
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = T(_("Save as %1?"), BD.filename(filename)),
|
||||
|
||||
Reference in New Issue
Block a user