예제 #1
0
 private boolean addRoot(String pathname, String filename, boolean listIt) {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = pathname;
   dir.filename = filename;
   if (findRoot(pathname) != null) {
     log.w("skipping duplicate root " + pathname);
     return false; // exclude duplicates
   }
   if (listIt) {
     log.i("Checking FS root " + pathname);
     if (!dir.isReadableDirectory()) { // isWritableDirectory
       log.w("Skipping " + pathname + " - it's not a readable directory");
       return false;
     }
     if (!listDirectory(dir)) {
       log.w("Skipping " + pathname + " - listing failed");
       return false;
     }
     log.i("Adding FS root: " + pathname + "  " + filename);
   }
   mRoot.addDir(dir);
   dir.parent = mRoot;
   if (!listIt) {
     dir.isListed = true;
     dir.isScanned = true;
   }
   return true;
 }
예제 #2
0
 public FileInfo createTitleRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.TITLE_TAG;
   dir.filename = mActivity.getString(R.string.folder_name_books_by_title);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #3
0
 public FileInfo createBooksByStateFinishedRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.STATE_FINISHED_TAG;
   dir.filename = mActivity.getString(R.string.folder_name_books_by_state_finished);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #4
0
 public FileInfo createBooksByStateReadingRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.STATE_READING_TAG;
   dir.filename = mActivity.getString(R.string.folder_name_books_by_state_reading);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #5
0
 public FileInfo createBooksByRatingRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.RATING_TAG;
   dir.filename = mActivity.getString(R.string.folder_name_books_by_rating);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #6
0
 public FileInfo createSeriesRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.SERIES_TAG;
   dir.filename = mActivity.getString(R.string.folder_name_books_by_series);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #7
0
 public FileInfo createAuthorsRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.AUTHORS_TAG;
   dir.filename = mActivity.getString(R.string.folder_name_books_by_author);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #8
0
 public FileInfo createSearchRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.SEARCH_SHORTCUT_TAG;
   dir.filename = mActivity.getString(R.string.mi_book_search);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #9
0
 public FileInfo createRecentRoot() {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.RECENT_DIR_TAG;
   dir.filename = mActivity.getString(R.string.dir_recent_books);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #10
0
 public FileInfo createOPDSRoot() {
   final FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = FileInfo.OPDS_LIST_TAG;
   dir.filename = mActivity.getString(R.string.mi_book_opds_root);
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #11
0
 public static FileInfo createOnlineLibraryPluginItem(String packageName, String label) {
   final FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   if (packageName.startsWith(FileInfo.ONLINE_CATALOG_PLUGIN_PREFIX)) dir.pathname = packageName;
   else dir.pathname = FileInfo.ONLINE_CATALOG_PLUGIN_PREFIX + packageName;
   dir.filename = label;
   dir.isListed = true;
   dir.isScanned = true;
   return dir;
 }
예제 #12
0
 public Scanner(BaseActivity coolReader, Engine engine) {
   this.engine = engine;
   this.mActivity = coolReader;
   mRoot = new FileInfo();
   mRoot.path = FileInfo.ROOT_DIR_TAG;
   mRoot.filename = "File Manager";
   mRoot.pathname = FileInfo.ROOT_DIR_TAG;
   mRoot.isListed = true;
   mRoot.isScanned = true;
   mRoot.isDirectory = true;
 }
예제 #13
0
 private FileInfo scanZip(FileInfo zip) {
   try {
     File zf = new File(zip.pathname);
     long arcsize = zf.length();
     // ZipFile file = new ZipFile(zf);
     ArrayList<ZipEntry> entries = engine.getArchiveItems(zip.pathname);
     ArrayList<FileInfo> items = new ArrayList<FileInfo>();
     // for ( Enumeration<?> e = file.entries(); e.hasMoreElements(); ) {
     for (ZipEntry entry : entries) {
       if (entry.isDirectory()) continue;
       String name = entry.getName();
       FileInfo item = new FileInfo();
       item.format = DocumentFormat.byExtension(name);
       if (item.format == null) continue;
       File f = new File(name);
       item.filename = f.getName();
       item.path = f.getPath();
       item.pathname = entry.getName();
       item.size = (int) entry.getSize();
       // item.createTime = entry.getTime();
       item.createTime = zf.lastModified();
       item.arcname = zip.pathname;
       item.arcsize = (int) entry.getCompressedSize();
       item.isArchive = true;
       items.add(item);
     }
     if (items.size() == 0) {
       L.i("Supported files not found in " + zip.pathname);
       return null;
     } else if (items.size() == 1) {
       // single supported file in archive
       FileInfo item = items.get(0);
       item.isArchive = true;
       item.isDirectory = false;
       return item;
     } else {
       zip.isArchive = true;
       zip.isDirectory = true;
       zip.isListed = true;
       for (FileInfo item : items) {
         item.parent = zip;
         zip.addFile(item);
       }
       return zip;
     }
   } catch (Exception e) {
     L.e("IOException while opening " + zip.pathname + " " + e.getMessage());
   }
   return null;
 }
예제 #14
0
 public FileInfo setSearchResults(FileInfo[] results) {
   FileInfo existingResults = null;
   for (int i = 0; i < mRoot.dirCount(); i++) {
     FileInfo dir = mRoot.getDir(i);
     if (dir.isSearchDir()) {
       existingResults = dir;
       dir.clear();
       break;
     }
   }
   if (existingResults == null) {
     FileInfo dir = new FileInfo();
     dir.isDirectory = true;
     dir.pathname = FileInfo.SEARCH_RESULT_DIR_TAG;
     dir.filename = mActivity.getResources().getString(R.string.dir_search_results);
     dir.parent = mRoot;
     dir.isListed = true;
     dir.isScanned = true;
     mRoot.addDir(dir);
     existingResults = dir;
   }
   for (FileInfo item : results) existingResults.addFile(item);
   return existingResults;
 }