Ejemplo n.º 1
0
  public static Book getByFile(ZLFile bookFile) {
    if (bookFile == null) {
      return null;
    }

    final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
    if (physicalFile != null && !physicalFile.exists()) {
      return null;
    }

    final FileInfoSet fileInfos = new FileInfoSet(bookFile);

    Book book = BooksDatabase.Instance().loadBookByFile(fileInfos.getId(bookFile), bookFile);
    if (book != null) {
      book.loadLists();
    }

    if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) {
      return book;
    }
    fileInfos.save();

    if (book == null) {
      book = new Book(bookFile);
    }
    if (book.readMetaInfo()) {
      book.save();
      return book;
    }
    return null;
  }
Ejemplo n.º 2
0
  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;
  }
Ejemplo n.º 3
0
  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;
    }
  }
Ejemplo n.º 4
0
  public static Book getById(long bookId) {
    final Book book = BooksDatabase.Instance().loadBook(bookId);
    if (book == null) {
      return null;
    }
    book.loadLists();

    final ZLFile bookFile = book.File;
    final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
    if (physicalFile == null) {
      return book;
    }
    if (!physicalFile.exists()) {
      return null;
    }

    FileInfoSet fileInfos = new FileInfoSet(physicalFile);
    if (fileInfos.check(physicalFile, physicalFile != bookFile)) {
      return book;
    }
    fileInfos.save();

    return book.readMetaInfo() ? book : null;
  }