Пример #1
0
  boolean readMetaInfo() {
    myEncoding = null;
    myLanguage = null;
    myTitle = null;
    myAuthors = null;
    myTags = null;
    mySeriesInfo = null;

    myIsSaved = false;

    final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
    if (plugin == null || !plugin.readMetaInfo(this)) {
      return false;
    }
    if (myTitle == null || myTitle.length() == 0) {
      final String fileName = File.getShortName();
      final int index = fileName.lastIndexOf('.');
      setTitle(index > 0 ? fileName.substring(0, index) : fileName);
    }
    final String demoPathPrefix =
        Paths.BooksDirectoryOption().getValue()
            + java.io.File.separator
            + "Demos"
            + java.io.File.separator;
    if (File.getPath().startsWith(demoPathPrefix)) {
      final String demoTag = LibraryUtil.resource().getResource("demo").getValue();
      setTitle(getTitle() + " (" + demoTag + ")");
      addTag(demoTag);
    }
    return true;
  }
Пример #2
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;
  }
Пример #3
0
  public String getContentHashCode() {
    InputStream stream = null;

    try {
      final MessageDigest hash = MessageDigest.getInstance("SHA-256");
      stream = File.getInputStream();

      final byte[] buffer = new byte[2048];
      while (true) {
        final int nread = stream.read(buffer);
        if (nread == -1) {
          break;
        }
        hash.update(buffer, 0, nread);
      }

      final Formatter f = new Formatter();
      for (byte b : hash.digest()) {
        f.format("%02X", b & 0xFF);
      }
      return f.toString();
    } catch (IOException e) {
      return null;
    } catch (NoSuchAlgorithmException e) {
      return null;
    } finally {
      if (stream != null) {
        try {
          stream.close();
        } catch (IOException e) {
        }
      }
    }
  }
Пример #4
0
 boolean matches(String pattern) {
   if (myTitle != null && ZLMiscUtil.matchesIgnoreCase(myTitle, pattern)) {
     return true;
   }
   if (mySeriesInfo != null && ZLMiscUtil.matchesIgnoreCase(mySeriesInfo.Name, pattern)) {
     return true;
   }
   if (myAuthors != null) {
     for (Author author : myAuthors) {
       if (ZLMiscUtil.matchesIgnoreCase(author.DisplayName, pattern)) {
         return true;
       }
     }
   }
   if (myTags != null) {
     for (Tag tag : myTags) {
       if (ZLMiscUtil.matchesIgnoreCase(tag.Name, pattern)) {
         return true;
       }
     }
   }
   if (ZLMiscUtil.matchesIgnoreCase(File.getLongName(), pattern)) {
     return true;
   }
   return false;
 }
Пример #5
0
 @Override
 public boolean equals(Object o) {
   if (this == o) {
     return true;
   }
   if (!(o instanceof Book)) {
     return false;
   }
   return File.equals(((Book) o).File);
 }
Пример #6
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;
  }