public FileInfo getDownloadDirectory() { for (int i = 0; i < mRoot.dirCount(); i++) { FileInfo item = mRoot.getDir(i); if (!item.isSpecialDir() && !item.isArchive) { if (!item.isListed) listDirectory(item); FileInfo books = item.findItemByPathName(item.pathname + "/Books"); if (books == null) books = item.findItemByPathName(item.pathname + "/books"); if (books != null && books.exists()) return books; File dir = new File(item.getPathName()); if (dir.isDirectory()) { if (!dir.canWrite()) Log.w("cr3", "Directory " + dir + " is readonly"); File f = new File(dir, "Books"); if (f.mkdirs() || f.isDirectory()) { books = new FileInfo(f); books.parent = item; item.addDir(books); books.isScanned = true; books.isListed = true; return books; } } } } try { throw new Exception("download directory not found and cannot be created"); } catch (Exception e) { Log.e("cr3", "download directory is not found!!!", e); } return null; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
/** * Adds dir and file children to directory FileInfo item. * * @param baseDir is directory to list files and dirs for * @return true if successful. */ public boolean listDirectory(FileInfo baseDir) { Set<String> knownItems = null; if (baseDir.isListed) { knownItems = new HashSet<String>(); for (int i = baseDir.itemCount() - 1; i >= 0; i--) { FileInfo item = baseDir.getItem(i); if (!item.exists()) { // remove item from list baseDir.removeChild(item); } else { knownItems.add(item.getBasePath()); } } } try { File dir = new File(baseDir.pathname); File[] items = dir.listFiles(); // process normal files if (items != null) { for (File f : items) { // check whether file is a link if (Engine.isLink(f.getAbsolutePath()) != null) { log.w("skipping " + f + " because it's a link"); continue; } if (!f.isDirectory()) { // regular file if (f.getName().startsWith(".")) continue; // treat files beginning with '.' as hidden if (f.getName().equalsIgnoreCase("LOST.DIR")) continue; // system directory String pathName = f.getAbsolutePath(); if (knownItems != null && knownItems.contains(pathName)) continue; if (engine.isRootsMountPoint(pathName)) { // skip mount root continue; } boolean isZip = pathName.toLowerCase().endsWith(".zip"); FileInfo item = mFileList.get(pathName); boolean isNew = false; if (item == null) { item = new FileInfo(f); if (isZip) { item = scanZip(item); if (item == null) continue; if (item.isDirectory) { // many supported files in ZIP item.parent = baseDir; baseDir.addDir(item); for (int i = 0; i < item.fileCount(); i++) { FileInfo file = item.getFile(i); mFileList.put(file.getPathName(), file); } } else { item.parent = baseDir; baseDir.addFile(item); mFileList.put(pathName, item); } continue; } isNew = true; } if (item.format != null) { item.parent = baseDir; baseDir.addFile(item); if (isNew) mFileList.put(pathName, item); } } } // process directories for (File f : items) { if (f.isDirectory()) { if (f.getName().startsWith(".")) continue; // treat dirs beginning with '.' as hidden FileInfo item = new FileInfo(f); if (knownItems != null && knownItems.contains(item.getPathName())) continue; item.parent = baseDir; baseDir.addDir(item); } } } baseDir.isListed = true; return !baseDir.isEmpty(); } catch (Exception e) { L.e("Exception while listing directory " + baseDir.pathname, e); baseDir.isListed = true; return false; } }