| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns the total aggregate log size for a contact. For meta-contacts, the |
| 96 | * total log file size of all sub-contacts is returned. If no log exists or if |
| 97 | * something else goes wrong, 0 is returned. |
| 98 | * |
| 99 | * @param listObject an AIListContact for which to retrieve a total log file size |
| 100 | * @return the total log file size in bytes or 0 if an error occurred |
| 101 | */ |
| 102 | +(unsigned long long)getContactLogSize:(AIListContact *)listObject |
| 103 | { |
| 104 | NSFileManager *fileManager = [NSFileManager defaultManager]; |
| 105 | |
| 106 | if([listObject isMemberOfClass:[AIMetaContact class]]) |
| 107 | { |
| 108 | // Recurse through all sub-contacts |
| 109 | |
| 110 | id contact; |
| 111 | unsigned long long size = 0; |
| 112 | |
| 113 | NSEnumerator *contactEnumerator = [[listObject listContacts] objectEnumerator]; |
| 114 | |
| 115 | while(contact = [contactEnumerator nextObject]) |
| 116 | { |
| 117 | size += [AILogSizeSort getContactLogSize:contact]; |
| 118 | } |
| 119 | |
| 120 | return size; |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | // Find the path to the directory containing the log files for this contact |
| 125 | NSString *path = [[AILoggerPlugin logBasePath] stringByAppendingPathComponent:[AILoggerPlugin relativePathForLogWithObject:[listObject UID] onAccount: [listObject account]]]; |
| 126 | |
| 127 | // Grab an enumerator for all log files for this contact |
| 128 | NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:path]; |
| 129 | NSString *file; |
| 130 | |
| 131 | unsigned long long size = 0; |
| 132 | |
| 133 | while(file = [dirEnum nextObject]) |
| 134 | { |
| 135 | NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:[path stringByAppendingPathComponent:file] traverseLink:YES]; |
| 136 | |
| 137 | if (fileAttributes != nil) |
| 138 | { |
| 139 | NSNumber *fileSize; |
| 140 | if(fileSize = [fileAttributes objectForKey:NSFileSize]) |
| 141 | { |
| 142 | size += [fileSize unsignedLongLongValue]; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return size; |
| 148 | } |
134 | | |
135 | | +(unsigned long long)getContactLogSize:(AIListContact *)listObject |
136 | | { |
137 | | NSFileManager *fileManager = [NSFileManager defaultManager]; |
138 | | |
139 | | if([listObject isMemberOfClass:[AIMetaContact class]]) |
140 | | { |
141 | | unsigned long long size = 0; |
142 | | |
143 | | NSEnumerator *contactEnumerator = [[listObject listContacts] objectEnumerator]; |
144 | | |
145 | | id contact; |
146 | | |
147 | | while(contact = [contactEnumerator nextObject]) |
148 | | { |
149 | | size += [AILogSizeSort getContactLogSize:contact]; |
150 | | } |
151 | | |
152 | | return size; |
153 | | } |
154 | | else |
155 | | { |
156 | | NSString *path = [[AILoggerPlugin logBasePath] stringByAppendingPathComponent:[AILoggerPlugin relativePathForLogWithObject:[listObject UID] onAccount: [listObject account]]]; |
157 | | |
158 | | NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:path]; |
159 | | NSString *file; |
160 | | |
161 | | unsigned long long size = 0; |
162 | | |
163 | | while(file = [dirEnum nextObject]) |
164 | | { |
165 | | NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:[path stringByAppendingPathComponent:file] traverseLink:YES]; |
166 | | |
167 | | if (fileAttributes != nil) |
168 | | { |
169 | | NSNumber *fileSize; |
170 | | if(fileSize = [fileAttributes objectForKey:NSFileSize]) |
171 | | { |
172 | | size += [fileSize unsignedLongLongValue]; |
173 | | } |
174 | | } |
175 | | } |
176 | | |
177 | | return size; |
178 | | } |
179 | | } |
180 | | |