public Book getBookByFile(ZLFile bookFile) { if (bookFile == null) { return null; } final FormatPlugin plugin = PluginCollection.Instance().getPlugin(bookFile); if (plugin == null) { return null; } try { bookFile = plugin.realBookFile(bookFile); } catch (BookReadingException e) { return null; } Book book = myBooksByFile.get(bookFile); if (book != null) { return book; } final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile(); if (physicalFile != null && !physicalFile.exists()) { return null; } final FileInfoSet fileInfos = new FileInfoSet(myDatabase, bookFile); book = myDatabase.loadBookByFile(fileInfos.getId(bookFile), bookFile); if (book != null) { book.loadLists(myDatabase); } if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) { saveBook(book, false); // saved addBook(book, false); return book; } fileInfos.save(); try { if (book == null) { book = new Book(bookFile); } else { book.readMetaInfo(); } } catch (BookReadingException e) { return null; } saveBook(book, false); return book; }
public Book getBookById(long id) { Book book = myBooksById.get(id); if (book != null) { return book; } book = myDatabase.loadBook(id); if (book == null) { return null; } book.loadLists(myDatabase); final ZLFile bookFile = book.File; final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile(); if (physicalFile == null) { // loaded from db addBook(book, false); return book; } if (!physicalFile.exists()) { return null; } FileInfoSet fileInfos = new FileInfoSet(myDatabase, physicalFile); if (fileInfos.check(physicalFile, physicalFile != bookFile)) { // loaded from db addBook(book, false); return book; } fileInfos.save(); try { book.readMetaInfo(); // loaded from db addBook(book, false); return book; } catch (BookReadingException e) { return null; } }