From 7d4d5d9d848ade93793e23e1d8bbcec0ef7e262b Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 29 Nov 2014 13:30:02 +0800 Subject: [PATCH] run koreader script with superuser on firmware 5.6.1 --- ChangeLog.txt | 4 + build-updates.sh | 2 +- mimes.install.sql | 166 +++++++++--------- .../github/chrox/kpvbooklet/KPVBooklet.java | 67 ++++--- 4 files changed, 128 insertions(+), 111 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 3d2fe02..89bc817 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +2014-11-27 20:32 chrox + + * add support for firmware version 5.6.1 + 2014-11-21 10:32 chrox * add support for Kindle Basic & Voyage diff --git a/build-updates.sh b/build-updates.sh index 11df841..7baf5bd 100755 --- a/build-updates.sh +++ b/build-updates.sh @@ -2,7 +2,7 @@ HACKNAME="kpvbooklet" PKGNAME="${HACKNAME}" -PKGVER="0.5.7" +PKGVER="0.5.8" # We need kindletool (https://github.com/NiLuJe/KindleTool) in $PATH if (( $(kindletool version | wc -l) == 1 )) ; then diff --git a/mimes.install.sql b/mimes.install.sql index bf67887..dfa94b7 100644 --- a/mimes.install.sql +++ b/mimes.install.sql @@ -1,84 +1,84 @@ -INSERT INTO "handlerIds" VALUES('com.github.koreader.kpvbooklet'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','lipcId','com.github.koreader.kpvbooklet'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','jar','/opt/amazon/ebook/booklet/KPVBooklet.jar'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','detailFactoryPath','/opt/amazon/ebook/lib/detail_view.jar'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','detailFactoryClass','com.amazon.ebook.booklet.reader.impl.detail.ReaderDetailViewFactory'); - -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','maxGoTime','0'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','maxPauseTime','60'); - -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','default-chrome-style','NH'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','extend-start','Y'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','searchbar-mode','transient'); -INSERT INTO "properties" VALUES('com.github.koreader.kpvbooklet','supportedOrientation','URL'); - -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','detail','MT:application/octet-stream','true'); - -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/pdf','true'); - -INSERT INTO "mimetypes" VALUES('djvu','MT:image/x.djvu'); -INSERT INTO "extenstions" VALUES('djvu','MT:image/x.djvu'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','image/x.djvu','DjVu'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.djvu','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:image/x.djvu','true'); - -INSERT INTO "mimetypes" VALUES('epub','MT:application/epub+zip'); -INSERT INTO "extenstions" VALUES('epub','MT:application/epub+zip'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/epub+zip','EPUB'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.epub','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/epub+zip','true'); - -INSERT INTO "mimetypes" VALUES('cbz','MT:application/cbz'); -INSERT INTO "extenstions" VALUES('cbz','MT:application/cbz'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/cbz','CBZ'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.cbz','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/cbz','true'); - -INSERT INTO "mimetypes" VALUES('chm','MT:application/chm'); -INSERT INTO "extenstions" VALUES('chm','MT:application/chm'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/chm','CHM'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.chm','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/chm','true'); - -INSERT INTO "mimetypes" VALUES('doc','MT:application/doc'); -INSERT INTO "extenstions" VALUES('doc','MT:application/doc'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/doc','DOC'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.doc','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/doc','true'); - -INSERT INTO "mimetypes" VALUES('fb2','MT:application/fb2'); -INSERT INTO "extenstions" VALUES('fb2','MT:application/fb2'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/fb2','FB2'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.fb2','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/fb2','true'); - -INSERT INTO "mimetypes" VALUES('pdb','MT:application/pdb'); -INSERT INTO "extenstions" VALUES('pdb','MT:application/pdb'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/pdb','PDB'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.pdb','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/pdb','true'); - -INSERT INTO "mimetypes" VALUES('rtf','MT:application/rtf'); -INSERT INTO "extenstions" VALUES('rtf','MT:application/rtf'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/rtf','RTF'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.rtf','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/rtf','true'); - -INSERT INTO "mimetypes" VALUES('tcr','MT:application/tcr'); -INSERT INTO "extenstions" VALUES('tcr','MT:application/tcr'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/tcr','TCR'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.tcr','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/tcr','true'); - -INSERT INTO "mimetypes" VALUES('xps','MT:application/xps'); -INSERT INTO "extenstions" VALUES('xps','MT:application/xps'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/xps','XPS'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.xps','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/xps','true'); - -INSERT INTO "mimetypes" VALUES('zip','MT:application/zip'); -INSERT INTO "extenstions" VALUES('zip','MT:application/zip'); -INSERT INTO "properties" VALUES('archive.displaytags.mimetypes','application/zip','ZIP'); -INSERT INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.zip','true'); -INSERT INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/zip','true'); +INSERT OR IGNORE INTO "handlerIds" VALUES('com.github.koreader.kpvbooklet'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','lipcId','com.github.koreader.kpvbooklet'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','jar','/opt/amazon/ebook/booklet/KPVBooklet.jar'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','detailFactoryPath','/opt/amazon/ebook/lib/detail_view.jar'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','detailFactoryClass','com.amazon.ebook.booklet.reader.impl.detail.ReaderDetailViewFactory'); + +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','maxGoTime','0'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','maxPauseTime','60'); + +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','default-chrome-style','NH'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','extend-start','Y'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','searchbar-mode','transient'); +INSERT OR IGNORE INTO "properties" VALUES('com.github.koreader.kpvbooklet','supportedOrientation','URL'); + +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','detail','MT:application/octet-stream','true'); + +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/pdf','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('djvu','MT:image/x.djvu'); +INSERT OR IGNORE INTO "extenstions" VALUES('djvu','MT:image/x.djvu'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','image/x.djvu','DjVu'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.djvu','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:image/x.djvu','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('epub','MT:application/epub+zip'); +INSERT OR IGNORE INTO "extenstions" VALUES('epub','MT:application/epub+zip'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/epub+zip','EPUB'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.epub','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/epub+zip','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('cbz','MT:application/cbz'); +INSERT OR IGNORE INTO "extenstions" VALUES('cbz','MT:application/cbz'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/cbz','CBZ'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.cbz','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/cbz','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('chm','MT:application/chm'); +INSERT OR IGNORE INTO "extenstions" VALUES('chm','MT:application/chm'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/chm','CHM'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.chm','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/chm','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('doc','MT:application/doc'); +INSERT OR IGNORE INTO "extenstions" VALUES('doc','MT:application/doc'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/doc','DOC'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.doc','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/doc','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('fb2','MT:application/fb2'); +INSERT OR IGNORE INTO "extenstions" VALUES('fb2','MT:application/fb2'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/fb2','FB2'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.fb2','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/fb2','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('pdb','MT:application/pdb'); +INSERT OR IGNORE INTO "extenstions" VALUES('pdb','MT:application/pdb'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/pdb','PDB'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.pdb','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/pdb','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('rtf','MT:application/rtf'); +INSERT OR IGNORE INTO "extenstions" VALUES('rtf','MT:application/rtf'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/rtf','RTF'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.rtf','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/rtf','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('tcr','MT:application/tcr'); +INSERT OR IGNORE INTO "extenstions" VALUES('tcr','MT:application/tcr'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/tcr','TCR'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.tcr','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/tcr','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('xps','MT:application/xps'); +INSERT OR IGNORE INTO "extenstions" VALUES('xps','MT:application/xps'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/xps','XPS'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.xps','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/xps','true'); + +INSERT OR IGNORE INTO "mimetypes" VALUES('zip','MT:application/zip'); +INSERT OR IGNORE INTO "extenstions" VALUES('zip','MT:application/zip'); +INSERT OR IGNORE INTO "properties" VALUES('archive.displaytags.mimetypes','application/zip','ZIP'); +INSERT OR IGNORE INTO "associations" VALUES('com.lab126.generic.extractor','extractor','GL:*.zip','true'); +INSERT OR IGNORE INTO "associations" VALUES('com.github.koreader.kpvbooklet','application','MT:application/zip','true'); diff --git a/src/com/github/chrox/kpvbooklet/KPVBooklet.java b/src/com/github/chrox/kpvbooklet/KPVBooklet.java index 3d5f5ec..459507d 100644 --- a/src/com/github/chrox/kpvbooklet/KPVBooklet.java +++ b/src/com/github/chrox/kpvbooklet/KPVBooklet.java @@ -4,7 +4,6 @@ import java.net.URI; import java.lang.reflect.Field; import java.io.PrintStream; -import java.io.File; import com.github.chrox.kpvbooklet.ccadapter.CCAdapter; import com.github.chrox.kpvbooklet.util.Log; @@ -27,7 +26,7 @@ class BookletTimer { private static final String timersource = "com.github.koreader.kpvbooklet.timer"; private static final PrintStream logger = Log.INSTANCE; private static int counter = 0; - + private static class TimerProperties extends LipcPropertyAdapter { public int getIntProperty(String property) throws LipcException { if(property.equals("count")) { @@ -46,15 +45,15 @@ public void setProperty(String property, int val) throws LipcException { } } } - + public static int getCounter() { return counter; } - + public static void addCounter(int count) { counter += count; } - + public static void addBookletCounter() { try { LipcSource source = LipcService.getInstance().createSource(timersource); @@ -63,7 +62,7 @@ public static void addBookletCounter() { source.exportIntProperty("add", timerproperty, 2); source.exportIntProperty("set", timerproperty, 2); source.exportIntProperty("reset", timerproperty, 2); - + } catch(LipcException e) { logger.println("E: " + e.toString()); e.printStackTrace(logger); @@ -73,9 +72,9 @@ public static void addBookletCounter() { /** * A booklet for launching koreader directly from Kindle home screen. - * + * * Modified by chrox@github. - * + * * @author Patric Mueller <bhaak@gmx.net> */ public class KPVBooklet extends ReaderBooklet { @@ -86,18 +85,30 @@ public class KPVBooklet extends ReaderBooklet { private final String kpv_history = "/mnt/us/kindlepdfviewer/history/"; private final String gandalf = "/var/local/mkk/gandalf"; private final String su = "/var/local/mkk/su"; - + private static String PRIVILEGE_HINT_PREFIX = "?"; + private Process readerProcess; private String history_dir; private CCAdapter ccrequest = CCAdapter.INSTANCE; private static final PrintStream logger = Log.INSTANCE; - + public KPVBooklet() { + // Check current privileges... + String currentUsername = System.getProperty("user.name"); + if ("root".equals(currentUsername)) { + PRIVILEGE_HINT_PREFIX = "#"; + } else { + if (new File(gandalf).exists()) { + PRIVILEGE_HINT_PREFIX = "$"; + } else { + PRIVILEGE_HINT_PREFIX = "%"; + } + } log("I: KPVBooklet"); BookletTimer.addBookletCounter(); } - - public void start(URI contentURI) { + + public void start(URI contentURI) { log("I: start()"); log("I: kpvbooklet launching times " + BookletTimer.getCounter()); log("I: contentURI " + contentURI.toString()); @@ -112,10 +123,12 @@ public void start(URI contentURI) { } } log("I: Opening " + path + " with koreader..."); - if (new File(gandalf).exists()) { - String[] cmd = new String[] {su, "-s", "/bin/ash", "-c", koreader + " \"" + path + "\""}; + String[] cmd; + if ("$".equals(PRIVILEGE_HINT_PREFIX)) { + log("I: Call Gandalf for help..."); + cmd = new String[] {su, "-s", "/bin/ash", "-c", koreader + " \"" + path + "\""}; } else { - String[] cmd = new String[] {koreader, path}; + cmd = new String[] {"/bin/sh", koreader, path}; } try { readerProcess = Runtime.getRuntime().exec(cmd); @@ -127,7 +140,7 @@ public void start(URI contentURI) { // fallback to kpdf.sh if we cannot exec koreader.sh if (readerProcess == null) { log("I: Opening " + path + " with kindlepdfviewer..."); - cmd[0] = kpdfview; + cmd[cmd.length - 2] = kpdfview; history_dir = kpv_history; try { readerProcess = Runtime.getRuntime().exec(cmd); @@ -135,7 +148,7 @@ public void start(URI contentURI) { log("E: " + e.toString()); } } - + Thread thread = new ReaderWaitThread(history_dir, path); thread.start(); } @@ -154,10 +167,10 @@ public void stop() { } super.stop(); } - - /** + + /** * Send a QUIT signal to a process. - * + * * See http://stackoverflow.com/questions/2950338/how-can-i-kill-a-linux-process-in-java-with-sigkill-process-destroy-does-sigte#answer-2951193 */ private void killQuitProcess(Process process) @@ -173,13 +186,13 @@ private void killQuitProcess(Process process) throw new IllegalArgumentException("Needs to be a UNIXProcess"); } } - - /** This thread waits for reader process to finish and then update content catalog + + /** This thread waits for reader process to finish and then update content catalog */ class ReaderWaitThread extends Thread { private String history_dir = ""; private String content_path = ""; - + public ReaderWaitThread(String dir, String path) { history_dir = dir; content_path = path; @@ -191,14 +204,14 @@ public void run() { } catch (InterruptedException e) { log("E: " + e.toString()); } - + try { // update content catlog after reader exits ccrequest.updateCC(content_path, extractPercentFinished(history_dir, content_path)); } catch (Exception e) { log("E: " + e.toString()); } - + // send backward lipc event after reader exits try { Runtime.getRuntime().exec("lipc-set-prop com.lab126.appmgrd backward 0"); @@ -207,7 +220,7 @@ public void run() { } } } - + /** * Extract last_percent in document history file * @param file path @@ -241,7 +254,7 @@ private float extractPercentFinished(String history_dir, String path) { } return percent_finished; } - + private void log(String msg) { logger.println(msg); }