-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDBMetadata.m
More file actions
126 lines (109 loc) · 4.44 KB
/
DBMetadata.m
File metadata and controls
126 lines (109 loc) · 4.44 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// DBMetadata.m
// DropboxSDK
//
// Created by Brian Smith on 5/3/10.
// Copyright 2010 Dropbox, Inc. All rights reserved.
//
#import "DBMetadata.h"
@implementation DBMetadata
+ (NSDateFormatter*)dateFormatter {
NSMutableDictionary* dictionary = [[NSThread currentThread] threadDictionary];
static NSString* dateFormatterKey = @"DBMetadataDateFormatter";
NSDateFormatter* dateFormatter = [dictionary objectForKey:dateFormatterKey];
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter new] autorelease];
// Must set locale to ensure consistent parsing:
// http://developer.apple.com/iphone/library/qa/qa2010/qa1480.html
dateFormatter.locale =
[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z";
[dictionary setObject:dateFormatter forKey:dateFormatterKey];
}
return dateFormatter;
}
- (id)initWithDictionary:(NSDictionary*)dict {
if ((self = [super init])) {
thumbnailExists = [[dict objectForKey:@"thumb_exists"] boolValue];
totalBytes = [[dict objectForKey:@"bytes"] longLongValue];
if ([dict objectForKey:@"modified"]) {
lastModifiedDate =
[[[DBMetadata dateFormatter] dateFromString:[dict objectForKey:@"modified"]] retain];
}
path = [[dict objectForKey:@"path"] retain];
isDirectory = [[dict objectForKey:@"is_dir"] boolValue];
if ([dict objectForKey:@"contents"]) {
NSArray* subfileDicts = [dict objectForKey:@"contents"];
NSMutableArray* mutableContents =
[[NSMutableArray alloc] initWithCapacity:[subfileDicts count]];
for (NSDictionary* subfileDict in subfileDicts) {
DBMetadata* subfile = [[DBMetadata alloc] initWithDictionary:subfileDict];
[mutableContents addObject:subfile];
[subfile release];
}
contents = mutableContents;
}
hash = [[dict objectForKey:@"hash"] retain];
humanReadableSize = [[dict objectForKey:@"size"] retain];
root = [[dict objectForKey:@"root"] retain];
icon = [[dict objectForKey:@"icon"] retain];
revision = [[dict objectForKey:@"revision"] longLongValue];
isDeleted = [[dict objectForKey:@"is_deleted"] boolValue];
}
return self;
}
- (void)dealloc {
[lastModifiedDate release];
[path release];
[contents release];
[hash release];
[humanReadableSize release];
[root release];
[icon release];
[super dealloc];
}
@synthesize thumbnailExists;
@synthesize totalBytes;
@synthesize lastModifiedDate;
@synthesize path;
@synthesize isDirectory;
@synthesize contents;
@synthesize hash;
@synthesize humanReadableSize;
@synthesize root;
@synthesize icon;
@synthesize revision;
@synthesize isDeleted;
#pragma mark NSCoding methods
- (id)initWithCoder:(NSCoder*)coder {
if ((self = [super init])) {
thumbnailExists = [coder decodeBoolForKey:@"thumbnailExists"];
totalBytes = [coder decodeInt64ForKey:@"totalBytes"];
lastModifiedDate = [[coder decodeObjectForKey:@"lastModifiedDate"] retain];
path = [[coder decodeObjectForKey:@"path"] retain];
isDirectory = [coder decodeBoolForKey:@"isDirectory"];
contents = [[coder decodeObjectForKey:@"contents"] retain];
hash = [[coder decodeObjectForKey:@"hash"] retain];
humanReadableSize = [[coder decodeObjectForKey:@"humanReadableSize"] retain];
root = [[coder decodeObjectForKey:@"root"] retain];
icon = [[coder decodeObjectForKey:@"icon"] retain];
revision = [coder decodeInt64ForKey:@"revision"];
isDeleted = [coder decodeBoolForKey:@"isDeleted"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder*)coder {
[coder encodeBool:thumbnailExists forKey:@"thumbnailExists"];
[coder encodeInt64:totalBytes forKey:@"totalBytes"];
[coder encodeObject:lastModifiedDate forKey:@"lastModifiedDate"];
[coder encodeObject:path forKey:@"path"];
[coder encodeBool:isDirectory forKey:@"isDirectory"];
[coder encodeObject:contents forKey:@"contents"];
[coder encodeObject:hash forKey:@"hash"];
[coder encodeObject:humanReadableSize forKey:@"humanReadableSize"];
[coder encodeObject:root forKey:@"root"];
[coder encodeObject:icon forKey:@"icon"];
[coder encodeInt64:revision forKey:@"revision"];
[coder encodeBool:isDeleted forKey:@"isDeleted"];
}
@end