From 76897fac49bfcc2ed9e7d32894e688c27f17cade Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 17 Jul 2016 14:04:40 +0800 Subject: [PATCH] check new document settings path for updating progress --- ChangeLog.txt | 5 +++++ build-updates.sh | 2 +- .../github/chrox/kpvbooklet/KPVBooklet.java | 22 ++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9f3c78e..c97044e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,8 @@ +2016-07-17 13:53 chrox + + * check new document settings path for updating progress and possibly add + support for Kindle Oasis + 2016-04-23 21:06 chrox * add support for firmware version 5.7.4 diff --git a/build-updates.sh b/build-updates.sh index aefbe6b..6267b43 100755 --- a/build-updates.sh +++ b/build-updates.sh @@ -2,7 +2,7 @@ HACKNAME="kpvbooklet" PKGNAME="${HACKNAME}" -PKGVER="0.6.3" +PKGVER="0.6.4" # We need kindletool (https://github.com/NiLuJe/KindleTool) in $PATH if (( $(kindletool version | wc -l) == 1 )) ; then diff --git a/src/com/github/chrox/kpvbooklet/KPVBooklet.java b/src/com/github/chrox/kpvbooklet/KPVBooklet.java index 4b3064b..81b907c 100644 --- a/src/com/github/chrox/kpvbooklet/KPVBooklet.java +++ b/src/com/github/chrox/kpvbooklet/KPVBooklet.java @@ -228,13 +228,23 @@ public void run() { */ private float extractPercentFinished(String history_dir, String path) { float percent_finished = 0.0f; - int slash = path.lastIndexOf('/'); - String parentname = (slash == -1) ? "" : path.substring(0, slash+1); - String basename = (slash == -1) ? "" : path.substring(slash+1); - String histroypath = history_dir + "[" + parentname.replace('/','#') + "] " + basename + ".lua"; - log("I: found history file: " + histroypath); + int lastSlash = path.lastIndexOf('/'); + String parentname = (lastSlash == -1) ? "" : path.substring(0, lastSlash+1); + String filename = (lastSlash == -1) ? "" : path.substring(lastSlash+1); + int lastDot = filename.lastIndexOf('.'); + String basename = (lastDot == -1) ? "" : filename.substring(0, lastDot); + String extname = (lastDot == -1) ? "" : filename.substring(lastDot+1); + String histroyPath = history_dir + "[" + parentname.replace('/','#') + "] " + filename + ".lua"; + String metadataPath = parentname + basename + ".sdr/metadata." + extname + ".lua"; + File settingsFile = new File(metadataPath); + if (!settingsFile.exists()) { + settingsFile = new File(histroyPath); + } + + log("I: found document settings file: " + settingsFile.getPath()); try { - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(histroypath))); + BufferedReader br = new BufferedReader( + new InputStreamReader(new FileInputStream(settingsFile.getPath()))); String line; while ((line = br.readLine()) != null) { if (line.indexOf("[\"percent_finished\"]") > -1) {