Repository navigation
Expand file tree
/
Copy pathDBMetadata.m
More file actions
executable file
·153 lines (135 loc) · 5.41 KB
/
Copy pathDBMetadata.m
File metadata and controls
executable file
·153 lines (135 loc) · 5.41 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// 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];
}
if ([dict objectForKey:@"client_mtime"]) {
clientMtime =
[[[DBMetadata dateFormatter] dateFromString:[dict objectForKey:@"client_mtime"]] 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];
rev = [[dict objectForKey:@"rev"] retain];
revision = [[dict objectForKey:@"revision"] longLongValue];
isDeleted = [[dict objectForKey:@"is_deleted"] boolValue];
}
return self;
}
- (void)dealloc {
[lastModifiedDate release];
[clientMtime release];
[path release];
[contents release];
[hash release];
[humanReadableSize release];
[root release];
[icon release];
[rev release];
[filename release];
[super dealloc];
}
@synthesize thumbnailExists;
@synthesize totalBytes;
@synthesize lastModifiedDate;
@synthesize clientMtime;
@synthesize path;
@synthesize isDirectory;
@synthesize contents;
@synthesize hash;
@synthesize humanReadableSize;
@synthesize root;
@synthesize icon;
@synthesize rev;
@synthesize revision;
@synthesize isDeleted;
- (BOOL)isEqual:(id)object {
if (object == self) return YES;
if (![object isKindOfClass:[DBMetadata class]]) return NO;
DBMetadata *other = (DBMetadata *)object;
return [self.rev isEqualToString:other.rev];
}
- (NSString *)filename {
if (filename == nil) {
filename = [[path lastPathComponent] retain];
}
return filename;
}
#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];
clientMtime = [[coder decodeObjectForKey:@"clientMtime"] 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];
rev = [[coder decodeObjectForKey:@"rev"] 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:clientMtime forKey:@"clientMtime"];
[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 encodeObject:rev forKey:@"rev"];
[coder encodeInt64:revision forKey:@"revision"];
[coder encodeBool:isDeleted forKey:@"isDeleted"];
}
@end