Skip to content

Commit

Permalink
Fix encrypted doc support
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kammerer committed Jun 11, 2024
1 parent 40be22b commit 7aa1734
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
import com.artifex.mupdf.fitz.StructuredText;
import com.artifex.mupdf.fitz.android.AndroidDrawDevice;

import kotlin.jvm.Volatile;

public class MuPDFCore
{
public Document doc;
private Outline[] outline;

@Volatile
private int pageCount = -1;
private int currentPage;
private Page page;
Expand Down Expand Up @@ -231,7 +235,11 @@ public synchronized boolean needsPassword() {
}

public synchronized boolean authenticatePassword(String password) {
return doc.authenticatePassword(password);
boolean res = doc.authenticatePassword(password);
if (res) {
pageCount = doc.countPages();
}
return res;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import universe.constellation.orion.viewer.device.Device
import universe.constellation.orion.viewer.dialog.SearchDialog
import universe.constellation.orion.viewer.dialog.TapHelpDialog
import universe.constellation.orion.viewer.dialog.create
import universe.constellation.orion.viewer.document.Document
import universe.constellation.orion.viewer.layout.SimpleLayoutStrategy
import universe.constellation.orion.viewer.prefs.GlobalOptions
import universe.constellation.orion.viewer.prefs.initalizer
Expand Down Expand Up @@ -280,6 +281,14 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT
}

try {
if (!askPassword(newDocument)) {
showErrorOrFallbackPanel(
getString(R.string.crash_on_book_opening_encrypted),
intent
)
return@launch
}

if (newDocument.pageCount == 0) {
showErrorAndErrorPanel(
getString(R.string.crash_on_book_opening_title),
Expand All @@ -297,9 +306,6 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT
val layoutStrategy = SimpleLayoutStrategy.create()
val controller1 = Controller(this@OrionViewerActivity, newDocument, layoutStrategy, rootJob, context = executor)

if (!askPassword(controller1)) {
return@launch
}

val lastPageInfo1 = loadBookParameters(rootJob, file)
log("Read LastPageInfo for page ${lastPageInfo1.pageNumber}")
Expand Down Expand Up @@ -891,13 +897,13 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT
}
}

private suspend fun askPassword(controller: Controller): Boolean {
private suspend fun askPassword(controller: Document): Boolean {
if (controller.needPassword()) {
val view = layoutInflater.inflate(R.layout.password, null)
val builder = createThemedAlertBuilder()

builder.setView(view)
.setNegativeButton(R.string.string_cancel) { dialog, _ -> dialog.dismiss() }
.setNegativeButton(R.string.string_cancel) { dialog, _ -> dialog.cancel() }
.setPositiveButton(R.string.string_apply) { _, _ -> }


Expand All @@ -917,6 +923,7 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT
}
}
}

dialog.setOnCancelListener {
continuation.resume(false)
}
Expand Down
1 change: 1 addition & 0 deletions orion-viewer/src/main/res/values-ru/fileopen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="crash_on_intent_opening_title">Ошибка при обработке интента</string>
<string name="crash_on_book_opening_message_header">Ошибка при открытии \`%1$s\` файла. Пожалуйста, отправьте сообщение об ошибке:</string>
<string name="crash_on_book_opening_message_header_panel">Ошибка при открытии \`%1$s\` файла:</string>
<string name="crash_on_book_opening_encrypted">Зашифрованный документ</string>

<string name="string_send">Отправить…</string>
<string name="send_report_header">[Пожалуйста, укажите дополнительную информацию (как воспроизвести проблему)]</string>
Expand Down
2 changes: 2 additions & 0 deletions orion-viewer/src/main/res/values/fileopen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<string name="crash_on_book_opening_message_header">Error during file \`%1$s\` opening. Please report an issue:</string>
<string name="crash_on_book_opening_message_header_panel">Error during file \`%1$s\` opening:</string>

<string name="crash_on_book_opening_encrypted">Encrypted document</string>

<string name="string_send">Send…</string>
<string name="send_report_header">[Please provide additional details (steps to reproduce issue)]</string>

Expand Down

0 comments on commit 7aa1734

Please sign in to comment.