Changeset 1597


Ignore:
Timestamp:
Mar 28, 2007, 3:02:08 AM (15 years ago)
Author:
livings124
Message:

save transfer info in a file in application support rather than into the preference file

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r1577 r1597  
    206206- (void) prepareForUpdate:  (NSNotification *) notification;
    207207
     208- (NSString *) applicationSupportFolder;
     209
    208210@end
    209211
  • trunk/macosx/Controller.m

    r1582 r1597  
    282282        NSLog(@"Could not IORegisterForSystemPower");
    283283
    284     //load torrents from history
    285     Torrent * torrent;
    286     NSDictionary * historyItem;
    287     NSEnumerator * enumerator = [[fDefaults arrayForKey: @"History"] objectEnumerator];
    288     while ((historyItem = [enumerator nextObject]))
    289         if ((torrent = [[Torrent alloc] initWithHistory: historyItem lib: fLib]))
    290         {
    291             [fTorrents addObject: torrent];
    292             [torrent release];
    293         }
     284    //load previous transfers
     285    NSLog([self applicationSupportFolder]);
     286    NSArray * history = [[NSArray alloc] initWithContentsOfFile: [[self applicationSupportFolder]
     287                                                stringByAppendingPathComponent: @"Transfers.plist"]];
     288   
     289    //old version saved transfer info in prefs file
     290    if (!history)
     291        if ((history = [fDefaults arrayForKey: @"History"]))
     292            [history retain];
     293    [fDefaults removeObjectForKey: @"History"];
     294   
     295    if (history)
     296    {
     297        Torrent * torrent;
     298        NSDictionary * historyItem;
     299        NSEnumerator * enumerator = [history objectEnumerator];
     300        while ((historyItem = [enumerator nextObject]))
     301            if ((torrent = [[Torrent alloc] initWithHistory: historyItem lib: fLib]))
     302            {
     303                [fTorrents addObject: torrent];
     304                [torrent release];
     305            }
     306       
     307        [history release];
     308    }
    294309   
    295310    //set sort
     
    13601375        [history addObject: [torrent history]];
    13611376
    1362     [fDefaults setObject: history forKey: @"History"];
    1363     [fDefaults synchronize];
     1377    [history writeToFile: [[self applicationSupportFolder] stringByAppendingPathComponent: @"Transfers.plist"] atomically: YES];
    13641378}
    13651379
     
    27862800}
    27872801
     2802- (NSString *) applicationSupportFolder
     2803{
     2804    return [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex: 0]
     2805                stringByAppendingPathComponent: [[NSProcessInfo processInfo] processName]];
     2806}
     2807
    27882808@end
Note: See TracChangeset for help on using the changeset viewer.