check the plugin the user just double clicked to see if it has the current running architecture in it, if not let them know that they can install it but that its not going to actually load, rather than the previous behavior of just loading it and leaving the user wondering why it doesn't show up future-1.2.1
authorRudy Richter
Thu Sep 17 23:26:08 2009 -0400 (2009-09-17)
branchfuture-1.2.1
changeset 4457384b50bb0ab1
parent 4456 78f33988db18
child 4458 2597ed525cf7
child 4460 3cbd662ab3c1
check the plugin the user just double clicked to see if it has the current running architecture in it, if not let them know that they can install it but that its not going to actually load, rather than the previous behavior of just loading it and leaving the user wondering why it doesn't show up
Core/Source/GrowlPluginController.m
     1.1 --- a/Core/Source/GrowlPluginController.m	Sun Aug 30 12:47:50 2009 -0400
     1.2 +++ b/Core/Source/GrowlPluginController.m	Thu Sep 17 23:26:08 2009 -0400
     1.3 @@ -817,7 +817,8 @@
     1.4  		if ([fileManager copyPath:filename toPath:destination handler:nil]) {
     1.5  			[self dispatchPluginAtPath:destination];
     1.6  			[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
     1.7 -			NSBeginInformationalAlertSheet( NSLocalizedString( @"Plugin installed", @"" ),
     1.8 +			if([self _hasNativeArchitecture:destination])
     1.9 +				NSBeginInformationalAlertSheet( NSLocalizedString( @"Plugin installed", @"" ),
    1.10  											NSLocalizedString( @"No",  @"" ),
    1.11  											NSLocalizedString( @"Yes", @"" ),
    1.12  											nil, nil, self,
    1.13 @@ -846,19 +847,50 @@
    1.14  	// retain a copy of the filename because it is passed as context to the sheetDidEnd selectors
    1.15  	NSString *filenameCopy = [[NSString alloc] initWithString:filename];
    1.16  
    1.17 -	if ([[NSFileManager defaultManager] fileExistsAtPath:destination]) {
    1.18 -		// plugin already exists at destination
    1.19 -		[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
    1.20 -		NSBeginAlertSheet( NSLocalizedString( @"Plugin already exists", @"" ),
    1.21 -						   NSLocalizedString( @"No", @"" ),
    1.22 -						   NSLocalizedString( @"Yes", @"" ), nil, nil, self,
    1.23 -						   NULL, @selector(pluginExistsSelector:returnCode:contextInfo:),
    1.24 -						   filenameCopy,
    1.25 -						   NSLocalizedString( @"Plugin '%@' is already installed, do you want to overwrite it?", @"" ),
    1.26 -						   [pluginFile stringByDeletingPathExtension] );
    1.27 -	} else {
    1.28 -		[self pluginExistsSelector:nil returnCode:NSAlertAlternateReturn contextInfo:filenameCopy];
    1.29 -	}
    1.30 +	//Check to see if we've got valid architectures in this plugin for our use, if not, bail.
    1.31 +	if(![self _hasNativeArchitecture:filenameCopy]) {
    1.32 +		NSBeginAlertSheet( NSLocalizedString( @"Plugin missing native architecture", @"" ),
    1.33 +						  NSLocalizedString( @"No", @"" ),
    1.34 +						  NSLocalizedString( @"Yes", @"" ), nil, nil, self,
    1.35 +						  NULL, @selector(pluginExistsSelector:returnCode:contextInfo:),
    1.36 +						  filenameCopy,
    1.37 +						  NSLocalizedString( @"Plugin '%@' does not work with the currently running architecture, install it anyway? (with the understanding that it won't load)", @"" ),
    1.38 +						  [pluginFile stringByDeletingPathExtension] );		
    1.39 +	}
    1.40 +	else {
    1.41 +		if ([[NSFileManager defaultManager] fileExistsAtPath:destination]) {
    1.42 +			// plugin already exists at destination
    1.43 +			[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
    1.44 +			NSBeginAlertSheet( NSLocalizedString( @"Plugin already exists", @"" ),
    1.45 +							  NSLocalizedString( @"No", @"" ),
    1.46 +							  NSLocalizedString( @"Yes", @"" ), nil, nil, self,
    1.47 +							  NULL, @selector(pluginExistsSelector:returnCode:contextInfo:),
    1.48 +							  filenameCopy,
    1.49 +							  NSLocalizedString( @"Plugin '%@' is already installed, do you want to overwrite it?", @"" ),
    1.50 +							  [pluginFile stringByDeletingPathExtension] );
    1.51 +		} else {
    1.52 +			[self pluginExistsSelector:nil returnCode:NSAlertAlternateReturn contextInfo:filenameCopy];
    1.53 +		}
    1.54 +	}
    1.55 +}
    1.56 +
    1.57 +- (BOOL)_hasNativeArchitecture:(NSString*)filename {	
    1.58 +	BOOL result = NO;
    1.59 +	NSInteger currentArchitecture = 0;
    1.60 +#if defined(__ppc__) && __ppc__
    1.61 +	currentArchitecture = NSBundleExecutableArchitecturePPC;
    1.62 +#elif defined(__i386__) && __i386__
    1.63 +	currentArchitecture = NSBundleExecutableArchitectureI386;
    1.64 +#elif defined(__x86_64__) && __x86_64__
    1.65 +	currentArchitecture = NSBundleExecutableArchitectureX86_64;
    1.66 +#else
    1.67 +	#error unsupported architecture
    1.68 +#endif
    1.69 +	NSBundle *pluginBundle = [NSBundle bundleWithPath:filename];
    1.70 +	NSArray *pluginArchitectures = [pluginBundle executableArchitectures];
    1.71 +	if([pluginArchitectures containsObject:[NSNumber numberWithInteger:currentArchitecture]])
    1.72 +		result = YES;
    1.73 +	return result;
    1.74  }
    1.75  
    1.76  @end