1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

Merge branch 'master' into epub-native

This commit is contained in:
Nikolay Pultsin 2012-04-13 18:37:02 +02:00
commit acb57df3c6
2 changed files with 59 additions and 35 deletions

View file

@ -60,7 +60,12 @@ public class Book {
}
fileInfos.save();
return book.readMetaInfo() ? book : null;
try {
book.readMetaInfo();
return book;
} catch (BookReadingException e) {
return null;
}
}
public static Book getByFile(ZLFile bookFile) {
@ -85,14 +90,18 @@ public class Book {
}
fileInfos.save();
if (book == null) {
book = new Book(bookFile);
try {
if (book == null) {
book = new Book(bookFile);
} else {
book.readMetaInfo();
}
} catch (BookReadingException e) {
return null;
}
if (book.readMetaInfo()) {
book.save();
return book;
}
return null;
book.save();
return book;
}
public final ZLFile File;
@ -120,14 +129,18 @@ public class Book {
myIsSaved = true;
}
Book(ZLFile file) {
Book(ZLFile file) throws BookReadingException {
myId = -1;
File = file;
readMetaInfo();
}
public void reloadInfoFromFile() {
if (readMetaInfo()) {
try {
readMetaInfo();
save();
} catch (BookReadingException e) {
// ignore
}
}
@ -140,7 +153,7 @@ public class Book {
myIsSaved = true;
}
boolean readMetaInfo() {
void readMetaInfo() throws BookReadingException {
myEncoding = null;
myLanguage = null;
myTitle = null;
@ -152,13 +165,10 @@ public class Book {
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
if (plugin == null) {
return false;
}
try {
plugin.readMetaInfo(this);
} catch (BookReadingException e) {
return false;
throw new BookReadingException("pluginNotFound", File);
}
plugin.readMetaInfo(this);
if (myTitle == null || myTitle.length() == 0) {
final String fileName = File.getShortName();
final int index = fileName.lastIndexOf('.');
@ -170,7 +180,6 @@ public class Book {
setTitle(getTitle() + " (" + demoTag + ")");
addTag(demoTag);
}
return true;
}
private void loadLists() {

View file

@ -26,6 +26,7 @@ import org.geometerplus.zlibrary.core.filesystem.*;
import org.geometerplus.fbreader.tree.FBTree;
import org.geometerplus.fbreader.Paths;
import org.geometerplus.fbreader.bookmodel.BookReadingException;
public final class Library extends AbstractLibrary {
public static final String ROOT_FOUND = "found";
@ -121,20 +122,29 @@ public final class Library extends AbstractLibrary {
return;
}
Book book = orphanedBooksByFileId.get(fileId);
if (book != null && (!doReadMetaInfo || book.readMetaInfo())) {
addBookToLibrary(book);
fireModelChangedEvent(ChangeListener.Code.BookAdded);
newBooks.add(book);
return;
try {
final Book book = orphanedBooksByFileId.get(fileId);
if (book != null) {
if (doReadMetaInfo) {
book.readMetaInfo();
}
addBookToLibrary(book);
fireModelChangedEvent(ChangeListener.Code.BookAdded);
newBooks.add(book);
return;
}
} catch (BookReadingException e) {
// ignore
}
book = new Book(file);
if (book.readMetaInfo()) {
try {
final Book book = new Book(file);
addBookToLibrary(book);
fireModelChangedEvent(ChangeListener.Code.BookAdded);
newBooks.add(book);
return;
} catch (BookReadingException e) {
// ignore
}
if (file.isArchive()) {
@ -337,9 +347,10 @@ public final class Library extends AbstractLibrary {
continue;
}
if (!fileInfos.check(file, true)) {
if (book.readMetaInfo()) {
try {
book.readMetaInfo();
book.save();
} else {
} catch (BookReadingException e) {
doAdd = false;
}
file.setCached(false);
@ -377,14 +388,18 @@ public final class Library extends AbstractLibrary {
}
// Step 4: add help file
final ZLFile helpFile = getHelpFile();
Book helpBook = savedBooksByFileId.get(fileInfos.getId(helpFile));
if (helpBook == null) {
helpBook = new Book(helpFile);
helpBook.readMetaInfo();
try {
final ZLFile helpFile = getHelpFile();
Book helpBook = savedBooksByFileId.get(fileInfos.getId(helpFile));
if (helpBook == null) {
helpBook = new Book(helpFile);
}
addBookToLibrary(helpBook);
fireModelChangedEvent(ChangeListener.Code.BookAdded);
} catch (BookReadingException e) {
// that's impossible
e.printStackTrace();
}
addBookToLibrary(helpBook);
fireModelChangedEvent(ChangeListener.Code.BookAdded);
// Step 5: save changes into database
fileInfos.save();