]>
git.saurik.com Git - android/aapt.git/blob - CrunchCache.h
2 // Copyright 2011 The Android Open Source Project
4 // Cache manager for pre-processed PNG files.
5 // Contains code for managing which PNG files get processed
12 #include <utils/KeyedVector.h>
13 #include <utils/String8.h>
14 #include "FileFinder.h"
15 #include "CacheUpdater.h"
17 using namespace android
;
20 * This class is a cache manager which can pre-process PNG files and store
21 * them in a mirror-cache. It's capable of doing incremental updates to its
25 * Create an instance initialized with the root of the source tree, the
26 * root location to store the cache files, and an instance of a file finder.
27 * Then update the cache by calling crunch.
32 CrunchCache(String8 sourcePath
, String8 destPath
, FileFinder
* ff
);
34 // Nobody should be calling the default constructor
35 // So this space is intentionally left blank
37 // Default Copy Constructor and Destructor are fine
39 /** crunch is the workhorse of this class.
40 * It goes through all the files found in the sourcePath and compares
41 * them to the cached versions in the destPath. If the optional
42 * argument forceOverwrite is set to true, then all source files are
43 * re-crunched even if they have not been modified recently. Otherwise,
44 * source files are only crunched when they needUpdating. Afterwards,
45 * we delete any leftover files in the cache that are no longer present
49 * No setup besides construction is needed
51 * The cache is updated to fully reflect all changes in source.
52 * The function then returns the number of files changed in cache
53 * (counting deletions).
55 size_t crunch(CacheUpdater
* cu
, bool forceOverwrite
=false);
58 /** loadFiles is a wrapper to the FileFinder that places matching
59 * files into mSourceFiles and mDestFiles.
62 * mDestFiles and mSourceFiles are refreshed to reflect the current
63 * state of the files in the source and dest directories.
64 * Any previous contents of mSourceFiles and mDestFiles are cleared.
68 /** needsUpdating takes a file path
69 * and returns true if the file represented by this path is newer in the
70 * sourceFiles than in the cache (mDestFiles).
73 * mSourceFiles and mDestFiles must be initialized and filled.
75 * returns true if and only if source file's modification time
76 * is greater than the cached file's mod-time. Otherwise returns false.
79 * Should be used something like the following:
80 * if (needsUpdating(filePath))
81 * // Recrunch sourceFile out to destFile.
84 bool needsUpdating(String8 relativePath
) const;
86 // DATA MEMBERS ====================================================
91 Vector
<String8
> mExtensions
;
93 // Each vector of paths contains one entry per PNG file encountered.
94 // Each entry consists of a path pointing to that PNG.
95 DefaultKeyedVector
<String8
,time_t> mSourceFiles
;
96 DefaultKeyedVector
<String8
,time_t> mDestFiles
;
98 // Pointer to a FileFinder to use
99 FileFinder
* mFileFinder
;
102 #endif // CRUNCHCACHE_H