]>
git.saurik.com Git - android/aapt.git/blob - FileFinder.h
   2 // Copyright 2011 The Android Open Source Project 
   6 // This is a collection of useful functions for finding paths and modification 
   7 // times of files that match an extension pattern in a directory tree. 
   8 // and finding files in it. 
  13 #include <utils/Vector.h> 
  14 #include <utils/KeyedVector.h> 
  15 #include <utils/String8.h> 
  17 #include "DirectoryWalker.h" 
  19 using namespace android
; 
  21 // Abstraction to allow for dependency injection. See MockFileFinder.h 
  22 // for the testing implementation. 
  25     virtual bool findFiles(String8 basePath
, Vector
<String8
>& extensions
, 
  26                            KeyedVector
<String8
,time_t>& fileStore
, 
  27                            DirectoryWalker
* dw
) = 0; 
  30 class SystemFileFinder 
: public FileFinder 
{ 
  33     /* findFiles takes a path, a Vector of extensions, and a destination KeyedVector 
  34      *           and places path/modification date key/values pointing to 
  35      *          all files with matching extensions found into the KeyedVector 
  37      *     path is a valid system path 
  38      *     extensions should include leading "." 
  39      *                This is not necessary, but the comparison directly 
  40      *                compares the end of the path string so if the "." 
  41      *                is excluded there is a small chance you could have 
  42      *                a false positive match. (For example: extension "png" 
  43      *                would match a file called "blahblahpng") 
  46      *     fileStore contains (in no guaranteed order) paths to all 
  47      *                matching files encountered in subdirectories of path 
  48      *                as keys in the KeyedVector. Each key has the modification time 
  49      *                of the file as its value. 
  51      * Calls checkAndAddFile on each file encountered in the directory tree 
  52      * Recursively descends into subdirectories. 
  54     virtual bool findFiles(String8 basePath
, Vector
<String8
>& extensions
, 
  55                            KeyedVector
<String8
,time_t>& fileStore
, 
  60      * checkAndAddFile looks at a single file path and stat combo 
  61      * to determine whether it is a matching file (by looking at 
  68      *    If the given file has a matching extension then a new entry 
  69      *    is added to the KeyedVector with the path as the key and the modification 
  73     static void checkAndAddFile(String8 path
, const struct stat
* stats
, 
  74                                 Vector
<String8
>& extensions
, 
  75                                 KeyedVector
<String8
,time_t>& fileStore
); 
  78 #endif // FILEFINDER_H