Skip to content

Commit ca3f719

Browse files
committed
Add cache size for disk.
fix xhzengAIB#82
1 parent 1a19ee8 commit ca3f719

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

Example/MessageDisplayExample/MessageDisplayExample.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@
522522
ABB777181932A27B00F4ACAF /* XHVideoOutputSampleBufferFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = ABB777151932A27B00F4ACAF /* XHVideoOutputSampleBufferFactory.m */; };
523523
ABB7771C1932A7D700F4ACAF /* Contact_Female@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = ABB7771A1932A7D700F4ACAF /* Contact_Female@2x.png */; };
524524
ABB7771D1932A7D700F4ACAF /* Contact_Male@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = ABB7771B1932A7D700F4ACAF /* Contact_Male@2x.png */; };
525+
ABB839E9193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.h in Headers */ = {isa = PBXBuildFile; fileRef = ABB839E7193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.h */; };
526+
ABB839EA193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m in Sources */ = {isa = PBXBuildFile; fileRef = ABB839E8193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m */; };
527+
ABB839EB193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m in Sources */ = {isa = PBXBuildFile; fileRef = ABB839E8193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m */; };
525528
ABCB35AB19342DFA002F9938 /* VoiceSearchBtn@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = ABCB356719342DFA002F9938 /* VoiceSearchBtn@2x.png */; };
526529
ABCB35AC19342DFA002F9938 /* VoiceSearchBtn_ios7@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = ABCB356819342DFA002F9938 /* VoiceSearchBtn_ios7@2x.png */; };
527530
ABCB35AD19342DFA002F9938 /* VoiceSearchBtnHL@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = ABCB356919342DFA002F9938 /* VoiceSearchBtnHL@2x.png */; };
@@ -1050,6 +1053,8 @@
10501053
ABB777151932A27B00F4ACAF /* XHVideoOutputSampleBufferFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHVideoOutputSampleBufferFactory.m; sourceTree = "<group>"; };
10511054
ABB7771A1932A7D700F4ACAF /* Contact_Female@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Contact_Female@2x.png"; sourceTree = "<group>"; };
10521055
ABB7771B1932A7D700F4ACAF /* Contact_Male@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Contact_Male@2x.png"; sourceTree = "<group>"; };
1056+
ABB839E7193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+XHDiskSizeTransfrom.h"; sourceTree = "<group>"; };
1057+
ABB839E8193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+XHDiskSizeTransfrom.m"; sourceTree = "<group>"; };
10531058
ABCB356719342DFA002F9938 /* VoiceSearchBtn@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "VoiceSearchBtn@2x.png"; sourceTree = "<group>"; };
10541059
ABCB356819342DFA002F9938 /* VoiceSearchBtn_ios7@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "VoiceSearchBtn_ios7@2x.png"; sourceTree = "<group>"; };
10551060
ABCB356919342DFA002F9938 /* VoiceSearchBtnHL@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "VoiceSearchBtnHL@2x.png"; sourceTree = "<group>"; };
@@ -2135,6 +2140,8 @@
21352140
AB6AB483193C03D600AFE823 /* NSString+MessageInputView.m */,
21362141
AB6AB484193C03D600AFE823 /* NSString+XHMD5.h */,
21372142
AB6AB485193C03D600AFE823 /* NSString+XHMD5.m */,
2143+
ABB839E7193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.h */,
2144+
ABB839E8193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m */,
21382145
);
21392146
path = NSString;
21402147
sourceTree = "<group>";
@@ -2614,6 +2621,7 @@
26142621
AB6AB4B9193C03D600AFE823 /* UIScrollView+XHkeyboardControl.h in Headers */,
26152622
AB6AB4B0193C03D600AFE823 /* UIImage+Utility.h in Headers */,
26162623
AB6AB4A1193C03D600AFE823 /* NSString+XHMD5.h in Headers */,
2624+
ABB839E9193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.h in Headers */,
26172625
AB6AB4AD193C03D600AFE823 /* UIImage+RoundedCorner.h in Headers */,
26182626
ABB777161932A27B00F4ACAF /* XHVideoOutputSampleBufferFactory.h in Headers */,
26192627
AB72638919328D9A00AA738F /* XHLocationServiceTableViewCell.h in Headers */,
@@ -3142,6 +3150,7 @@
31423150
AB63BF191936B35500B6C977 /* XHNewsTemplateTableViewCell.m in Sources */,
31433151
746C897F1917F8C5007F9A5E /* XHBaseTabBarController.m in Sources */,
31443152
746C89491917F691007F9A5E /* XHEmotionCollectionViewFlowLayout.m in Sources */,
3153+
ABB839EB193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m in Sources */,
31453154
74E900B51928F3D100D37C81 /* XHStoreManager.m in Sources */,
31463155
AB5493981931102E001F2FCC /* XHContactPhotosTableViewCell.m in Sources */,
31473156
AB73B1671932463E009665E3 /* XHScanningView.m in Sources */,
@@ -3240,6 +3249,7 @@
32403249
74E5EAF21924FFBE0084BCFA /* SETextSelectionView.m in Sources */,
32413250
746C89421917F691007F9A5E /* XHMessageTextView.m in Sources */,
32423251
74065FBA19123E1C00E1CE95 /* XHShareMenuItem.m in Sources */,
3252+
ABB839EA193CCACA003DEE7A /* NSString+XHDiskSizeTransfrom.m in Sources */,
32433253
ABB777171932A27B00F4ACAF /* XHVideoOutputSampleBufferFactory.m in Sources */,
32443254
AB79A20E192C0A6400A9B951 /* XHPathCover.m in Sources */,
32453255
74E5EAE31924FFBE0084BCFA /* SETextInput.m in Sources */,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// NSString+XHDiskSizeTransfrom.h
3+
// MessageDisplayExample
4+
//
5+
// Created by 曾 宪华 on 14-6-2.
6+
// Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface NSString (XHDiskSizeTransfrom)
12+
13+
+ (NSString *)transformedValue:(long long)value;
14+
15+
@end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// NSString+XHDiskSizeTransfrom.m
3+
// MessageDisplayExample
4+
//
5+
// Created by 曾 宪华 on 14-6-2.
6+
// Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved.
7+
//
8+
9+
#import "NSString+XHDiskSizeTransfrom.h"
10+
11+
@implementation NSString (XHDiskSizeTransfrom)
12+
13+
+ (NSString *)transformedValue:(long long)value {
14+
double convertedValue = value;
15+
int multiplyFactor = 0;
16+
17+
NSArray *tokens = [NSArray arrayWithObjects:@"bytes", @"KB", @"MB", @"GB", @"TB", nil];
18+
19+
while (convertedValue > 1024) {
20+
convertedValue /= 1024;
21+
multiplyFactor++;
22+
}
23+
24+
return [NSString stringWithFormat:@"%4.2f %@",convertedValue, [tokens objectAtIndex:multiplyFactor]];
25+
}
26+
27+
@end

MessageDisplayKit/Classes/Core/Cache/XHCacheManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
+ (void)removeCacheDirectory;
2525
- (void)removeCacheDirectory;
2626

27+
+ (unsigned long long)diskSize;
28+
- (unsigned long long)diskSize;
29+
2730
// NSData caching
2831
+ (void)storeData:(NSData *)data forURL:(NSURL *)url storeMemoryCache:(BOOL)storeMemoryCache;
2932
- (void)storeData:(NSData *)data forURL:(NSURL *)url storeMemoryCache:(BOOL)storeMemoryCache;

MessageDisplayKit/Classes/Core/Cache/XHCacheManager.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ - (void)removeCacheDirectory {
169169
_cacheDirectoryPath = nil;
170170
}
171171

172+
- (unsigned long long)diskSize {
173+
long long diskSize = 0;
174+
NSFileManager *fileManager = [NSFileManager defaultManager];
175+
NSError *error;
176+
NSArray *contents = [fileManager contentsOfDirectoryAtPath:[self _cacheDirectory] error:&error];
177+
if (!contents) {
178+
NSLog(@"Failed to list directory with error %@", error);
179+
return diskSize;
180+
}
181+
for (NSString *pathComponent in contents) {
182+
NSString *path = [[self _cacheDirectory] stringByAppendingPathComponent:pathComponent];
183+
NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:&error];
184+
if (!attributes) continue;
185+
186+
diskSize += attributes.fileSize;
187+
}
188+
return diskSize;
189+
}
190+
172191
#pragma mark- NSData caching
173192

174193
- (void)storeData:(NSData *)data forURL:(NSURL *)url storeMemoryCache:(BOOL)storeMemoryCache {
@@ -283,6 +302,10 @@ + (void)removeCacheDirectory {
283302
[self.manager removeCacheDirectory];
284303
}
285304

305+
+ (unsigned long long)diskSize {
306+
return [self.manager diskSize];
307+
}
308+
286309
+ (void)storeData:(NSData *)data forURL:(NSURL *)url storeMemoryCache:(BOOL)storeMemoryCache {
287310
[self.manager storeData:data forURL:url storeMemoryCache:storeMemoryCache];
288311
}

MessageDisplayKit/Classes/Models/XHStoreManager.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#import "XHContact.h"
1212
#import "XHAlbum.h"
1313

14+
#import "XHCacheManager.h"
15+
16+
#import "NSString+XHDiskSizeTransfrom.h"
17+
1418
@implementation XHStoreManager
1519

1620
+ (instancetype)shareStoreManager {
@@ -224,7 +228,7 @@ - (NSMutableArray *)getSettingConfigureArray {
224228

225229
[settings addObject:@[@{titleKey: @"新消息通知"}, @{titleKey: @"隐私"}, @{titleKey: @"通用"}]];
226230

227-
[settings addObject:@[@{titleKey: @"关于微信"}]];
231+
[settings addObject:@[@{titleKey: @"关于微信"}, @{titleKey: [NSString stringWithFormat:@"离线缓存大小 %@", [NSString transformedValue:[XHCacheManager diskSize]]]}]];
228232

229233
[settings addObject:@[@{titleKey: @"退出登录"}]];
230234

0 commit comments

Comments
 (0)