blob: be3da5c40b255aea9ae9681fb7d47e96db56b7a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
//
// Copyright 2011 The Android Open Source Project
//
// Cache manager for pre-processed PNG files.
// Contains code for managing which PNG files get processed
// at build time.
//
#ifndef CRUNCHCACHE_H
#define CRUNCHCACHE_H
#include <utils/KeyedVector.h>
#include <utils/String8.h>
#include "FileFinder.h"
#include "CacheUpdater.h"
using namespace android;
/** CrunchCache
* This class is a cache manager which can pre-process PNG files and store
* them in a mirror-cache. It's capable of doing incremental updates to its
* cache.
*
* Usage:
* Create an instance initialized with the root of the source tree, the
* root location to store the cache files, and an instance of a file finder.
* Then update the cache by calling crunch.
*/
class CrunchCache {
public:
// Constructor
CrunchCache(String8 sourcePath, String8 destPath, FileFinder* ff);
// Nobody should be calling the default constructor
// So this space is intentionally left blank
// Default Copy Constructor and Destructor are fine
/** crunch is the workhorse of this class.
* It goes through all the files found in the sourcePath and compares
* them to the cached versions in the destPath. If the optional
* argument forceOverwrite is set to true, then all source files are
* re-crunched even if they have not been modified recently. Otherwise,
* source files are only crunched when they needUpdating. Afterwards,
* we delete any leftover files in the cache that are no longer present
* in source.
*
* PRECONDITIONS:
* No setup besides construction is needed
* POSTCONDITIONS:
* The cache is updated to fully reflect all changes in source.
* The function then returns the number of files changed in cache
* (counting deletions).
*/
size_t crunch(CacheUpdater* cu, bool forceOverwrite=false);
private:
/** loadFiles is a wrapper to the FileFinder that places matching
* files into mSourceFiles and mDestFiles.
*
* POSTCONDITIONS
* mDestFiles and mSourceFiles are refreshed to reflect the current
* state of the files in the source and dest directories.
* Any previous contents of mSourceFiles and mDestFiles are cleared.
*/
void loadFiles();
/** needsUpdating takes a file path
* and returns true if the file represented by this path is newer in the
* sourceFiles than in the cache (mDestFiles).
*
* PRECONDITIONS:
* mSourceFiles and mDestFiles must be initialized and filled.
* POSTCONDITIONS:
* returns true if and only if source file's modification time
* is greater than the cached file's mod-time. Otherwise returns false.
*
* USAGE:
* Should be used something like the following:
* if (needsUpdating(filePath))
* // Recrunch sourceFile out to destFile.
*
*/
bool needsUpdating(String8 relativePath) const;
// DATA MEMBERS ====================================================
String8 mSourcePath;
String8 mDestPath;
Vector<String8> mExtensions;
// Each vector of paths contains one entry per PNG file encountered.
// Each entry consists of a path pointing to that PNG.
DefaultKeyedVector<String8,time_t> mSourceFiles;
DefaultKeyedVector<String8,time_t> mDestFiles;
// Pointer to a FileFinder to use
FileFinder* mFileFinder;
};
#endif // CRUNCHCACHE_H
|