-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTCDiskKit.m
59 lines (46 loc) · 1.88 KB
/
TTCDiskKit.m
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
//
// TTCDiskKit.m
// Drive
//
// Created by will strimling on 8/5/10.
// Copyright 2010 TapTouchClick - Will Strimling. All rights reserved.
//
#import "TTCDiskKit.h"
@implementation TTCDiskKit
+(NSString *)gigabytesFromBytes:(float)bytes {
float kilobytes = bytes/1024.0;
float megabytes = kilobytes/1024.0;
float gigabytes = megabytes/1024.0;
return [NSString stringWithFormat:@"%.2f",gigabytes];
}
+(NSString *)totalSpace {
float bytes = 0.0f;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
bytes = [fileSystemSizeInBytes floatValue];
} else {
NSLog(@"Error Obtaining File System Info: Domain = %@, Code = %@", [error domain], [error code]);
}
return [self gigabytesFromBytes:bytes];
}
+(NSString *)takenSpace {
float bytes = ([[self totalSpace]floatValue])-([[self freeSpace]floatValue]);
return [NSString stringWithFormat:@"%.2f",bytes];
}
+(NSString *)freeSpace {
float bytes = 0.0f;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];
bytes = [fileSystemSizeInBytes floatValue];
} else {
NSLog(@"Error Obtaining File System Info: Domain = %@, Code = %@", [error domain], [error code]);
}
return [self gigabytesFromBytes:bytes];
}
@end