1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

book uids (in progress)

This commit is contained in:
Nikolay Pultsin 2013-03-19 01:52:42 +04:00
parent 20491d9a12
commit 9eb54b261a
30 changed files with 205 additions and 16 deletions

View file

@ -142,7 +142,8 @@ LOCAL_SRC_FILES := \
NativeFormats/fbreader/src/library/Book.cpp \ NativeFormats/fbreader/src/library/Book.cpp \
NativeFormats/fbreader/src/library/Comparators.cpp \ NativeFormats/fbreader/src/library/Comparators.cpp \
NativeFormats/fbreader/src/library/Library.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_C_INCLUDES := \
$(LOCAL_PATH)/NativeFormats/util \ $(LOCAL_PATH)/NativeFormats/util \

View file

@ -27,6 +27,7 @@
#include "fbreader/src/library/Author.h" #include "fbreader/src/library/Author.h"
#include "fbreader/src/library/Book.h" #include "fbreader/src/library/Book.h"
#include "fbreader/src/library/Tag.h" #include "fbreader/src/library/Tag.h"
#include "fbreader/src/library/UID.h"
static shared_ptr<FormatPlugin> findCppPlugin(jobject base) { static shared_ptr<FormatPlugin> findCppPlugin(jobject base) {
const std::string fileType = AndroidUtil::Method_NativeFormatPlugin_supportedFileType->callForCppString(base); const std::string fileType = AndroidUtil::Method_NativeFormatPlugin_supportedFileType->callForCppString(base);
@ -37,6 +38,17 @@ static shared_ptr<FormatPlugin> findCppPlugin(jobject base) {
return plugin; 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) { static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) {
jstring javaString; jstring javaString;
@ -81,6 +93,8 @@ static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) {
const Tag &tag = *tags[i]; const Tag &tag = *tags[i];
AndroidUtil::Method_Book_addTag->call(javaBook, tag.javaTag(env)); AndroidUtil::Method_Book_addTag->call(javaBook, tag.javaTag(env));
} }
fillUids(env, javaBook, book);
} }
static void fillLanguageAndEncoding(JNIEnv* env, jobject javaBook, Book &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; return JNI_TRUE;
} }
extern "C"
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readUidsNative(JNIEnv* env, jobject thiz, jobject javaBook) {
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
if (plugin.isNull()) {
return;
}
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
plugin->readUids(*book);
fillUids(env, javaBook, *book);
}
extern "C" extern "C"
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_detectLanguageAndEncodingNative(JNIEnv* env, jobject thiz, jobject javaBook) { JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_detectLanguageAndEncodingNative(JNIEnv* env, jobject thiz, jobject javaBook) {
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz); shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);

View file

@ -58,6 +58,7 @@ public:
virtual const std::string &tryOpen(const ZLFile &file) const; virtual const std::string &tryOpen(const ZLFile &file) const;
virtual bool readMetaInfo(Book &book) const = 0; virtual bool readMetaInfo(Book &book) const = 0;
virtual bool readUids(Book &book) const = 0;
virtual bool readLanguageAndEncoding(Book &book) const = 0; virtual bool readLanguageAndEncoding(Book &book) const = 0;
virtual bool readModel(BookModel &model) const = 0; virtual bool readModel(BookModel &model) const = 0;
virtual shared_ptr<const ZLImage> coverImage(const ZLFile &file) const; virtual shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;

View file

@ -62,6 +62,10 @@ bool DocPlugin::readMetaInfo(Book &book) const {
return true; return true;
} }
bool DocPlugin::readUids(Book&) const {
return false;
}
bool DocPlugin::readLanguageAndEncoding(Book &/*book*/) const { bool DocPlugin::readLanguageAndEncoding(Book &/*book*/) const {
return true; return true;
} }

View file

@ -32,6 +32,7 @@ public:
const std::string supportedFileType() const; const std::string supportedFileType() const;
bool acceptsFile(const ZLFile &file) const; bool acceptsFile(const ZLFile &file) const;
bool readMetaInfo(Book &book) const; bool readMetaInfo(Book &book) const;
bool readUids(Book &book) const;
bool readLanguageAndEncoding(Book &book) const; bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const; bool readModel(BookModel &model) const;
}; };

View file

@ -30,6 +30,7 @@ public:
bool providesMetaInfo() const; bool providesMetaInfo() const;
const std::string supportedFileType() const; const std::string supportedFileType() const;
bool readMetaInfo(Book &book) const; bool readMetaInfo(Book &book) const;
bool readUids(Book &book) const;
bool readLanguageAndEncoding(Book &book) const; bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const; bool readModel(BookModel &model) const;
shared_ptr<const ZLImage> coverImage(const ZLFile &file) const; shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;

View file

@ -50,6 +50,10 @@ bool HtmlPlugin::readMetaInfo(Book &book) const {
return true; return true;
} }
bool HtmlPlugin::readUids(Book&) const {
return false;
}
bool HtmlPlugin::readModel(BookModel &model) const { bool HtmlPlugin::readModel(BookModel &model) const {
const Book& book = *model.book(); const Book& book = *model.book();
const ZLFile &file = book.file(); const ZLFile &file = book.file();

View file

@ -30,6 +30,7 @@ public:
bool providesMetaInfo() const; bool providesMetaInfo() const;
const std::string supportedFileType() const; const std::string supportedFileType() const;
bool readMetaInfo(Book &book) const; bool readMetaInfo(Book &book) const;
bool readUids(Book &book) const;
bool readLanguageAndEncoding(Book &book) const; bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const; bool readModel(BookModel &model) const;
// FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file); // FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file);

View file

@ -32,6 +32,7 @@ public:
bool providesMetaInfo() const; bool providesMetaInfo() const;
const std::string supportedFileType() const; const std::string supportedFileType() const;
bool readMetaInfo(Book &book) const; bool readMetaInfo(Book &book) const;
bool readUids(Book &book) const;
bool readLanguageAndEncoding(Book &book) const; bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const; bool readModel(BookModel &model) const;
shared_ptr<const ZLImage> coverImage(const ZLFile &file) const; shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;

View file

@ -54,6 +54,10 @@ bool RtfPlugin::readMetaInfo(Book &book) const {
return true; return true;
} }
bool RtfPlugin::readUids(Book&) const {
return false;
}
bool RtfPlugin::readModel(BookModel &model) const { bool RtfPlugin::readModel(BookModel &model) const {
const Book &book = *model.book(); const Book &book = *model.book();
return RtfBookReader(model, book.encoding()).readDocument(book.file()); return RtfBookReader(model, book.encoding()).readDocument(book.file());

View file

@ -28,6 +28,7 @@ public:
bool providesMetaInfo() const; bool providesMetaInfo() const;
const std::string supportedFileType() const; const std::string supportedFileType() const;
bool readMetaInfo(Book &book) const; bool readMetaInfo(Book &book) const;
bool readUids(Book &book) const;
bool readLanguageAndEncoding(Book &book) const; bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const; bool readModel(BookModel &model) const;
}; };

View file

@ -38,10 +38,14 @@ const std::string TxtPlugin::supportedFileType() const {
return "plain text"; return "plain text";
} }
bool TxtPlugin::readMetaInfo(Book &book) const { bool TxtPlugin::readMetaInfo(Book&) const {
return true; return true;
} }
bool TxtPlugin::readUids(Book&) const {
return false;
}
bool TxtPlugin::readModel(BookModel &model) const { bool TxtPlugin::readModel(BookModel &model) const {
Book &book = *model.book(); Book &book = *model.book();
const ZLFile &file = book.file(); const ZLFile &file = book.file();

View file

@ -29,6 +29,7 @@ public:
bool providesMetaInfo() const; bool providesMetaInfo() const;
const std::string supportedFileType() const; const std::string supportedFileType() const;
bool readMetaInfo(Book &book) const; bool readMetaInfo(Book &book) const;
bool readUids(Book &book) const;
bool readLanguageAndEncoding(Book &book) const; bool readLanguageAndEncoding(Book &book) const;
bool readModel(BookModel &model) const; bool readModel(BookModel &model) const;
// FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file); // FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file);

View file

@ -30,6 +30,7 @@
#include "Book.h" #include "Book.h"
#include "Author.h" #include "Author.h"
#include "Tag.h" #include "Tag.h"
#include "UID.h"
#include "../formats/FormatPlugin.h" #include "../formats/FormatPlugin.h"
//#include "../migration/BookInfo.h" //#include "../migration/BookInfo.h"

View file

@ -30,9 +30,6 @@
#include "Lists.h" #include "Lists.h"
class Author;
class Tag;
class Book { class Book {
public: public:
@ -70,6 +67,7 @@ public: // unmodifiable book methods
const TagList &tags() const; const TagList &tags() const;
const AuthorList &authors() const; const AuthorList &authors() const;
const UIDList &uids() const;
public: // modifiable book methods public: // modifiable book methods
void setTitle(const std::string &title); void setTitle(const std::string &title);
@ -105,6 +103,7 @@ private:
std::string myIndexInSeries; std::string myIndexInSeries;
TagList myTags; TagList myTags;
AuthorList myAuthors; AuthorList myAuthors;
UIDList myUIDs;
private: // disable copying private: // disable copying
Book(const Book &); 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 TagList &Book::tags() const { return myTags; }
inline const AuthorList &Book::authors() const { return myAuthors; } inline const AuthorList &Book::authors() const { return myAuthors; }
inline const UIDList &Book::uids() const { return myUIDs; }
inline int Book::bookId() const { return myBookId; } inline int Book::bookId() const { return myBookId; }
inline void Book::setBookId(int bookId) { myBookId = bookId; } inline void Book::setBookId(int bookId) { myBookId = bookId; }

View file

@ -28,6 +28,7 @@
class Book; class Book;
class Author; class Author;
class Tag; class Tag;
class UID;
class BookByFileNameComparator; class BookByFileNameComparator;
typedef std::vector<shared_ptr<Book> > BookList; typedef std::vector<shared_ptr<Book> > BookList;
@ -35,5 +36,6 @@ typedef std::set<shared_ptr<Book>,BookByFileNameComparator> BookSet;
typedef std::vector<shared_ptr<Author> > AuthorList; typedef std::vector<shared_ptr<Author> > AuthorList;
typedef std::vector<shared_ptr<Tag> > TagList; typedef std::vector<shared_ptr<Tag> > TagList;
typedef std::set<shared_ptr<Tag> > TagSet; typedef std::set<shared_ptr<Tag> > TagSet;
typedef std::vector<shared_ptr<UID> > UIDList;
#endif /* __LISTS_H__ */ #endif /* __LISTS_H__ */

View file

@ -0,0 +1,20 @@
/*
* Copyright (C) 2009-2013 Geometer Plus <contact@geometerplus.com>
*
* 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"

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2009-2013 Geometer Plus <contact@geometerplus.com>
*
* 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 <string>
#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__ */

View file

@ -104,6 +104,7 @@ shared_ptr<VoidMethod> AndroidUtil::Method_Book_setLanguage;
shared_ptr<VoidMethod> AndroidUtil::Method_Book_setEncoding; shared_ptr<VoidMethod> AndroidUtil::Method_Book_setEncoding;
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addAuthor; shared_ptr<VoidMethod> AndroidUtil::Method_Book_addAuthor;
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addTag; shared_ptr<VoidMethod> AndroidUtil::Method_Book_addTag;
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addUid;
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Tag_getTag; shared_ptr<StaticObjectMethod> 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_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_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, "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;)"); StaticMethod_Tag_getTag = new StaticObjectMethod(Class_Tag, "getTag", Class_Tag, "(Lorg/geometerplus/fbreader/book/Tag;Ljava/lang/String;)");

View file

@ -126,6 +126,7 @@ public:
static shared_ptr<VoidMethod> Method_Book_setEncoding; static shared_ptr<VoidMethod> Method_Book_setEncoding;
static shared_ptr<VoidMethod> Method_Book_addAuthor; static shared_ptr<VoidMethod> Method_Book_addAuthor;
static shared_ptr<VoidMethod> Method_Book_addTag; static shared_ptr<VoidMethod> Method_Book_addTag;
static shared_ptr<VoidMethod> Method_Book_addUid;
static shared_ptr<StaticObjectMethod> StaticMethod_Tag_getTag; static shared_ptr<StaticObjectMethod> StaticMethod_Tag_getTag;

View file

@ -80,6 +80,7 @@
public void setEncoding(**); public void setEncoding(**);
public void addAuthor(**,**); public void addAuthor(**,**);
public void addTag(**); public void addTag(**);
public void addUid(**);
} }
-keep class org.geometerplus.fbreader.book.Tag -keep class org.geometerplus.fbreader.book.Tag
-keepclassmembers class org.geometerplus.fbreader.book.Tag { -keepclassmembers class org.geometerplus.fbreader.book.Tag {

View file

@ -77,7 +77,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
private void migrate() { private void migrate() {
final int version = myDatabase.getVersion(); final int version = myDatabase.getVersion();
final int currentVersion = 21; final int currentVersion = 22;
if (version >= currentVersion) { if (version >= currentVersion) {
return; return;
} }
@ -127,6 +127,8 @@ final class SQLiteBooksDatabase extends BooksDatabase {
updateTables19(); updateTables19();
case 20: case 20:
updateTables20(); updateTables20();
case 21:
updateTables21();
} }
myDatabase.setTransactionSuccessful(); myDatabase.setTransactionSuccessful();
myDatabase.setVersion(currentVersion); myDatabase.setVersion(currentVersion);
@ -482,15 +484,15 @@ final class SQLiteBooksDatabase extends BooksDatabase {
protected void saveBookUid(long bookId, UID uid) { protected void saveBookUid(long bookId, UID uid) {
if (myInsertBookUidStatement == null) { if (myInsertBookUidStatement == null) {
myInsertBookUidStatement = myDatabase.compileStatement( 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) { synchronized (myInsertBookUidStatement) {
myInsertBookUidStatement.bindLong(1, bookId); myInsertBookUidStatement.bindLong(1, bookId);
myInsertBookUidStatement.bindString(2, uid.Type); myInsertBookUidStatement.bindString(2, uid.Type);
myInsertBookUidStatement.bindString(2, uid.Id); myInsertBookUidStatement.bindString(3, uid.Id);
myInsertBookAuthorStatement.execute(); myInsertBookUidStatement.execute();
} }
} }
@ -1373,11 +1375,6 @@ final class SQLiteBooksDatabase extends BooksDatabase {
} }
private void updateTables20() { 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( myDatabase.execSQL(
"CREATE TABLE IF NOT EXISTS Labels(" + "CREATE TABLE IF NOT EXISTS Labels(" +
"label_id INTEGER PRIMARY KEY," + "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("INSERT INTO BookLabel (label_id,book_id) SELECT " + id + ",book_id FROM Favorites");
myDatabase.execSQL("DROP TABLE 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))");
}
} }

View file

@ -115,10 +115,14 @@ public class Book extends TitledEntity {
myAuthors = null; myAuthors = null;
myTags = null; myTags = null;
mySeriesInfo = null; mySeriesInfo = null;
myUids = null;
myIsSaved = false; myIsSaved = false;
plugin.readMetaInfo(this); plugin.readMetaInfo(this);
if (myUids == null || myUids.isEmpty()) {
plugin.readUids(this);
}
if (isTitleEmpty()) { if (isTitleEmpty()) {
final String fileName = File.getShortName(); final String fileName = File.getShortName();
@ -139,6 +143,16 @@ public class Book extends TitledEntity {
mySeriesInfo = database.getSeriesInfo(myId); mySeriesInfo = database.getSeriesInfo(myId);
myUids = database.listUids(myId); myUids = database.listUids(myId);
myIsSaved = true; 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<Author> authors() { public List<Author> authors() {
@ -310,6 +324,24 @@ public class Book extends TitledEntity {
addTag(Tag.getTag(null, tagName)); addTag(Tag.getTag(null, tagName));
} }
public List<UID> uids() {
return myUids != null ? Collections.unmodifiableList(myUids) : Collections.<UID>emptyList();
}
public void addUid(String type, String id) {
addUid(new UID(type, id));
}
public void addUid(UID uid) {
if (myUids == null) {
myUids = new ArrayList<UID>();
}
if (!myUids.contains(uid)) {
myUids.add(uid);
myIsSaved = false;
}
}
public boolean matchesUid(UID uid) { public boolean matchesUid(UID uid) {
return myUids.contains(uid); return myUids.contains(uid);
} }
@ -370,6 +402,10 @@ public class Book extends TitledEntity {
database.saveBookTagInfo(myId, tag); database.saveBookTagInfo(myId, tag);
} }
database.saveBookSeriesInfo(myId, mySeriesInfo); database.saveBookSeriesInfo(myId, mySeriesInfo);
database.deleteAllBookUids(myId);
for (UID uid : uids()) {
database.saveBookUid(myId, uid);
}
} }
}); });

View file

@ -99,7 +99,7 @@ public abstract class BookUtil {
for (byte b : hash.digest()) { for (byte b : hash.digest()) {
f.format("%02X", b & 0xFF); f.format("%02X", b & 0xFF);
} }
return new UID("SHA256", f.toString()); return new UID("SHA-256", f.toString());
} catch (IOException e) { } catch (IOException e) {
return null; return null;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {

View file

@ -31,7 +31,7 @@ public abstract class BooksDatabase {
return createBook(id, infos.getFile(fileId), title, encoding, language); return createBook(id, infos.getFile(fileId), title, encoding, language);
} }
protected Book createBook(long id, ZLFile file, String title, String encoding, String 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) { protected void addAuthor(Book book, Author author) {
book.addAuthorWithNoCheck(author); book.addAuthorWithNoCheck(author);

View file

@ -42,6 +42,7 @@ public abstract class FormatPlugin {
return file; return file;
} }
public abstract void readMetaInfo(Book book) throws BookReadingException; 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 readModel(BookModel model) throws BookReadingException;
public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException; public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException;
public abstract ZLImage readCover(ZLFile file); public abstract ZLImage readCover(ZLFile file);

View file

@ -26,6 +26,7 @@ import org.geometerplus.zlibrary.core.image.*;
import org.geometerplus.zlibrary.core.util.MimeType; import org.geometerplus.zlibrary.core.util.MimeType;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.Book;
import org.geometerplus.fbreader.book.BookUtil;
import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.fbreader.bookmodel.BookReadingException; import org.geometerplus.fbreader.bookmodel.BookReadingException;
import org.geometerplus.fbreader.formats.fb2.FB2NativePlugin; import org.geometerplus.fbreader.formats.fb2.FB2NativePlugin;
@ -55,6 +56,15 @@ public class NativeFormatPlugin extends FormatPlugin {
private native boolean readMetaInfoNative(Book book); 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 @Override
public void detectLanguageAndEncoding(Book book) { public void detectLanguageAndEncoding(Book book) {
detectLanguageAndEncodingNative(book); detectLanguageAndEncodingNative(book);

View file

@ -47,6 +47,11 @@ public class FB2Plugin extends JavaFormatPlugin {
new FB2MetaInfoReader(book).readMetaInfo(); new FB2MetaInfoReader(book).readMetaInfo();
} }
@Override
public void readUids(Book book) throws BookReadingException {
// this method does nothing, we expect it will be never called
}
@Override @Override
public void readModel(BookModel model) throws BookReadingException { public void readModel(BookModel model) throws BookReadingException {
new FB2Reader(model).readBook(); new FB2Reader(model).readBook();

View file

@ -61,6 +61,11 @@ public class OEBPlugin extends JavaFormatPlugin {
new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File)); 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 @Override
public void readModel(BookModel model) throws BookReadingException { public void readModel(BookModel model) throws BookReadingException {
model.Book.File.setCached(true); model.Book.File.setCached(true);

View file

@ -29,6 +29,7 @@ import org.geometerplus.zlibrary.core.language.ZLLanguageUtil;
import org.geometerplus.zlibrary.core.util.MimeType; import org.geometerplus.zlibrary.core.util.MimeType;
import org.geometerplus.fbreader.book.Book; import org.geometerplus.fbreader.book.Book;
import org.geometerplus.fbreader.book.BookUtil;
import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.fbreader.bookmodel.BookReadingException; import org.geometerplus.fbreader.bookmodel.BookReadingException;
import org.geometerplus.fbreader.formats.JavaFormatPlugin; 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 @Override
public void readModel(BookModel model) throws BookReadingException { public void readModel(BookModel model) throws BookReadingException {
try { try {