mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add support for password protected zip/cbz documents
This commit is contained in:
2
base
2
base
Submodule base updated: d0bed73cd6...d8403c0898
@@ -1,6 +1,7 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local DocSettings = require("docsettings")
|
||||
@@ -321,7 +322,13 @@ function ReaderUI:showReader(file)
|
||||
text = T( _("Opening file '%1'."), file),
|
||||
timeout = 0.1,
|
||||
})
|
||||
UIManager:scheduleIn(0.1, function() self:doShowReader(file) end)
|
||||
UIManager:scheduleIn(0.1, function()
|
||||
DEBUG("creating coroutine for showing reader")
|
||||
local co = coroutine.create(function()
|
||||
self:doShowReader(file)
|
||||
end)
|
||||
coroutine.resume(co)
|
||||
end)
|
||||
end
|
||||
|
||||
local running_instance = nil
|
||||
@@ -338,6 +345,17 @@ function ReaderUI:doShowReader(file)
|
||||
})
|
||||
return
|
||||
end
|
||||
if document.is_locked then
|
||||
DEBUG("document is locked")
|
||||
self._coroutine = coroutine.running() or self._coroutine
|
||||
self:unlockDocumentWithPassword(document)
|
||||
if coroutine.running() then
|
||||
local unlock_success = coroutine.yield()
|
||||
if not unlock_success then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
G_reader_settings:saveSetting("lastfile", file)
|
||||
local reader = ReaderUI:new{
|
||||
@@ -348,6 +366,54 @@ function ReaderUI:doShowReader(file)
|
||||
running_instance = reader
|
||||
end
|
||||
|
||||
function ReaderUI:unlockDocumentWithPassword(document, try_again)
|
||||
DEBUG("show input password dialog")
|
||||
self.password_dialog = InputDialog:new{
|
||||
title = try_again and _("Password is incorrect, try again?")
|
||||
or _("Input document password"),
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Cancel"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
self:closeDialog()
|
||||
coroutine.resume(self._coroutine)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("OK"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
local success = self:onVerifyPassword(document)
|
||||
self:closeDialog()
|
||||
if success then
|
||||
coroutine.resume(self._coroutine, success)
|
||||
else
|
||||
self:unlockDocumentWithPassword(document, true)
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
text_type = "password",
|
||||
width = Screen:getWidth() * 0.8,
|
||||
height = Screen:getHeight() * 0.2,
|
||||
}
|
||||
self.password_dialog:onShowKeyboard()
|
||||
UIManager:show(self.password_dialog)
|
||||
end
|
||||
|
||||
function ReaderUI:onVerifyPassword(document)
|
||||
local password = self.password_dialog:getInputText()
|
||||
return document:unlock(password)
|
||||
end
|
||||
|
||||
function ReaderUI:closeDialog()
|
||||
self.password_dialog:onClose()
|
||||
UIManager:close(self.password_dialog)
|
||||
end
|
||||
|
||||
function ReaderUI:onSetDimensions(dimen)
|
||||
self.dimen = dimen
|
||||
end
|
||||
|
||||
@@ -32,17 +32,17 @@ function PdfDocument:init()
|
||||
self:_readMetadata()
|
||||
end
|
||||
if not (self.info.number_of_pages > 0) then
|
||||
error("No page found in PDF file")
|
||||
--error("No page found in PDF file")
|
||||
end
|
||||
end
|
||||
|
||||
function PdfDocument:unlock(password)
|
||||
if not self._document:authenticatePassword(password) then
|
||||
self._document:close()
|
||||
return false, "wrong password"
|
||||
return false
|
||||
end
|
||||
self.is_locked = false
|
||||
return self:_readMetadata()
|
||||
self:_readMetadata()
|
||||
return true
|
||||
end
|
||||
|
||||
function PdfDocument:getPageTextBoxes(pageno)
|
||||
|
||||
@@ -60,6 +60,7 @@ function InputDialog:init()
|
||||
face = self.input_face,
|
||||
width = self.width * 0.9,
|
||||
input_type = self.input_type,
|
||||
text_type = self.text_type,
|
||||
enter_callback = self.enter_callback,
|
||||
scroll = false,
|
||||
parent = self,
|
||||
|
||||
Reference in New Issue
Block a user