The cache size did not include the media one (it was only the Matrix SDK one)

This commit is contained in:
ylecollen 2015-01-09 17:14:09 +01:00
parent c0abd65b0d
commit 2a97155f44
5 changed files with 54 additions and 2 deletions

View file

@ -50,6 +50,7 @@ extern NSString *const kMediaDownloadDidFailNotification;
+ (NSString *)cacheMediaData:(NSData *)mediaData forURL:(NSString *)mediaURL mimeType:(NSString *)mimeType;
+ (NSUInteger)cacheSize;
+ (void)clearCache;
@end

View file

@ -207,6 +207,45 @@ static NSMutableDictionary* pendingMediaLoadersByURL = nil;
mediaCachePath = nil;
}
// recursive method to compute the folder content size
+ (long long)folderSize:(NSString *)folderPath
{
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderPath error:nil];
NSEnumerator *contentsEnumurator = [contents objectEnumerator];
NSString *file;
unsigned long long int folderSize = 0;
while (file = [contentsEnumurator nextObject])
{
NSString* itemPath = [folderPath stringByAppendingPathComponent:file];
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:itemPath error:nil];
// is directory
if ([[fileAttributes objectForKey:NSFileType] isEqual:NSFileTypeDirectory])
{
folderSize += [MediaManager folderSize:itemPath];
}
else
{
folderSize += [[fileAttributes objectForKey:NSFileSize] intValue];
}
}
return folderSize;
}
+ (NSUInteger)cacheSize {
if (!mediaCachePath) {
// compute the path
mediaCachePath = [MediaManager getCachePath];
}
return (NSUInteger)[MediaManager folderSize:mediaCachePath];
}
#pragma mark - Cache handling
+ (UIImage*)loadCachePicture:(NSString*)pictureURL {

View file

@ -49,6 +49,8 @@ typedef enum : NSUInteger {
@property (nonatomic,readonly) BOOL isResumeDone;
// return the MX cache size in bytes
@property (nonatomic,readonly) NSUInteger MXCacheSize;
// return the sum of the caches (MX cache + media cache ...)
@property (nonatomic,readonly) NSUInteger cachesSize;
+ (MatrixHandler *)sharedHandler;

View file

@ -22,6 +22,8 @@
#import "MXFileStore.h"
#import "MXTools.h"
#import "MediaManager.h"
NSString *const kMatrixHandlerUnsupportedMessagePrefix = @"UNSUPPORTED MSG: ";
static MatrixHandler *sharedHandler = nil;
@ -280,6 +282,9 @@ static MatrixHandler *sharedHandler = nil;
[[AppDelegate theDelegate].masterTabBarController popRoomViewControllerAnimated:NO];
if (clearCache) {
// clear the media cache
[MediaManager clearCache];
[_mxFileStore deleteAllData];
}
@ -787,7 +792,7 @@ static MatrixHandler *sharedHandler = nil;
return nil;
}
-(NSUInteger) MXCacheSize {
- (NSUInteger) MXCacheSize {
if (self.mxFileStore) {
return self.mxFileStore.diskUsage;
@ -796,6 +801,10 @@ static MatrixHandler *sharedHandler = nil;
return 0;
}
- (NSUInteger) cachesSize {
return self.MXCacheSize + [MediaManager cacheSize];
}
- (CGFloat)getPowerLevel:(MXRoomMember *)roomMember inRoom:(MXRoom *)room {
CGFloat powerLevel = 0;

View file

@ -658,6 +658,7 @@ NSString* const kCommandsDescriptionText = @"The following commands are availabl
if (self.tableView == aTableView) {
// tap on clear application cache
if ((indexPath.section == SETTINGS_SECTION_ROOMS_INDEX) && (indexPath.row == SETTINGS_SECTION_ROOMS_CLEAR_CACHE_INDEX)) {
// clear caches
[[MatrixHandler sharedHandler] forceInitialSync:YES];
}
@ -807,7 +808,7 @@ NSString* const kCommandsDescriptionText = @"The following commands are availabl
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ClearCacheCell"];
}
cell.textLabel.text = [NSString stringWithFormat:@"Clear cache (%@)", [NSByteCountFormatter stringFromByteCount:[MatrixHandler sharedHandler].MXCacheSize countStyle:NSByteCountFormatterCountStyleFile]];
cell.textLabel.text = [NSString stringWithFormat:@"Clear cache (%@)", [NSByteCountFormatter stringFromByteCount:[MatrixHandler sharedHandler].cachesSize countStyle:NSByteCountFormatterCountStyleFile]];
;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [AppDelegate theDelegate].masterTabBarController.tabBar.tintColor;