1. Perry Metzger
  2. growl

Commits

Rudy Richter  committed 384b50b

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

  • Participants
  • Parent commits 78f3398
  • Branches future-1.2.1

Comments (0)

Files changed (1)

File Core/Source/GrowlPluginController.m

View file
 		if ([fileManager copyPath:filename toPath:destination handler:nil]) {
 			[self dispatchPluginAtPath:destination];
 			[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
-			NSBeginInformationalAlertSheet( NSLocalizedString( @"Plugin installed", @"" ),
+			if([self _hasNativeArchitecture:destination])
+				NSBeginInformationalAlertSheet( NSLocalizedString( @"Plugin installed", @"" ),
 											NSLocalizedString( @"No",  @"" ),
 											NSLocalizedString( @"Yes", @"" ),
 											nil, nil, self,
 	// retain a copy of the filename because it is passed as context to the sheetDidEnd selectors
 	NSString *filenameCopy = [[NSString alloc] initWithString:filename];
 
-	if ([[NSFileManager defaultManager] fileExistsAtPath:destination]) {
-		// plugin already exists at destination
-		[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
-		NSBeginAlertSheet( NSLocalizedString( @"Plugin already exists", @"" ),
-						   NSLocalizedString( @"No", @"" ),
-						   NSLocalizedString( @"Yes", @"" ), nil, nil, self,
-						   NULL, @selector(pluginExistsSelector:returnCode:contextInfo:),
-						   filenameCopy,
-						   NSLocalizedString( @"Plugin '%@' is already installed, do you want to overwrite it?", @"" ),
-						   [pluginFile stringByDeletingPathExtension] );
-	} else {
-		[self pluginExistsSelector:nil returnCode:NSAlertAlternateReturn contextInfo:filenameCopy];
+	//Check to see if we've got valid architectures in this plugin for our use, if not, bail.
+	if(![self _hasNativeArchitecture:filenameCopy]) {
+		NSBeginAlertSheet( NSLocalizedString( @"Plugin missing native architecture", @"" ),
+						  NSLocalizedString( @"No", @"" ),
+						  NSLocalizedString( @"Yes", @"" ), nil, nil, self,
+						  NULL, @selector(pluginExistsSelector:returnCode:contextInfo:),
+						  filenameCopy,
+						  NSLocalizedString( @"Plugin '%@' does not work with the currently running architecture, install it anyway? (with the understanding that it won't load)", @"" ),
+						  [pluginFile stringByDeletingPathExtension] );		
 	}
+	else {
+		if ([[NSFileManager defaultManager] fileExistsAtPath:destination]) {
+			// plugin already exists at destination
+			[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
+			NSBeginAlertSheet( NSLocalizedString( @"Plugin already exists", @"" ),
+							  NSLocalizedString( @"No", @"" ),
+							  NSLocalizedString( @"Yes", @"" ), nil, nil, self,
+							  NULL, @selector(pluginExistsSelector:returnCode:contextInfo:),
+							  filenameCopy,
+							  NSLocalizedString( @"Plugin '%@' is already installed, do you want to overwrite it?", @"" ),
+							  [pluginFile stringByDeletingPathExtension] );
+		} else {
+			[self pluginExistsSelector:nil returnCode:NSAlertAlternateReturn contextInfo:filenameCopy];
+		}
+	}
+}
+
+- (BOOL)_hasNativeArchitecture:(NSString*)filename {	
+	BOOL result = NO;
+	NSInteger currentArchitecture = 0;
+#if defined(__ppc__) && __ppc__
+	currentArchitecture = NSBundleExecutableArchitecturePPC;
+#elif defined(__i386__) && __i386__
+	currentArchitecture = NSBundleExecutableArchitectureI386;
+#elif defined(__x86_64__) && __x86_64__
+	currentArchitecture = NSBundleExecutableArchitectureX86_64;
+#else
+	#error unsupported architecture
+#endif
+	NSBundle *pluginBundle = [NSBundle bundleWithPath:filename];
+	NSArray *pluginArchitectures = [pluginBundle executableArchitectures];
+	if([pluginArchitectures containsObject:[NSNumber numberWithInteger:currentArchitecture]])
+		result = YES;
+	return result;
 }
 
 @end