Beispiel #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;
 }
Beispiel #2
0
 /**
  * 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;
   }
 }