diff --git a/jni/Android.mk b/jni/Android.mk index 21315c3d9..b6e3c084c 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -142,7 +142,8 @@ LOCAL_SRC_FILES := \ NativeFormats/fbreader/src/library/Book.cpp \ NativeFormats/fbreader/src/library/Comparators.cpp \ NativeFormats/fbreader/src/library/Library.cpp \ - NativeFormats/fbreader/src/library/Tag.cpp + NativeFormats/fbreader/src/library/Tag.cpp \ + NativeFormats/fbreader/src/library/UID.cpp LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/NativeFormats/util \ diff --git a/jni/NativeFormats/JavaNativeFormatPlugin.cpp b/jni/NativeFormats/JavaNativeFormatPlugin.cpp index 1c56aa8d4..b8bb85255 100644 --- a/jni/NativeFormats/JavaNativeFormatPlugin.cpp +++ b/jni/NativeFormats/JavaNativeFormatPlugin.cpp @@ -27,6 +27,7 @@ #include "fbreader/src/library/Author.h" #include "fbreader/src/library/Book.h" #include "fbreader/src/library/Tag.h" +#include "fbreader/src/library/UID.h" static shared_ptr findCppPlugin(jobject base) { const std::string fileType = AndroidUtil::Method_NativeFormatPlugin_supportedFileType->callForCppString(base); @@ -37,6 +38,17 @@ static shared_ptr findCppPlugin(jobject base) { return plugin; } +static void fillUids(JNIEnv* env, jobject javaBook, Book &book) { + const UIDList &uids = book.uids(); + for (UIDList::const_iterator it = uids.begin(); it != uids.end(); ++it) { + jstring type = AndroidUtil::createJavaString(env, (*it)->Type); + jstring id = AndroidUtil::createJavaString(env, (*it)->Id); + AndroidUtil::Method_Book_addUid->call(javaBook, type, id); + env->DeleteLocalRef(id); + env->DeleteLocalRef(type); + } +} + static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) { jstring javaString; @@ -81,6 +93,8 @@ static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) { const Tag &tag = *tags[i]; AndroidUtil::Method_Book_addTag->call(javaBook, tag.javaTag(env)); } + + fillUids(env, javaBook, book); } static void fillLanguageAndEncoding(JNIEnv* env, jobject javaBook, Book &book) { @@ -116,6 +130,19 @@ JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPl return JNI_TRUE; } +extern "C" +JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readUidsNative(JNIEnv* env, jobject thiz, jobject javaBook) { + shared_ptr plugin = findCppPlugin(thiz); + if (plugin.isNull()) { + return; + } + + shared_ptr book = Book::loadFromJavaBook(env, javaBook); + + plugin->readUids(*book); + fillUids(env, javaBook, *book); +} + extern "C" JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_detectLanguageAndEncodingNative(JNIEnv* env, jobject thiz, jobject javaBook) { shared_ptr plugin = findCppPlugin(thiz); diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h index bf5fc5240..ba58243b6 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h @@ -58,6 +58,7 @@ public: virtual const std::string &tryOpen(const ZLFile &file) const; virtual bool readMetaInfo(Book &book) const = 0; + virtual bool readUids(Book &book) const = 0; virtual bool readLanguageAndEncoding(Book &book) const = 0; virtual bool readModel(BookModel &model) const = 0; virtual shared_ptr coverImage(const ZLFile &file) const; diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp index 3a8a9aef8..717c7ed6e 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp @@ -62,6 +62,10 @@ bool DocPlugin::readMetaInfo(Book &book) const { return true; } +bool DocPlugin::readUids(Book&) const { + return false; +} + bool DocPlugin::readLanguageAndEncoding(Book &/*book*/) const { return true; } diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.h b/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.h index 65f97c29f..102a8b55f 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.h @@ -32,6 +32,7 @@ public: const std::string supportedFileType() const; bool acceptsFile(const ZLFile &file) const; bool readMetaInfo(Book &book) const; + bool readUids(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; }; diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h b/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h index 785196599..746efdf7a 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2Plugin.h @@ -30,6 +30,7 @@ public: bool providesMetaInfo() const; const std::string supportedFileType() const; bool readMetaInfo(Book &book) const; + bool readUids(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; shared_ptr coverImage(const ZLFile &file) const; diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.cpp index 4e3bdb013..82b079a98 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.cpp @@ -50,6 +50,10 @@ bool HtmlPlugin::readMetaInfo(Book &book) const { return true; } +bool HtmlPlugin::readUids(Book&) const { + return false; +} + bool HtmlPlugin::readModel(BookModel &model) const { const Book& book = *model.book(); const ZLFile &file = book.file(); diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.h b/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.h index ef6bc25cb..1e31e405c 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlPlugin.h @@ -30,6 +30,7 @@ public: bool providesMetaInfo() const; const std::string supportedFileType() const; bool readMetaInfo(Book &book) const; + bool readUids(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; // FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file); diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h index d462d8275..0e4de6524 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h @@ -32,6 +32,7 @@ public: bool providesMetaInfo() const; const std::string supportedFileType() const; bool readMetaInfo(Book &book) const; + bool readUids(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; shared_ptr coverImage(const ZLFile &file) const; diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.cpp index f5eac05ad..a778056ef 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.cpp @@ -54,6 +54,10 @@ bool RtfPlugin::readMetaInfo(Book &book) const { return true; } +bool RtfPlugin::readUids(Book&) const { + return false; +} + bool RtfPlugin::readModel(BookModel &model) const { const Book &book = *model.book(); return RtfBookReader(model, book.encoding()).readDocument(book.file()); diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.h b/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.h index 7a83a179f..bcc2203ea 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfPlugin.h @@ -28,6 +28,7 @@ public: bool providesMetaInfo() const; const std::string supportedFileType() const; bool readMetaInfo(Book &book) const; + bool readUids(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; }; diff --git a/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.cpp index 9626e7ee5..ed4cbdcc4 100644 --- a/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.cpp @@ -38,10 +38,14 @@ const std::string TxtPlugin::supportedFileType() const { return "plain text"; } -bool TxtPlugin::readMetaInfo(Book &book) const { +bool TxtPlugin::readMetaInfo(Book&) const { return true; } +bool TxtPlugin::readUids(Book&) const { + return false; +} + bool TxtPlugin::readModel(BookModel &model) const { Book &book = *model.book(); const ZLFile &file = book.file(); diff --git a/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.h b/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.h index 50834f88b..1ea91ecd9 100644 --- a/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/txt/TxtPlugin.h @@ -29,6 +29,7 @@ public: bool providesMetaInfo() const; const std::string supportedFileType() const; bool readMetaInfo(Book &book) const; + bool readUids(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; // FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file); diff --git a/jni/NativeFormats/fbreader/src/library/Book.cpp b/jni/NativeFormats/fbreader/src/library/Book.cpp index 54773aa07..bc9a2a7bc 100644 --- a/jni/NativeFormats/fbreader/src/library/Book.cpp +++ b/jni/NativeFormats/fbreader/src/library/Book.cpp @@ -30,6 +30,7 @@ #include "Book.h" #include "Author.h" #include "Tag.h" +#include "UID.h" #include "../formats/FormatPlugin.h" //#include "../migration/BookInfo.h" diff --git a/jni/NativeFormats/fbreader/src/library/Book.h b/jni/NativeFormats/fbreader/src/library/Book.h index 13cd97753..661c52e91 100644 --- a/jni/NativeFormats/fbreader/src/library/Book.h +++ b/jni/NativeFormats/fbreader/src/library/Book.h @@ -30,9 +30,6 @@ #include "Lists.h" -class Author; -class Tag; - class Book { public: @@ -70,6 +67,7 @@ public: // unmodifiable book methods const TagList &tags() const; const AuthorList &authors() const; + const UIDList &uids() const; public: // modifiable book methods void setTitle(const std::string &title); @@ -105,6 +103,7 @@ private: std::string myIndexInSeries; TagList myTags; AuthorList myAuthors; + UIDList myUIDs; private: // disable copying Book(const Book &); @@ -138,6 +137,7 @@ inline const std::string &Book::indexInSeries() const { return myIndexInSeries; inline const TagList &Book::tags() const { return myTags; } inline const AuthorList &Book::authors() const { return myAuthors; } +inline const UIDList &Book::uids() const { return myUIDs; } inline int Book::bookId() const { return myBookId; } inline void Book::setBookId(int bookId) { myBookId = bookId; } diff --git a/jni/NativeFormats/fbreader/src/library/Lists.h b/jni/NativeFormats/fbreader/src/library/Lists.h index c4256d4ec..5803a801a 100644 --- a/jni/NativeFormats/fbreader/src/library/Lists.h +++ b/jni/NativeFormats/fbreader/src/library/Lists.h @@ -28,6 +28,7 @@ class Book; class Author; class Tag; +class UID; class BookByFileNameComparator; typedef std::vector > BookList; @@ -35,5 +36,6 @@ typedef std::set,BookByFileNameComparator> BookSet; typedef std::vector > AuthorList; typedef std::vector > TagList; typedef std::set > TagSet; +typedef std::vector > UIDList; #endif /* __LISTS_H__ */ diff --git a/jni/NativeFormats/fbreader/src/library/UID.cpp b/jni/NativeFormats/fbreader/src/library/UID.cpp new file mode 100644 index 000000000..ba59ba4a5 --- /dev/null +++ b/jni/NativeFormats/fbreader/src/library/UID.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2009-2013 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "UID.h" diff --git a/jni/NativeFormats/fbreader/src/library/UID.h b/jni/NativeFormats/fbreader/src/library/UID.h new file mode 100644 index 000000000..f8ff25074 --- /dev/null +++ b/jni/NativeFormats/fbreader/src/library/UID.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2009-2013 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __UID_H__ +#define __UID_H__ + +#include + +#include "Lists.h" + +class UID { + +public: + UID(const std::string &type, const std::string &id); + bool operator == (const UID &uid) const; + bool operator != (const UID &uid) const; + +public: + const std::string Type; + const std::string Id; +}; + +#endif /* __UID_H__ */ diff --git a/jni/NativeFormats/util/AndroidUtil.cpp b/jni/NativeFormats/util/AndroidUtil.cpp index 031f92d2c..b16213806 100644 --- a/jni/NativeFormats/util/AndroidUtil.cpp +++ b/jni/NativeFormats/util/AndroidUtil.cpp @@ -104,6 +104,7 @@ shared_ptr AndroidUtil::Method_Book_setLanguage; shared_ptr AndroidUtil::Method_Book_setEncoding; shared_ptr AndroidUtil::Method_Book_addAuthor; shared_ptr AndroidUtil::Method_Book_addTag; +shared_ptr AndroidUtil::Method_Book_addUid; shared_ptr AndroidUtil::StaticMethod_Tag_getTag; @@ -179,6 +180,7 @@ bool AndroidUtil::init(JavaVM* jvm) { Method_Book_setEncoding = new VoidMethod(Class_Book, "setEncoding", "(Ljava/lang/String;)"); Method_Book_addAuthor = new VoidMethod(Class_Book, "addAuthor", "(Ljava/lang/String;Ljava/lang/String;)"); Method_Book_addTag = new VoidMethod(Class_Book, "addTag", "(Lorg/geometerplus/fbreader/book/Tag;)"); + Method_Book_addTag = new VoidMethod(Class_Book, "addUid", "(Ljava/lang/String;Ljava/lang/String;)"); StaticMethod_Tag_getTag = new StaticObjectMethod(Class_Tag, "getTag", Class_Tag, "(Lorg/geometerplus/fbreader/book/Tag;Ljava/lang/String;)"); diff --git a/jni/NativeFormats/util/AndroidUtil.h b/jni/NativeFormats/util/AndroidUtil.h index 9ee984dca..955b23f8a 100644 --- a/jni/NativeFormats/util/AndroidUtil.h +++ b/jni/NativeFormats/util/AndroidUtil.h @@ -126,6 +126,7 @@ public: static shared_ptr Method_Book_setEncoding; static shared_ptr Method_Book_addAuthor; static shared_ptr Method_Book_addTag; + static shared_ptr Method_Book_addUid; static shared_ptr StaticMethod_Tag_getTag; diff --git a/proguard.cfg b/proguard.cfg index dfc5e5632..ccc0a7e6e 100755 --- a/proguard.cfg +++ b/proguard.cfg @@ -80,6 +80,7 @@ public void setEncoding(**); public void addAuthor(**,**); public void addTag(**); + public void addUid(**); } -keep class org.geometerplus.fbreader.book.Tag -keepclassmembers class org.geometerplus.fbreader.book.Tag { diff --git a/src/org/geometerplus/android/fbreader/libraryService/SQLiteBooksDatabase.java b/src/org/geometerplus/android/fbreader/libraryService/SQLiteBooksDatabase.java index baa87437e..1b973afce 100644 --- a/src/org/geometerplus/android/fbreader/libraryService/SQLiteBooksDatabase.java +++ b/src/org/geometerplus/android/fbreader/libraryService/SQLiteBooksDatabase.java @@ -77,7 +77,7 @@ final class SQLiteBooksDatabase extends BooksDatabase { private void migrate() { final int version = myDatabase.getVersion(); - final int currentVersion = 21; + final int currentVersion = 22; if (version >= currentVersion) { return; } @@ -127,6 +127,8 @@ final class SQLiteBooksDatabase extends BooksDatabase { updateTables19(); case 20: updateTables20(); + case 21: + updateTables21(); } myDatabase.setTransactionSuccessful(); myDatabase.setVersion(currentVersion); @@ -482,15 +484,15 @@ final class SQLiteBooksDatabase extends BooksDatabase { protected void saveBookUid(long bookId, UID uid) { if (myInsertBookUidStatement == null) { myInsertBookUidStatement = myDatabase.compileStatement( - "INSERT OR REPLACE INTO BookUid (book_id,type,uid) VALUES (?,?,?)" + "INSERT OR IGNORE INTO BookUid (book_id,type,uid) VALUES (?,?,?)" ); } synchronized (myInsertBookUidStatement) { myInsertBookUidStatement.bindLong(1, bookId); myInsertBookUidStatement.bindString(2, uid.Type); - myInsertBookUidStatement.bindString(2, uid.Id); - myInsertBookAuthorStatement.execute(); + myInsertBookUidStatement.bindString(3, uid.Id); + myInsertBookUidStatement.execute(); } } @@ -1373,11 +1375,6 @@ final class SQLiteBooksDatabase extends BooksDatabase { } private void updateTables20() { - myDatabase.execSQL( - "CREATE TABLE IF NOT EXISTS BookUid(" + - "book_id INTEGER NOT NULL UNIQUE REFERENCES Books(book_id)," + - "type TEXT NOT NULL," + - "uid TEXT NOT NULL)"); myDatabase.execSQL( "CREATE TABLE IF NOT EXISTS Labels(" + "label_id INTEGER PRIMARY KEY," + @@ -1394,4 +1391,14 @@ final class SQLiteBooksDatabase extends BooksDatabase { myDatabase.execSQL("INSERT INTO BookLabel (label_id,book_id) SELECT " + id + ",book_id FROM Favorites"); myDatabase.execSQL("DROP TABLE Favorites"); } + + private void updateTables21() { + myDatabase.execSQL("DROP TABLE BookUid"); + myDatabase.execSQL( + "CREATE TABLE IF NOT EXISTS BookUid(" + + "book_id INTEGER NOT NULL UNIQUE REFERENCES Books(book_id)," + + "type TEXT NOT NULL," + + "uid TEXT NOT NULL," + + "CONSTRAINT BookUid_Unique(book_id,type,uid))"); + } } diff --git a/src/org/geometerplus/fbreader/book/Book.java b/src/org/geometerplus/fbreader/book/Book.java index 939ba4e6d..263d396f1 100644 --- a/src/org/geometerplus/fbreader/book/Book.java +++ b/src/org/geometerplus/fbreader/book/Book.java @@ -115,10 +115,14 @@ public class Book extends TitledEntity { myAuthors = null; myTags = null; mySeriesInfo = null; + myUids = null; myIsSaved = false; plugin.readMetaInfo(this); + if (myUids == null || myUids.isEmpty()) { + plugin.readUids(this); + } if (isTitleEmpty()) { final String fileName = File.getShortName(); @@ -139,6 +143,16 @@ public class Book extends TitledEntity { mySeriesInfo = database.getSeriesInfo(myId); myUids = database.listUids(myId); myIsSaved = true; + if (myUids == null || myUids.isEmpty()) { + try { + final FormatPlugin plugin = getPlugin(); + if (plugin != null) { + plugin.readUids(this); + save(database, false); + } + } catch (BookReadingException e) { + } + } } public List authors() { @@ -310,6 +324,24 @@ public class Book extends TitledEntity { addTag(Tag.getTag(null, tagName)); } + public List uids() { + return myUids != null ? Collections.unmodifiableList(myUids) : Collections.emptyList(); + } + + public void addUid(String type, String id) { + addUid(new UID(type, id)); + } + + public void addUid(UID uid) { + if (myUids == null) { + myUids = new ArrayList(); + } + if (!myUids.contains(uid)) { + myUids.add(uid); + myIsSaved = false; + } + } + public boolean matchesUid(UID uid) { return myUids.contains(uid); } @@ -370,6 +402,10 @@ public class Book extends TitledEntity { database.saveBookTagInfo(myId, tag); } database.saveBookSeriesInfo(myId, mySeriesInfo); + database.deleteAllBookUids(myId); + for (UID uid : uids()) { + database.saveBookUid(myId, uid); + } } }); diff --git a/src/org/geometerplus/fbreader/book/BookUtil.java b/src/org/geometerplus/fbreader/book/BookUtil.java index 4bf70b2d5..3381ddda4 100644 --- a/src/org/geometerplus/fbreader/book/BookUtil.java +++ b/src/org/geometerplus/fbreader/book/BookUtil.java @@ -99,7 +99,7 @@ public abstract class BookUtil { for (byte b : hash.digest()) { f.format("%02X", b & 0xFF); } - return new UID("SHA256", f.toString()); + return new UID("SHA-256", f.toString()); } catch (IOException e) { return null; } catch (NoSuchAlgorithmException e) { diff --git a/src/org/geometerplus/fbreader/book/BooksDatabase.java b/src/org/geometerplus/fbreader/book/BooksDatabase.java index c06ee04f0..9b98ae5a0 100644 --- a/src/org/geometerplus/fbreader/book/BooksDatabase.java +++ b/src/org/geometerplus/fbreader/book/BooksDatabase.java @@ -31,7 +31,7 @@ public abstract class BooksDatabase { return createBook(id, infos.getFile(fileId), title, encoding, language); } protected Book createBook(long id, ZLFile file, String title, String encoding, String language) { - return (file != null) ? new Book(id, file, title, encoding, language) : null; + return file != null ? new Book(id, file, title, encoding, language) : null; } protected void addAuthor(Book book, Author author) { book.addAuthorWithNoCheck(author); diff --git a/src/org/geometerplus/fbreader/formats/FormatPlugin.java b/src/org/geometerplus/fbreader/formats/FormatPlugin.java index ceaa53009..4e550aabe 100644 --- a/src/org/geometerplus/fbreader/formats/FormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/FormatPlugin.java @@ -42,6 +42,7 @@ public abstract class FormatPlugin { return file; } public abstract void readMetaInfo(Book book) throws BookReadingException; + public abstract void readUids(Book book) throws BookReadingException; public abstract void readModel(BookModel model) throws BookReadingException; public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException; public abstract ZLImage readCover(ZLFile file); diff --git a/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java b/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java index 43aca5d41..44840c97d 100644 --- a/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java @@ -26,6 +26,7 @@ import org.geometerplus.zlibrary.core.image.*; import org.geometerplus.zlibrary.core.util.MimeType; import org.geometerplus.fbreader.book.Book; +import org.geometerplus.fbreader.book.BookUtil; import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookReadingException; import org.geometerplus.fbreader.formats.fb2.FB2NativePlugin; @@ -55,6 +56,15 @@ public class NativeFormatPlugin extends FormatPlugin { private native boolean readMetaInfoNative(Book book); + synchronized public void readUids(Book book) throws BookReadingException { + readUidsNative(book); + if (book.uids().isEmpty()) { + book.addUid(BookUtil.createSHA256Uid(book.File)); + } + } + + private native boolean readUidsNative(Book book); + @Override public void detectLanguageAndEncoding(Book book) { detectLanguageAndEncodingNative(book); diff --git a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java index 4cf7c5e91..7aa0aa505 100644 --- a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java +++ b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java @@ -47,6 +47,11 @@ public class FB2Plugin extends JavaFormatPlugin { new FB2MetaInfoReader(book).readMetaInfo(); } + @Override + public void readUids(Book book) throws BookReadingException { + // this method does nothing, we expect it will be never called + } + @Override public void readModel(BookModel model) throws BookReadingException { new FB2Reader(model).readBook(); diff --git a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java index bc3cfcc9f..4693fcff2 100644 --- a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java +++ b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java @@ -61,6 +61,11 @@ public class OEBPlugin extends JavaFormatPlugin { new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File)); } + @Override + public void readUids(Book book) throws BookReadingException { + // this method does nothing, we expect it will be never called + } + @Override public void readModel(BookModel model) throws BookReadingException { model.Book.File.setCached(true); diff --git a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java index 5377bebc5..be637efae 100644 --- a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java +++ b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java @@ -29,6 +29,7 @@ import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.core.util.MimeType; import org.geometerplus.fbreader.book.Book; +import org.geometerplus.fbreader.book.BookUtil; import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookReadingException; import org.geometerplus.fbreader.formats.JavaFormatPlugin; @@ -122,6 +123,13 @@ public class MobipocketPlugin extends JavaFormatPlugin { } } + @Override + public void readUids(Book book) throws BookReadingException { + if (book.uids().isEmpty()) { + book.addUid(BookUtil.createSHA256Uid(book.File)); + } + } + @Override public void readModel(BookModel model) throws BookReadingException { try {