summaryrefslogtreecommitdiffstats
path: root/tools/aapt/FileFinder.cpp
diff options
context:
space:
mode:
authorJosiah Gaskin <josiahgaskin@google.com>2011-06-06 17:00:35 -0700
committerJosiah Gaskin <josiahgaskin@google.com>2011-07-20 15:20:26 -0700
commit8a39da80b33691b0c82458c3b7727e13ff71277e (patch)
treeb6fa94370ecb2dba85d5fdb45c83729cef8708e1 /tools/aapt/FileFinder.cpp
parent1e24ccbdd56a45c8bb5f2eba94af5aecd2d02554 (diff)
downloadframeworks_base-8a39da80b33691b0c82458c3b7727e13ff71277e.zip
frameworks_base-8a39da80b33691b0c82458c3b7727e13ff71277e.tar.gz
frameworks_base-8a39da80b33691b0c82458c3b7727e13ff71277e.tar.bz2
Added Caching for PreProcessed PNGs
Added a cache management system for pre-processed PNG files along with unit tests. The cache system will be used if the --no-crunch flag is passed to AAPT during the package phase. The cache can be updated by a call to 'aapt crunch' (see usage statement). Also put in benchmarking code. Change-Id: I58271fb2ee2f5f9075fd74d4ff6f15e7afabd05c
Diffstat (limited to 'tools/aapt/FileFinder.cpp')
-rw-r--r--tools/aapt/FileFinder.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/tools/aapt/FileFinder.cpp b/tools/aapt/FileFinder.cpp
new file mode 100644
index 0000000..a1f64d0
--- /dev/null
+++ b/tools/aapt/FileFinder.cpp
@@ -0,0 +1,92 @@
+//
+// Copyright 2011 The Android Open Source Project
+//
+
+// File Finder implementation.
+// Implementation for the functions declared and documented in FileFinder.h
+
+#include <utils/Vector.h>
+#include <utils/String8.h>
+#include <utils/KeyedVector.h>
+
+
+#include <iostream>
+
+#include "DirectoryWalker.h"
+#include "FileFinder.h"
+
+//#define DEBUG
+
+using android::String8;
+using std::cout;
+using std::endl;
+
+bool SystemFileFinder::findFiles(String8 basePath, Vector<String8>& extensions,
+ KeyedVector<String8,time_t>& fileStore,
+ DirectoryWalker* dw)
+{
+ // Scan the directory pointed to by basePath
+ // check files and recurse into subdirectories.
+ if (!dw->openDir(basePath)) {
+ return false;
+ }
+#ifdef DEBUG
+ cout << "FileFinder looking in " << basePath << endl;
+#endif // DEBUG
+ /*
+ * Go through all directory entries. Check each file using checkAndAddFile
+ * and recurse into sub-directories.
+ */
+ struct dirent* entry;
+ while ((entry = dw->nextEntry()) != NULL) {
+ String8 entryName(entry->d_name);
+ if (entry->d_name[0] == '.') // Skip hidden files and directories
+ continue;
+
+ String8 fullPath = basePath.appendPathCopy(entryName);
+ // If this entry is a directory we'll recurse into it
+ if (entry->d_type == DT_DIR) {
+ DirectoryWalker* copy = dw->clone();
+ findFiles(fullPath, extensions, fileStore,copy);
+ delete copy;
+ }
+
+ // If this entry is a file, we'll pass it over to checkAndAddFile
+ if (entry->d_type == DT_REG) {
+ checkAndAddFile(fullPath,dw->entryStats(),extensions,fileStore);
+ }
+ }
+
+ // Clean up
+ dw->closeDir();
+
+ return true;
+}
+
+void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats,
+ Vector<String8>& extensions,
+ KeyedVector<String8,time_t>& fileStore)
+{
+#ifdef DEBUG
+ cout << "Checking file " << path << "...";
+#endif // DEBUG
+ // Loop over the extensions, checking for a match
+ bool done = false;
+ String8 ext(path.getPathExtension());
+ ext.toLower();
+ for (size_t i = 0; i < extensions.size() && !done; ++i) {
+ String8 ext2 = extensions[i].getPathExtension();
+ ext2.toLower();
+ // Compare the extensions. If a match is found, add to storage.
+ if (ext == ext2) {
+#ifdef DEBUG
+ cout << "Match";
+#endif // DEBUG
+ done = true;
+ fileStore.add(path,stats->st_mtime);
+ }
+ }
+#ifdef DEBUG
+ cout << endl;
+#endif //DEBUG
+} \ No newline at end of file