diff options
Diffstat (limited to '')
-rw-r--r-- | src/cache.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/cache.cpp b/src/cache.cpp index 1646d0a..de505b8 100644 --- a/src/cache.cpp +++ b/src/cache.cpp | |||
@@ -1,14 +1,18 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | #include <bu/file.h> | 2 | #include <bu/file.h> |
3 | #include <bu/archive.h> | 3 | #include <bu/archive.h> |
4 | #include <bu/sio.h> | ||
5 | using namespace Bu; | ||
4 | 6 | ||
5 | Cache::Cache() : | 7 | Cache::Cache() : |
8 | bCacheChanged( false ), | ||
6 | bIsLoaded( false ) | 9 | bIsLoaded( false ) |
7 | { | 10 | { |
8 | } | 11 | } |
9 | 12 | ||
10 | Cache::~Cache() | 13 | Cache::~Cache() |
11 | { | 14 | { |
15 | save(); | ||
12 | } | 16 | } |
13 | 17 | ||
14 | void Cache::bind( const Bu::FString &sCacheFile ) | 18 | void Cache::bind( const Bu::FString &sCacheFile ) |
@@ -21,19 +25,40 @@ void Cache::load() | |||
21 | { | 25 | { |
22 | if( bIsLoaded ) | 26 | if( bIsLoaded ) |
23 | return; | 27 | return; |
24 | Bu::File fIn( sCacheFile, Bu::File::Read ); | ||
25 | Bu::Archive ar( fIn, Bu::Archive::load ); | ||
26 | 28 | ||
27 | ar >> hRequires >> hVariables; | 29 | try |
30 | { | ||
31 | Bu::File fIn( sCacheFile, Bu::File::Read ); | ||
32 | Bu::Archive ar( fIn, Bu::Archive::load ); | ||
33 | |||
34 | ar >> hRequires >> hVariables; | ||
35 | } | ||
36 | catch(...) { } | ||
28 | 37 | ||
29 | bIsLoaded = true; | 38 | bIsLoaded = true; |
30 | } | 39 | } |
31 | 40 | ||
32 | void Cache::save() | 41 | void Cache::save() |
33 | { | 42 | { |
43 | if( !bIsLoaded ) | ||
44 | return; | ||
45 | if( bCacheChanged == false ) | ||
46 | return; | ||
47 | |||
34 | Bu::File fIn( sCacheFile, Bu::File::WriteNew ); | 48 | Bu::File fIn( sCacheFile, Bu::File::WriteNew ); |
35 | Bu::Archive ar( fIn, Bu::Archive::save ); | 49 | Bu::Archive ar( fIn, Bu::Archive::save ); |
36 | 50 | ||
37 | ar << hRequires << hVariables; | 51 | ar << hRequires << hVariables; |
38 | } | 52 | } |
39 | 53 | ||
54 | StrList Cache::getRequires( const Bu::FString &sOutput ) | ||
55 | { | ||
56 | return hRequires.get( sOutput ); | ||
57 | } | ||
58 | |||
59 | void Cache::setRequires( const Bu::FString &sOutput, StrList lReqs ) | ||
60 | { | ||
61 | hRequires.insert( sOutput, lReqs ); | ||
62 | bCacheChanged = true; | ||
63 | } | ||
64 | |||