Changeset 13219


Ignore:
Timestamp:
Feb 11, 2012, 5:13:46 AM (7 years ago)
Author:
livings124
Message:

replace NSAutoreleasePool objects with @autoreleasepool blocks

Location:
trunk/macosx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/BlocklistDownloader.m

    r13162 r13219  
    237237- (void) finishDownloadSuccess
    238238{
    239     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    240    
    241     [fViewController setStatusProcessing];
    242    
    243     //process data
    244     NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
    245    
    246     [self decompressBlocklist];
    247    
    248     const int count = tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
    249    
    250     //delete downloaded file
    251     [[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
    252    
    253     if (count > 0)
    254         [fViewController setFinished];
    255     else
    256         [fViewController setFailed: NSLocalizedString(@"The specified blocklist file did not contain any valid rules.",
    257                                         "blocklist fail message")];
    258    
    259     //update last updated date for schedule
    260     NSDate * date = [NSDate date];
    261     [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdate"];
    262     [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdateSuccess"];
    263     [[BlocklistScheduler scheduler] updateSchedule];
    264    
    265     [[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
    266    
    267     [pool drain];
     239    @autoreleasepool
     240    {
     241        [fViewController setStatusProcessing];
     242       
     243        //process data
     244        NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
     245       
     246        [self decompressBlocklist];
     247       
     248        const int count = tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
     249       
     250        //delete downloaded file
     251        [[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
     252       
     253        if (count > 0)
     254            [fViewController setFinished];
     255        else
     256            [fViewController setFailed: NSLocalizedString(@"The specified blocklist file did not contain any valid rules.",
     257                                            "blocklist fail message")];
     258       
     259        //update last updated date for schedule
     260        NSDate * date = [NSDate date];
     261        [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdate"];
     262        [[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdateSuccess"];
     263        [[BlocklistScheduler scheduler] updateSchedule];
     264       
     265        [[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
     266    }
    268267   
    269268    fDownloader = nil;
  • trunk/macosx/Controller.m

    r13187 r13219  
    44314431- (void) rpcCallback: (tr_rpc_callback_type) type forTorrentStruct: (struct tr_torrent *) torrentStruct
    44324432{
    4433     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    4434    
    4435     //get the torrent
    4436     Torrent * torrent = nil;
    4437     if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED && type != TR_RPC_SESSION_CLOSE))
    4438     {
    4439         for (torrent in fTorrents)
    4440             if (torrentStruct == [torrent torrentStruct])
     4433    @autoreleasepool
     4434    {
     4435        //get the torrent
     4436        Torrent * torrent = nil;
     4437        if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED && type != TR_RPC_SESSION_CLOSE))
     4438        {
     4439            for (torrent in fTorrents)
     4440                if (torrentStruct == [torrent torrentStruct])
     4441                {
     4442                    [torrent retain];
     4443                    break;
     4444                }
     4445           
     4446            if (!torrent)
    44414447            {
    4442                 [torrent retain];
     4448                NSLog(@"No torrent found matching the given torrent struct from the RPC callback!");
     4449                return;
     4450            }
     4451        }
     4452       
     4453        switch (type)
     4454        {
     4455            case TR_RPC_TORRENT_ADDED:
     4456                [self performSelectorOnMainThread: @selector(rpcAddTorrentStruct:) withObject:
     4457                    [[NSValue valueWithPointer: torrentStruct] retain] waitUntilDone: NO];
    44434458                break;
    4444             }
    4445        
    4446         if (!torrent)
    4447         {
    4448             [pool drain];
    4449            
    4450             NSLog(@"No torrent found matching the given torrent struct from the RPC callback!");
    4451             return;
    4452         }
    4453     }
    4454    
    4455     switch (type)
    4456     {
    4457         case TR_RPC_TORRENT_ADDED:
    4458             [self performSelectorOnMainThread: @selector(rpcAddTorrentStruct:) withObject:
    4459                 [[NSValue valueWithPointer: torrentStruct] retain] waitUntilDone: NO];
    4460             break;
    4461        
    4462         case TR_RPC_TORRENT_STARTED:
    4463         case TR_RPC_TORRENT_STOPPED:
    4464             [self performSelectorOnMainThread: @selector(rpcStartedStoppedTorrent:) withObject: torrent waitUntilDone: NO];
    4465             break;
    4466        
    4467         case TR_RPC_TORRENT_REMOVING:
    4468             [self performSelectorOnMainThread: @selector(rpcRemoveTorrent:) withObject: torrent waitUntilDone: NO];
    4469             break;
    4470        
    4471         case TR_RPC_TORRENT_TRASHING:
    4472             [self performSelectorOnMainThread: @selector(rpcRemoveTorrentDeleteData:) withObject: torrent waitUntilDone: NO];
    4473             break;
    4474        
    4475         case TR_RPC_TORRENT_CHANGED:
    4476             [self performSelectorOnMainThread: @selector(rpcChangedTorrent:) withObject: torrent waitUntilDone: NO];
    4477             break;
    4478        
    4479         case TR_RPC_TORRENT_MOVED:
    4480             [self performSelectorOnMainThread: @selector(rpcMovedTorrent:) withObject: torrent waitUntilDone: NO];
    4481             break;
    4482        
    4483         case TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED:
    4484             [self performSelectorOnMainThread: @selector(rpcUpdateQueue) withObject: nil waitUntilDone: NO];
    4485             break;
    4486        
    4487         case TR_RPC_SESSION_CHANGED:
    4488             [fPrefsController performSelectorOnMainThread: @selector(rpcUpdatePrefs) withObject: nil waitUntilDone: NO];
    4489             break;
    4490        
    4491         case TR_RPC_SESSION_CLOSE:
    4492             fQuitRequested = YES;
    4493             [NSApp performSelectorOnMainThread: @selector(terminate:) withObject: self waitUntilDone: NO];
    4494             break;
    4495        
    4496         default:
    4497             NSAssert1(NO, @"Unknown RPC command received: %d", type);
    4498             [torrent release];
    4499     }
    4500    
    4501     [pool drain];
     4459           
     4460            case TR_RPC_TORRENT_STARTED:
     4461            case TR_RPC_TORRENT_STOPPED:
     4462                [self performSelectorOnMainThread: @selector(rpcStartedStoppedTorrent:) withObject: torrent waitUntilDone: NO];
     4463                break;
     4464           
     4465            case TR_RPC_TORRENT_REMOVING:
     4466                [self performSelectorOnMainThread: @selector(rpcRemoveTorrent:) withObject: torrent waitUntilDone: NO];
     4467                break;
     4468           
     4469            case TR_RPC_TORRENT_TRASHING:
     4470                [self performSelectorOnMainThread: @selector(rpcRemoveTorrentDeleteData:) withObject: torrent waitUntilDone: NO];
     4471                break;
     4472           
     4473            case TR_RPC_TORRENT_CHANGED:
     4474                [self performSelectorOnMainThread: @selector(rpcChangedTorrent:) withObject: torrent waitUntilDone: NO];
     4475                break;
     4476           
     4477            case TR_RPC_TORRENT_MOVED:
     4478                [self performSelectorOnMainThread: @selector(rpcMovedTorrent:) withObject: torrent waitUntilDone: NO];
     4479                break;
     4480           
     4481            case TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED:
     4482                [self performSelectorOnMainThread: @selector(rpcUpdateQueue) withObject: nil waitUntilDone: NO];
     4483                break;
     4484           
     4485            case TR_RPC_SESSION_CHANGED:
     4486                [fPrefsController performSelectorOnMainThread: @selector(rpcUpdatePrefs) withObject: nil waitUntilDone: NO];
     4487                break;
     4488           
     4489            case TR_RPC_SESSION_CLOSE:
     4490                fQuitRequested = YES;
     4491                [NSApp performSelectorOnMainThread: @selector(terminate:) withObject: self waitUntilDone: NO];
     4492                break;
     4493           
     4494            default:
     4495                NSAssert1(NO, @"Unknown RPC command received: %d", type);
     4496                [torrent release];
     4497        }
     4498    }
    45024499}
    45034500
  • trunk/macosx/Torrent.m

    r13187 r13219  
    6868void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, bool wasRunning, void * torrentData)
    6969{
    70     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    71    
    72     NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt: status], @"Status",
    73                             [NSNumber numberWithBool: wasRunning], @"WasRunning", nil];
    74     [(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:) withObject: dict waitUntilDone: NO];
    75    
    76     [pool drain];
     70    @autoreleasepool
     71    {
     72        NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt: status], @"Status",
     73                               [NSNumber numberWithBool: wasRunning], @"WasRunning", nil];
     74        [(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:) withObject: dict waitUntilDone: NO];
     75    }
    7776}
    7877
     
    9493int trashDataFile(const char * filename)
    9594{
    96     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    97    
    98     if (filename != NULL)
    99         [Torrent trashFile: [NSString stringWithUTF8String: filename]];
    100    
    101     [pool drain];
     95    @autoreleasepool
     96    {
     97        if (filename != NULL)
     98            [Torrent trashFile: [NSString stringWithUTF8String: filename]];
     99    }
    102100    return 0;
    103101}
  • trunk/macosx/TrackerCell.m

    r13162 r13219  
    219219- (void) loadTrackerIcon: (NSString *) baseAddress
    220220{
    221     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    222    
    223     //try favicon.png
    224     NSURL * favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.png"]];
    225    
    226     NSURLRequest * request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
    227                                 timeoutInterval: 30.0];
    228     NSData * iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
    229     NSImage * icon = [[NSImage alloc] initWithData: iconData];
    230    
    231     //try favicon.ico
    232     if (!icon)
     221    @autoreleasepool
    233222    {
    234         favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.ico"]];
    235        
    236         request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
    237                     timeoutInterval: 30.0];
    238         iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
    239         icon = [[NSImage alloc] initWithData: iconData];
     223        //try favicon.png
     224        NSURL * favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.png"]];
     225       
     226        NSURLRequest * request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
     227                                    timeoutInterval: 30.0];
     228        NSData * iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
     229        NSImage * icon = [[NSImage alloc] initWithData: iconData];
     230       
     231        //try favicon.ico
     232        if (!icon)
     233        {
     234            favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.ico"]];
     235           
     236            request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
     237                        timeoutInterval: 30.0];
     238            iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
     239            icon = [[NSImage alloc] initWithData: iconData];
     240        }
     241       
     242        if (icon)
     243        {
     244            [fTrackerIconCache setObject: icon forKey: baseAddress];
     245            [icon release];
     246           
     247            [[self controlView] setNeedsDisplay: YES];
     248        }
     249        else
     250            [fTrackerIconCache setObject: [NSNull null] forKey: baseAddress];
     251       
     252        [fTrackerIconLoading removeObject: baseAddress];
    240253    }
    241    
    242     if (icon)
    243     {
    244         [fTrackerIconCache setObject: icon forKey: baseAddress];
    245         [icon release];
    246        
    247         [[self controlView] setNeedsDisplay: YES];
    248     }
    249     else
    250         [fTrackerIconCache setObject: [NSNull null] forKey: baseAddress];
    251    
    252     [fTrackerIconLoading removeObject: baseAddress];
    253 
    254     [pool drain];
    255254}
    256255
Note: See TracChangeset for help on using the changeset viewer.