if the user has a corrupt install and as a result pathForResource:ofType: returns nil for GHA, CFURLCreateWithFileSystemPath will crash, so we guard the call and the rest of the block since it depends on that path and log a message to console indicating that the user will need to reinstall Growl, as well as the returned value of prefPaneBundle and pathToGHA.
authorRudy Richter
Wed Sep 09 22:11:15 2009 -0400 (2009-09-09)
changeset 43870e19238de90f
parent 4380 b7f97c9f1ad0
child 4388 2cba9aa98a44
if the user has a corrupt install and as a result pathForResource:ofType: returns nil for GHA, CFURLCreateWithFileSystemPath will crash, so we guard the call and the rest of the block since it depends on that path and log a message to console indicating that the user will need to reinstall Growl, as well as the returned value of prefPaneBundle and pathToGHA.
Core/Source/GrowlPreferencesController.m
     1.1 --- a/Core/Source/GrowlPreferencesController.m	Sat Sep 05 23:51:09 2009 -0700
     1.2 +++ b/Core/Source/GrowlPreferencesController.m	Wed Sep 09 22:11:15 2009 -0400
     1.3 @@ -162,29 +162,35 @@
     1.4  	Boolean    foundIt = false;
     1.5  
     1.6  	//get the prefpane bundle and find GHA within it.
     1.7 -	NSString *pathToGHA      = [[NSBundle bundleWithIdentifier:GROWL_PREFPANE_BUNDLE_IDENTIFIER] pathForResource:@"GrowlHelperApp" ofType:@"app"];
     1.8 -	//get the file url to GHA.
     1.9 -	CFURLRef urlToGHA = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)pathToGHA, kCFURLPOSIXPathStyle, true);
    1.10 -
    1.11 -	UInt32 seed = 0U;
    1.12 -	NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
    1.13 -	for (id itemObject in currentLoginItems) {
    1.14 -		LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
    1.15 -
    1.16 -		UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
    1.17 -		CFURLRef URL = NULL;
    1.18 -		OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &URL, /*outRef*/ NULL);
    1.19 -		if (err == noErr) {
    1.20 -			foundIt = CFEqual(URL, urlToGHA);
    1.21 -			CFRelease(URL);
    1.22 -
    1.23 -			if (foundIt)
    1.24 -				break;
    1.25 +	NSBundle *prefPaneBundle = [NSBundle bundleWithIdentifier:GROWL_PREFPANE_BUNDLE_IDENTIFIER];
    1.26 +	NSString *pathToGHA      = [prefPaneBundle pathForResource:@"GrowlHelperApp" ofType:@"app"];
    1.27 +	if(pathToGHA) {
    1.28 +		//get the file url to GHA.
    1.29 +		CFURLRef urlToGHA = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)pathToGHA, kCFURLPOSIXPathStyle, true);
    1.30 +		
    1.31 +		UInt32 seed = 0U;
    1.32 +		NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
    1.33 +		for (id itemObject in currentLoginItems) {
    1.34 +			LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
    1.35 +			
    1.36 +			UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
    1.37 +			CFURLRef URL = NULL;
    1.38 +			OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &URL, /*outRef*/ NULL);
    1.39 +			if (err == noErr) {
    1.40 +				foundIt = CFEqual(URL, urlToGHA);
    1.41 +				CFRelease(URL);
    1.42 +				
    1.43 +				if (foundIt)
    1.44 +					break;
    1.45 +			}
    1.46  		}
    1.47 -	}
    1.48 -
    1.49 -	CFRelease(urlToGHA);
    1.50 -
    1.51 +		
    1.52 +		CFRelease(urlToGHA);
    1.53 +	}
    1.54 +	else {
    1.55 +		NSLog(@"Growl: your install is corrupt, you will need to reinstall\nyour prefpane bundle is:%@\n your pathToGHA is:%@", prefPaneBundle, pathToGHA);
    1.56 +	}
    1.57 +	
    1.58  	return foundIt;
    1.59  }
    1.60