mirror of
https://github.com/transmission/transmission
synced 2025-02-25 15:32:33 +00:00
replace NSAutoreleasePool objects with @autoreleasepool blocks
This commit is contained in:
parent
72b0086cef
commit
34d9663139
4 changed files with 129 additions and 136 deletions
|
@ -236,35 +236,34 @@ BlocklistDownloader * fDownloader = nil;
|
|||
|
||||
- (void) finishDownloadSuccess
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
[fViewController setStatusProcessing];
|
||||
|
||||
//process data
|
||||
NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
|
||||
|
||||
[self decompressBlocklist];
|
||||
|
||||
const int count = tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
|
||||
|
||||
//delete downloaded file
|
||||
[[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
|
||||
|
||||
if (count > 0)
|
||||
[fViewController setFinished];
|
||||
else
|
||||
[fViewController setFailed: NSLocalizedString(@"The specified blocklist file did not contain any valid rules.",
|
||||
"blocklist fail message")];
|
||||
|
||||
//update last updated date for schedule
|
||||
NSDate * date = [NSDate date];
|
||||
[[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdate"];
|
||||
[[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdateSuccess"];
|
||||
[[BlocklistScheduler scheduler] updateSchedule];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
|
||||
|
||||
[pool drain];
|
||||
@autoreleasepool
|
||||
{
|
||||
[fViewController setStatusProcessing];
|
||||
|
||||
//process data
|
||||
NSAssert(fDestination != nil, @"the blocklist file destination has not been specified");
|
||||
|
||||
[self decompressBlocklist];
|
||||
|
||||
const int count = tr_blocklistSetContent([PrefsController handle], [fDestination UTF8String]);
|
||||
|
||||
//delete downloaded file
|
||||
[[NSFileManager defaultManager] removeItemAtPath: fDestination error: NULL];
|
||||
|
||||
if (count > 0)
|
||||
[fViewController setFinished];
|
||||
else
|
||||
[fViewController setFailed: NSLocalizedString(@"The specified blocklist file did not contain any valid rules.",
|
||||
"blocklist fail message")];
|
||||
|
||||
//update last updated date for schedule
|
||||
NSDate * date = [NSDate date];
|
||||
[[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdate"];
|
||||
[[NSUserDefaults standardUserDefaults] setObject: date forKey: @"BlocklistNewLastUpdateSuccess"];
|
||||
[[BlocklistScheduler scheduler] updateSchedule];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"BlocklistUpdated" object: nil];
|
||||
}
|
||||
|
||||
fDownloader = nil;
|
||||
[self release];
|
||||
|
|
|
@ -4430,75 +4430,72 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
|
||||
- (void) rpcCallback: (tr_rpc_callback_type) type forTorrentStruct: (struct tr_torrent *) torrentStruct
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
//get the torrent
|
||||
Torrent * torrent = nil;
|
||||
if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED && type != TR_RPC_SESSION_CLOSE))
|
||||
@autoreleasepool
|
||||
{
|
||||
for (torrent in fTorrents)
|
||||
if (torrentStruct == [torrent torrentStruct])
|
||||
{
|
||||
[torrent retain];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!torrent)
|
||||
//get the torrent
|
||||
Torrent * torrent = nil;
|
||||
if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED && type != TR_RPC_SESSION_CLOSE))
|
||||
{
|
||||
[pool drain];
|
||||
for (torrent in fTorrents)
|
||||
if (torrentStruct == [torrent torrentStruct])
|
||||
{
|
||||
[torrent retain];
|
||||
break;
|
||||
}
|
||||
|
||||
NSLog(@"No torrent found matching the given torrent struct from the RPC callback!");
|
||||
return;
|
||||
if (!torrent)
|
||||
{
|
||||
NSLog(@"No torrent found matching the given torrent struct from the RPC callback!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case TR_RPC_TORRENT_ADDED:
|
||||
[self performSelectorOnMainThread: @selector(rpcAddTorrentStruct:) withObject:
|
||||
[[NSValue valueWithPointer: torrentStruct] retain] waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_STARTED:
|
||||
case TR_RPC_TORRENT_STOPPED:
|
||||
[self performSelectorOnMainThread: @selector(rpcStartedStoppedTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_REMOVING:
|
||||
[self performSelectorOnMainThread: @selector(rpcRemoveTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_TRASHING:
|
||||
[self performSelectorOnMainThread: @selector(rpcRemoveTorrentDeleteData:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_CHANGED:
|
||||
[self performSelectorOnMainThread: @selector(rpcChangedTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_MOVED:
|
||||
[self performSelectorOnMainThread: @selector(rpcMovedTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED:
|
||||
[self performSelectorOnMainThread: @selector(rpcUpdateQueue) withObject: nil waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_SESSION_CHANGED:
|
||||
[fPrefsController performSelectorOnMainThread: @selector(rpcUpdatePrefs) withObject: nil waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_SESSION_CLOSE:
|
||||
fQuitRequested = YES;
|
||||
[NSApp performSelectorOnMainThread: @selector(terminate:) withObject: self waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
default:
|
||||
NSAssert1(NO, @"Unknown RPC command received: %d", type);
|
||||
[torrent release];
|
||||
}
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case TR_RPC_TORRENT_ADDED:
|
||||
[self performSelectorOnMainThread: @selector(rpcAddTorrentStruct:) withObject:
|
||||
[[NSValue valueWithPointer: torrentStruct] retain] waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_STARTED:
|
||||
case TR_RPC_TORRENT_STOPPED:
|
||||
[self performSelectorOnMainThread: @selector(rpcStartedStoppedTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_REMOVING:
|
||||
[self performSelectorOnMainThread: @selector(rpcRemoveTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_TRASHING:
|
||||
[self performSelectorOnMainThread: @selector(rpcRemoveTorrentDeleteData:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_CHANGED:
|
||||
[self performSelectorOnMainThread: @selector(rpcChangedTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_TORRENT_MOVED:
|
||||
[self performSelectorOnMainThread: @selector(rpcMovedTorrent:) withObject: torrent waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED:
|
||||
[self performSelectorOnMainThread: @selector(rpcUpdateQueue) withObject: nil waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_SESSION_CHANGED:
|
||||
[fPrefsController performSelectorOnMainThread: @selector(rpcUpdatePrefs) withObject: nil waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
case TR_RPC_SESSION_CLOSE:
|
||||
fQuitRequested = YES;
|
||||
[NSApp performSelectorOnMainThread: @selector(terminate:) withObject: self waitUntilDone: NO];
|
||||
break;
|
||||
|
||||
default:
|
||||
NSAssert1(NO, @"Unknown RPC command received: %d", type);
|
||||
[torrent release];
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (void) rpcAddTorrentStruct: (NSValue *) torrentStructPtr
|
||||
|
|
|
@ -67,13 +67,12 @@ void startQueueCallback(tr_torrent * torrent, void * torrentData)
|
|||
|
||||
void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, bool wasRunning, void * torrentData)
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt: status], @"Status",
|
||||
[NSNumber numberWithBool: wasRunning], @"WasRunning", nil];
|
||||
[(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:) withObject: dict waitUntilDone: NO];
|
||||
|
||||
[pool drain];
|
||||
@autoreleasepool
|
||||
{
|
||||
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt: status], @"Status",
|
||||
[NSNumber numberWithBool: wasRunning], @"WasRunning", nil];
|
||||
[(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:) withObject: dict waitUntilDone: NO];
|
||||
}
|
||||
}
|
||||
|
||||
void ratioLimitHitCallback(tr_torrent * torrent, void * torrentData)
|
||||
|
@ -93,12 +92,11 @@ void metadataCallback(tr_torrent * torrent, void * torrentData)
|
|||
|
||||
int trashDataFile(const char * filename)
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
if (filename != NULL)
|
||||
[Torrent trashFile: [NSString stringWithUTF8String: filename]];
|
||||
|
||||
[pool drain];
|
||||
@autoreleasepool
|
||||
{
|
||||
if (filename != NULL)
|
||||
[Torrent trashFile: [NSString stringWithUTF8String: filename]];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -218,40 +218,39 @@ NSMutableSet * fTrackerIconLoading;
|
|||
#warning better favicon detection
|
||||
- (void) loadTrackerIcon: (NSString *) baseAddress
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
//try favicon.png
|
||||
NSURL * favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.png"]];
|
||||
|
||||
NSURLRequest * request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval: 30.0];
|
||||
NSData * iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
|
||||
NSImage * icon = [[NSImage alloc] initWithData: iconData];
|
||||
|
||||
//try favicon.ico
|
||||
if (!icon)
|
||||
@autoreleasepool
|
||||
{
|
||||
favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.ico"]];
|
||||
//try favicon.png
|
||||
NSURL * favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.png"]];
|
||||
|
||||
request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval: 30.0];
|
||||
iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
|
||||
icon = [[NSImage alloc] initWithData: iconData];
|
||||
}
|
||||
|
||||
if (icon)
|
||||
{
|
||||
[fTrackerIconCache setObject: icon forKey: baseAddress];
|
||||
[icon release];
|
||||
NSURLRequest * request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval: 30.0];
|
||||
NSData * iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
|
||||
NSImage * icon = [[NSImage alloc] initWithData: iconData];
|
||||
|
||||
[[self controlView] setNeedsDisplay: YES];
|
||||
//try favicon.ico
|
||||
if (!icon)
|
||||
{
|
||||
favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.ico"]];
|
||||
|
||||
request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval: 30.0];
|
||||
iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
|
||||
icon = [[NSImage alloc] initWithData: iconData];
|
||||
}
|
||||
|
||||
if (icon)
|
||||
{
|
||||
[fTrackerIconCache setObject: icon forKey: baseAddress];
|
||||
[icon release];
|
||||
|
||||
[[self controlView] setNeedsDisplay: YES];
|
||||
}
|
||||
else
|
||||
[fTrackerIconCache setObject: [NSNull null] forKey: baseAddress];
|
||||
|
||||
[fTrackerIconLoading removeObject: baseAddress];
|
||||
}
|
||||
else
|
||||
[fTrackerIconCache setObject: [NSNull null] forKey: baseAddress];
|
||||
|
||||
[fTrackerIconLoading removeObject: baseAddress];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (NSRect) imageRectForBounds: (NSRect) bounds
|
||||
|
|
Loading…
Reference in a new issue