]>
git.saurik.com Git - android/aapt.git/blob - FileFinder.cpp
   2 // Copyright 2011 The Android Open Source Project 
   5 // File Finder implementation. 
   6 // Implementation for the functions declared and documented in FileFinder.h 
   8 #include <utils/Vector.h> 
   9 #include <utils/String8.h> 
  10 #include <utils/KeyedVector.h> 
  15 #include "DirectoryWalker.h" 
  16 #include "FileFinder.h" 
  20 using android::String8
; 
  24 bool SystemFileFinder::findFiles(String8 basePath
, Vector
<String8
>& extensions
, 
  25                                  KeyedVector
<String8
,time_t>& fileStore
, 
  28     // Scan the directory pointed to by basePath 
  29     // check files and recurse into subdirectories. 
  30     if (!dw
->openDir(basePath
)) { 
  34     cout 
<< "FileFinder looking in " << basePath 
<< endl
; 
  37      *  Go through all directory entries. Check each file using checkAndAddFile 
  38      *  and recurse into sub-directories. 
  41     while ((entry 
= dw
->nextEntry()) != NULL
) { 
  42         String8 
entryName(entry
->d_name
); 
  43         if (entry
->d_name
[0] == '.') // Skip hidden files and directories 
  46         String8 fullPath 
= basePath
.appendPathCopy(entryName
); 
  47         // If this entry is a directory we'll recurse into it 
  48         if (entry
->d_type 
== DT_DIR
) { 
  49             DirectoryWalker
* copy 
= dw
->clone(); 
  50             findFiles(fullPath
, extensions
, fileStore
,copy
); 
  54         // If this entry is a file, we'll pass it over to checkAndAddFile 
  55         if (entry
->d_type 
== DT_REG
) { 
  56             checkAndAddFile(fullPath
,dw
->entryStats(),extensions
,fileStore
); 
  66 void SystemFileFinder::checkAndAddFile(String8 path
, const struct stat
* stats
, 
  67                                        Vector
<String8
>& extensions
, 
  68                                        KeyedVector
<String8
,time_t>& fileStore
) 
  71     cout 
<< "Checking file " << path 
<< "..."; 
  73     // Loop over the extensions, checking for a match 
  75     String8 
ext(path
.getPathExtension()); 
  77     for (size_t i 
= 0; i 
< extensions
.size() && !done
; ++i
) { 
  78         String8 ext2 
= extensions
[i
].getPathExtension(); 
  80         // Compare the extensions. If a match is found, add to storage. 
  86             fileStore
.add(path
,stats
->st_mtime
);