Reset sync daemon local state if the client version has changed
[pithos-macos] / pithos-macos / PithosAccount.m
1 //
2 //  PithosAccount.m
3 //  pithos-macos
4 //
5 // Copyright 2012 GRNET S.A. All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or
8 // without modification, are permitted provided that the following
9 // conditions are met:
10 // 
11 //   1. Redistributions of source code must retain the above
12 //      copyright notice, this list of conditions and the following
13 //      disclaimer.
14 // 
15 //   2. Redistributions in binary form must reproduce the above
16 //      copyright notice, this list of conditions and the following
17 //      disclaimer in the documentation and/or other materials
18 //      provided with the distribution.
19 // 
20 // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
21 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
24 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 // 
33 // The views and conclusions contained in the software and
34 // documentation are those of the authors and should not be
35 // interpreted as representing official policies, either expressed
36 // or implied, of GRNET S.A.
37
38 #import "PithosAccount.h"
39 #import "PithosSyncDaemon.h"
40 #import "ASIPithos.h"
41 #import "ASIPithosRequest.h"
42 #import "PithosAccountNode.h"
43 #import "PithosSharingAccountsNode.h"
44 #import "PithosUtilities.h"
45 #import "pithos_macosAppDelegate.h"
46
47 @interface PithosAccount (Internal)
48 - (BOOL)urlIsValid:(NSString *)urlString;
49 @end
50
51 @implementation PithosAccount
52 @synthesize uniqueName, active, name, clientVersion;
53 @synthesize syncActive, syncDirectoryPath, syncAccountsDictionary, syncSkipHidden, syncLastCompleted, syncDaemon;
54 @synthesize serverURL, versionResource, loginResource, publicResource, userCatalogResource;
55 @synthesize authUser, authToken, storageURLPrefix, authURL, loginURLPrefix, publicURLPrefix, userCatalogURL, userCatalog;
56 @synthesize pithos, accountNode, sharingAccountsNode;
57
58 #pragma mark -
59 #pragma mark Object Lifecycle
60
61 + (id)pithosAccount {
62     PithosAccount *pithosAccount = [[self alloc] init];
63     pithosAccount.uniqueName = [NSString stringWithFormat:@"pithosAccount-%f", [NSDate timeIntervalSinceReferenceDate]];
64     pithosAccount.clientVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
65     pithosAccount.syncSkipHidden = YES;
66     return pithosAccount;
67 }
68
69
70 - (NSString *)description {
71     return [NSString stringWithFormat:@"uniqueName: %@, active: %d, name: %@, clientVersion: %@, syncActive: %d, syncDirectoryPath: %@, syncAccountsDictionary: %@, syncSkipHidden: %d, syncLastCompleted: %@, serverURL: %@, versionResource: %@, loginResource: %@, publicResource: %@, userCatalogResource: %@, authUser: %@, authToken: %@, storageURLPrefix: %@, authURL: %@, loginURLPrefix: %@, publicURLPrefix: %@, userCatalogResource: %@",
72             uniqueName, active, name, clientVersion, syncActive, syncDirectoryPath, syncAccountsDictionary, syncSkipHidden, syncLastCompleted, serverURL, versionResource, loginResource, publicResource, userCatalogResource, authUser, authToken, storageURLPrefix, authURL, loginURLPrefix, publicURLPrefix, userCatalogResource];
73 }
74
75 #pragma mark -
76 #pragma mark Internal
77
78 - (BOOL)urlIsValid:(NSString *)urlString {
79     if (urlString) {
80         NSURL *url = [NSURL URLWithString:urlString];
81         if (url && url.scheme && url.host)
82             return YES;
83     }
84     return NO;
85 }
86
87 #pragma mark -
88 #pragma mark Properties
89
90 - (NSString *)name {
91     if (![name length]) {
92         NSDictionary *pithosAccountsDictionary = [(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] pithosAccountsDictionary];
93         NSString *namePrefix = @"okeanos";
94         NSUInteger nameSuffix = 1;
95         name = @"okeanos";
96         NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
97         NSFileManager *fileManager = [NSFileManager defaultManager];
98         while ([pithosAccountsDictionary objectForKey:name] || 
99                [fileManager fileExistsAtPath:[documentsDirectoryPath stringByAppendingPathComponent:name]]) {
100             name = [NSString stringWithFormat:@"%@%ld", namePrefix, ++nameSuffix];
101         }
102     }
103     return name;
104 }
105
106 - (void)setName:(NSString *)aName {
107     NSMutableDictionary *pithosAccountsDictionary = [(pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate] pithosAccountsDictionary];
108     if (![self.name isEqualToString:aName] && [aName length] && ![pithosAccountsDictionary objectForKey:aName]) {
109         [pithosAccountsDictionary setObject:self forKey:aName];
110         [pithosAccountsDictionary removeObjectForKey:name];
111         name = aName;
112     }
113 }
114
115 - (BOOL)syncActive {
116     if (active)
117         return syncActive;
118     else
119         return NO;
120 }
121
122 - (void)setSyncActive:(BOOL)aSyncActive {
123     syncActive = aSyncActive;
124     if (syncDaemon && !self.syncActive)
125         [syncDaemon resetDaemon];
126 }
127
128 - (NSString *)syncDirectoryPath {
129     if (![syncDirectoryPath length]) {
130         syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 
131                               stringByAppendingPathComponent:self.name];
132     }
133     return syncDirectoryPath;
134 }
135
136 - (void)setSyncDirectoryPath:(NSString *)aSyncDirectoryPath {
137     if (![self.syncDirectoryPath isEqualToString:aSyncDirectoryPath] && [aSyncDirectoryPath length]) {
138         BOOL isDirectory;
139         if (![[NSFileManager defaultManager] fileExistsAtPath:aSyncDirectoryPath isDirectory:&isDirectory] || isDirectory) {
140             syncDirectoryPath = aSyncDirectoryPath;
141         } else {
142             return;
143         }
144
145         @synchronized(self) {
146             resetSyncDaemonLocalState = YES;
147             syncLastCompleted = nil;
148         }
149     }
150 }
151
152 - (NSMutableDictionary *)syncAccountsDictionary {
153     if (!syncAccountsDictionary) {
154         syncAccountsDictionary = [NSMutableDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObject:[NSMutableSet set] 
155                                                                                                               forKey:@"pithos"]
156                                                                     forKey:@""];
157     }        
158     return syncAccountsDictionary;
159 }
160
161 - (void)setSyncAccountsDictionary:(NSMutableDictionary *)aSyncAccountsDictionary {
162     if (aSyncAccountsDictionary && ![self.syncAccountsDictionary isEqualToDictionary:aSyncAccountsDictionary]) {
163         syncAccountsDictionary = [[NSMutableDictionary alloc] initWithCapacity:[aSyncAccountsDictionary count]];
164         for (NSString *accountName in aSyncAccountsDictionary) {
165             NSDictionary *aSyncContainersDictionary = [aSyncAccountsDictionary objectForKey:accountName];
166             NSMutableDictionary *syncContainersDictionary = [NSMutableDictionary dictionary];
167             for (NSString *containerName in aSyncContainersDictionary) {
168                 if (![accountName isEqualToString:@""] || ![[containerName lowercaseString] isEqualToString:@"shared with me"])
169                     [syncContainersDictionary setObject:[NSMutableSet setWithSet:[aSyncContainersDictionary objectForKey:containerName]] 
170                                                  forKey:containerName];
171             }
172             if ([syncContainersDictionary count])
173                 [syncAccountsDictionary setObject:syncContainersDictionary forKey:accountName];
174         }
175         
176         @synchronized(self) {
177             resetSyncDaemonLocalState = YES;
178             syncLastCompleted = nil;
179         }
180     }
181 }
182
183 - (NSDate *)syncLastCompleted {
184     if (self.syncDaemon.lastCompletedSync && ![self.syncDaemon.lastCompletedSync isEqualToDate:syncLastCompleted]) {
185         syncLastCompleted = [self.syncDaemon.lastCompletedSync copy];
186     }
187     return syncLastCompleted;
188 }
189
190 - (PithosSyncDaemon *)syncDaemon {
191     @synchronized(self) {
192         if (self.syncActive && !syncDaemon)
193             syncDaemon = [[PithosSyncDaemon alloc] initWithDirectoryPath:self.syncDirectoryPath 
194                                                            pithosAccount:self 
195                                                       accountsDictionary:self.syncAccountsDictionary 
196                                                               skipHidden:self.syncSkipHidden 
197                                                          resetLocalState:resetSyncDaemonLocalState];
198         resetSyncDaemonLocalState = NO;
199     }
200     return syncDaemon;
201 }
202
203 - (NSString *)serverURL {
204     if (![self urlIsValid:serverURL]) {
205         serverURL = @"https://pithos.okeanos.grnet.gr";
206     }
207     return serverURL;
208 }
209
210 - (void)setServerURL:(NSString *)aServerURL {
211     if (![self.serverURL isEqualToString:aServerURL] && [self urlIsValid:aServerURL]) {
212         serverURL = aServerURL;
213         storageURLPrefix = nil;
214         authURL = nil;
215         publicURLPrefix = nil;
216         loginURLPrefix = nil;
217
218         @synchronized(self) {
219             updatePithos = YES;
220             resetSyncDaemonLocalState = YES;
221             syncLastCompleted = nil;
222         }
223     }
224 }
225
226 - (NSString *)versionResource {
227     if (!versionResource) {
228         versionResource = @"v1";
229     }
230     return versionResource;
231 }
232
233 - (NSString *)loginResource {
234     if (!loginResource) {
235         loginResource = @"login";
236     }
237     return loginResource;
238 }
239
240 - (NSString *)userCatalogResource {
241     if (!userCatalogResource) {
242         userCatalogResource = @"user_catalogs";
243     }
244     return userCatalogResource;
245 }
246
247 - (void)setAuthUser:(NSString *)anAuthUser {
248     if ([anAuthUser length] && ![anAuthUser isEqualToString:authUser]) {
249         authUser = anAuthUser;
250         
251         @synchronized(self) {
252             updatePithos = YES;
253             resetSyncDaemonLocalState = YES;
254             syncLastCompleted = nil;
255
256         }
257     }
258 }
259
260 - (void)setAuthToken:(NSString *)anAuthToken {
261     if ([anAuthToken length] && ![anAuthToken isEqualToString:authToken]) {
262         authToken = anAuthToken;
263         
264         @synchronized(self) {
265             updatePithos = YES;
266         }
267     }
268 }
269
270 - (NSString *)storageURLPrefix {
271     if (![self urlIsValid:storageURLPrefix]) {
272         storageURLPrefix = [self.serverURL stringByAppendingFormat:@"/%@", self.versionResource];
273     }
274     return storageURLPrefix;
275 }
276
277 - (void)setStorageURLPrefix:(NSString *)aStorageURLPrefix {
278     if (![self.storageURLPrefix isEqualToString:aStorageURLPrefix] && [self urlIsValid:aStorageURLPrefix]) {
279         storageURLPrefix = aStorageURLPrefix;
280     }
281 }
282
283 - (NSString *)authURL {
284     if (![self urlIsValid:authURL]) {
285         authURL = [self.serverURL stringByAppendingFormat:@"/%@", self.versionResource];
286     }
287     return authURL;
288 }
289
290 - (void)setAuthURL:(NSString *)anAuthURL {
291     if (![self.authURL isEqualToString:anAuthURL] && [self urlIsValid:anAuthURL]) {
292         authURL = anAuthURL;
293     }
294 }
295
296 - (NSString *)publicURLPrefix {
297     if (![self urlIsValid:publicURLPrefix]) {
298         if (publicResource)
299             publicURLPrefix = [self.serverURL stringByAppendingFormat:@"/%@", publicResource];
300         else
301             publicURLPrefix = [self.serverURL copy];
302     }
303     return publicURLPrefix;
304 }
305
306 - (void)setPublicURLPrefix:(NSString *)aPublicURLPrefix {
307     if (![self.publicURLPrefix isEqualToString:aPublicURLPrefix] && [self urlIsValid:aPublicURLPrefix]) {
308         publicURLPrefix = aPublicURLPrefix;
309     }
310 }
311
312 - (NSString *)loginURLPrefix {
313     if (![self urlIsValid:loginURLPrefix]) {
314         loginURLPrefix = [self.serverURL stringByAppendingFormat:@"/%@", self.loginResource];
315     }
316     return loginURLPrefix;
317 }
318
319 - (void)setLoginURLPrefix:(NSString *)aLoginURLPrefix {
320     if (![self.loginURLPrefix isEqualToString:aLoginURLPrefix] && [self urlIsValid:aLoginURLPrefix]) {
321         loginURLPrefix = aLoginURLPrefix;
322     }
323 }
324
325 - (NSString *)userCatalogURL {
326     if (![self urlIsValid:userCatalogURL]) {
327         userCatalogURL = [self.serverURL stringByAppendingFormat:@"/%@", self.userCatalogResource];
328     }
329     return userCatalogURL;
330 }
331
332 - (void)setUserCatalogURL:(NSString *)aUserCatalogURL {
333     if (![self.userCatalogURL isEqualToString:aUserCatalogURL] && [self urlIsValid:aUserCatalogURL]) {
334         userCatalogURL = aUserCatalogURL;
335     }
336 }
337
338 - (NSMutableDictionary *)userCatalog {
339     if (!userCatalog) {
340         userCatalog = [NSMutableDictionary dictionary];
341     }
342     return userCatalog;
343 }
344
345 - (ASIPithos *)pithos {
346     @synchronized(self) {
347         if (!pithos || updatePithos) {
348             pithos = [ASIPithos pithos];
349             pithos.authUser = authUser;
350             pithos.authToken = authToken;
351             pithos.storageURLPrefix = self.storageURLPrefix;
352             pithos.authURL = self.authURL;
353             pithos.publicURLPrefix = self.publicURLPrefix;
354             pithos.userCatalogURL = self.userCatalogURL;
355             updatePithos = NO;
356         }
357     }
358     return pithos;
359 }
360
361 - (PithosAccountNode *)accountNode {
362     if (!accountNode) {
363         accountNode = [[PithosAccountNode alloc] initWithPithos:self.pithos];
364         accountNode.childrenUpdatedNotificationName = nil;
365         accountNode.inheritChildrenUpdatedNotificationName = YES;
366         accountNode.pithosAccountManager = self;
367     }
368     return accountNode;
369 }
370
371 - (PithosSharingAccountsNode *)sharingAccountsNode {
372     if (!sharingAccountsNode) {
373         sharingAccountsNode = [[PithosSharingAccountsNode alloc] initWithPithos:self.pithos];
374         sharingAccountsNode.childrenUpdatedNotificationName = nil;
375         sharingAccountsNode.inheritChildrenUpdatedNotificationName = YES;
376         sharingAccountsNode.pithosAccountManager = self;
377     }
378     return sharingAccountsNode;
379 }
380
381 #pragma mark -
382 #pragma mark Actions
383
384 - (void)authenticateWithServerURL:(NSString *)aServerURL authUser:(NSString *)anAuthUser authToken:(NSString *)anAuthToken {
385     self.serverURL = aServerURL;
386     self.authUser = anAuthUser;
387     self.authToken = anAuthToken;
388     DLog(@"Account: %@\nauthentication", self);
389     if (![authUser length] || ![authToken length]) {
390         self.active = NO;
391         self.syncActive = NO;
392         // XXX Show preferences with self as the selected account?
393     } else  {
394         self.active = YES;
395         if (syncDaemon) {
396             self.syncDaemon.pithos = self.pithos;
397             if (self.syncActive)
398                 [self.syncDaemon startDaemon];
399         }
400         if (accountNode)
401             self.accountNode.pithos = self.pithos;
402         if (sharingAccountsNode)
403             self.sharingAccountsNode.pithos = self.pithos;
404         if (accountNode) {
405             if (self.accountNode.children) {
406             }
407             [self.accountNode refreshInfo];
408         }
409         if (sharingAccountsNode && self.sharingAccountsNode.children) {
410         }
411         
412         [self updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:authUser]];
413     }
414 }
415
416 - (void)loginWithServerURL:(NSString *)aServerURL {
417     self.serverURL = aServerURL;
418     NSProcessInfo *processInfo = [NSProcessInfo processInfo];
419     NSString *loginURL = [NSString stringWithFormat:@"%@?next=pithos://%d/%@&force=", 
420                           self.loginURLPrefix, [processInfo processIdentifier], [ASIPithosRequest encodeToPercentEscape:self.name]];
421     DLog(@"Account: %@\nloginURL: %@", self, loginURL);
422     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:loginURL]];
423 }
424
425 - (void)updateSyncWithSyncActive:(BOOL)aSyncActive 
426                syncDirectoryPath:(NSString *)aSyncDirectoryPath 
427           syncAccountsDictionary:(NSMutableDictionary *)aSyncAccountsDictionary 
428                   syncSkipHidden:(BOOL)aSyncSkipHidden {
429     self.syncAccountsDictionary = aSyncAccountsDictionary;
430     self.syncDirectoryPath = aSyncDirectoryPath;
431     self.syncSkipHidden = aSyncSkipHidden;
432     self.syncActive = aSyncActive;
433     if (syncDaemon) {
434         self.syncDaemon.accountsDictionary = self.syncAccountsDictionary;
435         self.syncDaemon.directoryPath = self.syncDirectoryPath;
436         self.syncDaemon.skipHidden = self.syncSkipHidden;
437         if (self.syncActive)
438             [self.syncDaemon startDaemon];
439     }    
440 }
441
442 - (ASIPithosRequest *)updateUserCatalogForForDisplaynames:(NSArray *)displaynames UUIDs:(NSArray *)UUIDs {
443     ASIPithosRequest *userCatalogRequest = [ASIPithosRequest userCatalogRequestWithPithos:self.pithos
444                                                                              displaynames:displaynames
445                                                                                     UUIDs:UUIDs];
446     [PithosUtilities startAndWaitForRequest:userCatalogRequest];
447     if (userCatalogRequest.error || ((userCatalogRequest.responseStatusCode != 200) && (userCatalogRequest.responseStatusCode != 404))) {
448         // Don't show alert on 404, since it can be a pre-UUID server.
449         [PithosUtilities httpRequestErrorAlertWithRequest:userCatalogRequest];
450     } else if (userCatalogRequest.responseStatusCode == 200) {
451         NSDictionary *catalogs = [userCatalogRequest catalogs];
452         NSDictionary *displaynameCatalog = [catalogs objectForKey:@"displayname_catalog"];
453         for (NSString *displayname in displaynameCatalog) {
454             [self.userCatalog setObject:displayname forKey:[displaynameCatalog objectForKey:displayname]];
455         }
456         if (UUIDs) {
457             NSDictionary *UUIDCatalog = [catalogs objectForKey:@"uuid_catalog"];
458             for (NSString *UUID in UUIDs) {
459                 NSString *displayname = [UUIDCatalog objectForKey:UUID];
460                 if (displayname) {
461                     [self.userCatalog setObject:displayname forKey:UUID];
462                 } else {
463                     [self.userCatalog removeObjectForKey:UUID];
464                 }
465             }
466         }
467     }
468     return userCatalogRequest;
469 }
470
471 - (NSString *)displaynameForUUID:(NSString *)UUID safe:(BOOL)safe {
472     NSString *displayName = [userCatalog objectForKey:UUID];
473     if (safe && !displayName) {
474         return UUID;
475     } else {
476         return displayName;
477     }
478 }
479
480 - (NSString *)displaynameForUUID:(NSString *)UUID {
481     return [self displaynameForUUID:UUID safe:NO];
482 }
483
484 #pragma mark -
485 #pragma mark NSCoding
486
487 - (id)initWithCoder:(NSCoder *)decoder {
488     if ((self = [super init])) {
489         self.uniqueName = [decoder decodeObjectForKey:@"uniqueName"];
490         self.active = [decoder decodeBoolForKey:@"active"];
491         name = [decoder decodeObjectForKey:@"name"];
492         self.clientVersion = [decoder decodeObjectForKey:@"clientVersion"];
493
494         self.syncActive = [decoder decodeBoolForKey:@"syncActive"];
495         self.syncDirectoryPath = [decoder decodeObjectForKey:@"syncDirectoryPath"];
496         self.syncAccountsDictionary = [decoder decodeObjectForKey:@"syncAccountsDictionary"];
497         self.syncSkipHidden = [decoder decodeBoolForKey:@"syncSkipHidden"];
498         self.syncLastCompleted = [decoder decodeObjectForKey:@"syncLastCompleted"];
499         
500         self.serverURL = [decoder decodeObjectForKey:@"serverURL"];
501         self.versionResource = [decoder decodeObjectForKey:@"versionResource"];
502         self.loginResource = [decoder decodeObjectForKey:@"loginResource"];
503         self.publicResource = [decoder decodeObjectForKey:@"publicResource"];
504         self.userCatalogResource = [decoder decodeObjectForKey:@"userCatalogResource"];
505         
506         self.authUser = [decoder decodeObjectForKey:@"authUser"];
507         self.authToken = [decoder decodeObjectForKey:@"authToken"];
508         self.storageURLPrefix = [decoder decodeObjectForKey:@"storageURLPrefix"];
509         self.authURL = [decoder decodeObjectForKey:@"authURL"];
510         self.publicURLPrefix = [decoder decodeObjectForKey:@"publicURLPrefix"];
511         self.loginURLPrefix = [decoder decodeObjectForKey:@"loginURLPrefix"];
512         self.userCatalogURL = [decoder decodeObjectForKey:@"userCatalogURL"];
513         self.userCatalog = [decoder decodeObjectForKey:@"userCatalog"];
514         
515         if (![authUser length] || ![authToken length] || ![self.storageURLPrefix length])
516             self.active = NO;
517         
518         NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
519         if (!clientVersion || ![clientVersion isEqualToString:currentVersion]) {
520             resetSyncDaemonLocalState = YES;
521             self.clientVersion = currentVersion;
522         } else {
523             resetSyncDaemonLocalState = NO;
524         }
525     }
526     return self;
527 }
528
529 - (void)encodeWithCoder:(NSCoder *)encoder {
530     [encoder encodeObject:uniqueName forKey:@"uniqueName"];
531     [encoder encodeBool:active forKey:@"active"];
532     [encoder encodeObject:name forKey:@"name"];
533     [encoder encodeObject:clientVersion forKey:@"clientVersion"];
534     
535     [encoder encodeBool:syncActive forKey:@"syncActive"];
536     [encoder encodeObject:syncDirectoryPath forKey:@"syncDirectoryPath"];
537     [encoder encodeObject:syncAccountsDictionary forKey:@"syncAccountsDictionary"];
538     [encoder encodeBool:syncSkipHidden forKey:@"syncSkipHidden"];
539     [encoder encodeObject:self.syncLastCompleted forKey:@"syncLastCompleted"];
540
541     [encoder encodeObject:serverURL forKey:@"serverURL"];
542     [encoder encodeObject:versionResource forKey:@"versionResource"];
543     [encoder encodeObject:publicResource forKey:@"publicResource"];
544     [encoder encodeObject:loginResource forKey:@"loginResource"];
545     [encoder encodeObject:loginResource forKey:@"userCatalogResource"];
546     
547     [encoder encodeObject:authUser forKey:@"authUser"];
548     [encoder encodeObject:authToken forKey:@"authToken"];
549     [encoder encodeObject:storageURLPrefix forKey:@"storageURLPrefix"];
550     [encoder encodeObject:authURL forKey:@"authURL"];
551     [encoder encodeObject:publicURLPrefix forKey:@"publicURLPrefix"];
552     [encoder encodeObject:loginURLPrefix forKey:@"loginURLPrefix"];
553     [encoder encodeObject:userCatalogURL forKey:@"userCatalogURL"];
554     [encoder encodeObject:userCatalog forKey:@"userCatalog"];
555 }
556
557 @end