Exemple #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;
  }
 @Override
 public ZLPhysicalFile getPhysicalFile() {
   ZLFile ancestor = myParent;
   while ((ancestor != null) && !(ancestor instanceof ZLPhysicalFile)) {
     ancestor = ancestor.getParent();
   }
   return (ZLPhysicalFile) ancestor;
 }
Exemple #3
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;
  }
Exemple #4
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) {
        }
      }
    }
  }
Exemple #5
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;
 }
 private static ZipFile getZipFile(final ZLFile file) throws IOException {
   synchronized (ourZipFileMap) {
     ZipFile zf = file.isCached() ? ourZipFileMap.get(file) : null;
     if (zf == null) {
       zf =
           new ZipFile(
               new ZipFile.InputStreamHolder() {
                 public InputStream getInputStream() throws IOException {
                   return file.getInputStream();
                 }
               });
       if (file.isCached()) {
         ourZipFileMap.put(file, zf);
       }
     }
     return zf;
   }
 }
Exemple #7
0
 @Override
 public boolean equals(Object o) {
   if (this == o) {
     return true;
   }
   if (!(o instanceof Book)) {
     return false;
   }
   return File.equals(((Book) o).File);
 }
Exemple #8
0
 private Book createBookForFile(ZLFile file) {
   if (file == null) {
     return null;
   }
   Book book = Book.getByFile(file);
   if (book != null) {
     book.insertIntoBookList();
     return book;
   }
   if (file.isArchive()) {
     for (ZLFile child : file.children()) {
       book = Book.getByFile(child);
       if (book != null) {
         book.insertIntoBookList();
         return book;
       }
     }
   }
   return null;
 }
Exemple #9
0
  public static List<String> languageCodes() {
    if (ourLanguageCodes.isEmpty()) {
      TreeSet<String> codes = new TreeSet<String>();
      for (ZLFile file : patternsFile().children()) {
        String name = file.getShortName();
        final int index = name.indexOf("_");
        if (index != -1) {
          String str = name.substring(0, index);
          if (!codes.contains(str)) {
            codes.add(str);
          }
        }
      }
      codes.add("id");
      codes.add("de-traditional");

      ourLanguageCodes.addAll(codes);
    }

    return Collections.unmodifiableList(ourLanguageCodes);
  }
Exemple #10
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;
  }
 @Override
 public String getPath() {
   return myParent.getPath() + ":" + myName;
 }