adium-1.4 3078:7eced108f702: Use `-[NSString(AIStringAdditions) ...

commits at adium.im commits at adium.im
Mon Oct 11 17:49:15 UTC 2010


details:	http://hg.adium.im/adium-1.4/rev/7eced108f702
revision:	3078:7eced108f702
author:		Evan Schoenberg
date:		Mon Oct 11 12:49:07 2010 -0500

Use `-[NSString(AIStringAdditions) stringByExpandingBundlePath]` and `-[NSString(AIStringAdditions) stringByCollapsingBundlePath]` so that our cached path to the active message style is app-bundle-relative if one of our shipping style is being used. This, in turn, fixes various subtle problems which could occur particularly if the user had multiple copies of Adium in differing versions installed.

Thanks to Matthew (mathuaerknedam) for his detailed investigation and reporting.

diffs (126 lines):

diff -r 5e06c4ce8862 -r 7eced108f702 Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m	Mon Oct 11 11:49:30 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m	Mon Oct 11 12:49:07 2010 -0500
@@ -23,12 +23,14 @@
 #import <AIUtilities/AIBundleAdditions.h>
 #import "AIWebkitMessageViewStyle.h"
 #import <Adium/AIChat.h>
+#import <AIUtilities/AIStringAdditions.h>
 
 #define NEW_CONTENT_RETRY_DELAY					0.01
 #define MESSAGE_STYLES_SUBFOLDER_OF_APP_SUPPORT @"Message Styles"
 
 @interface AIWebKitMessageViewPlugin ()
 - (void) resetStylesForType:(AIWebkitStyleType)styleType;
+- (void)performAdium14UpgradeIfNeeded;
 @end
 
 @implementation AIWebKitMessageViewPlugin
@@ -40,7 +42,8 @@
 {
 	styleDictionary = nil;
 	[adium createResourcePathForName:MESSAGE_STYLES_SUBFOLDER_OF_APP_SUPPORT];
-
+	[self performAdium14UpgradeIfNeeded];
+	
 	//Setup our preferences
 	[adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed:WEBKIT_DEFAULT_PREFS forClass:[self class]]
 										  forGroup:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
@@ -192,12 +195,15 @@
 	
 	if(loadFromGroup && thisStyle) {
 		id<AIPreferenceController> prefs = adium.preferenceController;
+		
+		/* We use the path directly, if possible, to avoid a relatively expensive search through multiple folders */
 		*thisStyle = [AIWebkitMessageViewStyle messageViewStyleFromPath:[prefs preferenceForKey:KEY_CURRENT_WEBKIT_STYLE_PATH
 																							group:loadFromGroup]];
 		if(!*thisStyle) {
+			/* If the path isn't cached yet, load the style and then store the path */
 			*thisStyle = [AIWebkitMessageViewStyle messageViewStyleFromBundle:[self messageStyleBundleWithIdentifier:[prefs preferenceForKey:KEY_WEBKIT_STYLE
 																																		   group:loadFromGroup]]];
-			[prefs setPreference:[[*thisStyle bundle] bundlePath]
+			[prefs setPreference:[[[*thisStyle bundle] bundlePath] stringByCollapsingBundlePath]
 						  forKey:KEY_CURRENT_WEBKIT_STYLE_PATH
 						   group:loadFromGroup];
 		}
@@ -221,18 +227,24 @@
 {
 	[styleDictionary release]; styleDictionary = nil;
 	
-	if(styleType == AIWebkitRegularChat) {
-		[currentRegularStyle release]; currentRegularStyle = nil;
-		
-		[adium.preferenceController setPreference:nil
-											 forKey:KEY_CURRENT_WEBKIT_STYLE_PATH
-											  group:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
-	} else {	
-		[currentGroupStyle release]; currentGroupStyle = nil;
+	switch (styleType) {
+		case AIWebkitRegularChat:
+		{			
+			[currentRegularStyle release]; currentRegularStyle = nil;
 			
-		[adium.preferenceController setPreference:nil
-										 forKey:KEY_CURRENT_WEBKIT_STYLE_PATH
-										  group:PREF_GROUP_WEBKIT_GROUP_MESSAGE_DISPLAY];
+			[adium.preferenceController setPreference:nil
+											   forKey:KEY_CURRENT_WEBKIT_STYLE_PATH
+												group:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
+			break;
+		}
+		case AIWebkitGroupChat:
+		{	
+			[currentGroupStyle release]; currentGroupStyle = nil;
+			
+			[adium.preferenceController setPreference:nil
+											   forKey:KEY_CURRENT_WEBKIT_STYLE_PATH
+												group:PREF_GROUP_WEBKIT_GROUP_MESSAGE_DISPLAY];
+		}
 	}
 }
 
@@ -265,4 +277,20 @@
 	return [NSString stringWithFormat:@"%@:%@", style, key];
 }
 
+#pragma mark -
+/*!
+ * @brief Clears the cached style bundle path when Adium 1.4 loads for the first time, so it'll be recreated app-bundle-relative
+ */
+- (void)performAdium14UpgradeIfNeeded
+{
+#define KEY_CLEARED_CACHED_BUNDLE_PATH @"Adium 1.4:Cleared cached bundle path"
+	if (![[NSUserDefaults standardUserDefaults] boolForKey:KEY_CLEARED_CACHED_BUNDLE_PATH]) {
+		[self resetStylesForType:AIWebkitRegularChat];
+		[self resetStylesForType:AIWebkitGroupChat];
+
+		[[NSUserDefaults standardUserDefaults] setBool:YES
+												forKey:KEY_CLEARED_CACHED_BUNDLE_PATH];
+	}
+}
+
 @end
diff -r 5e06c4ce8862 -r 7eced108f702 Plugins/WebKit Message View/AIWebkitMessageViewStyle.h
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h	Mon Oct 11 11:49:30 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h	Mon Oct 11 12:49:07 2010 -0500
@@ -135,6 +135,8 @@
 
 /*!
  *	@brief Create a message view style instance by loading the bundle at the passed path
+ *
+ * @param path The path, which will be expanded to be bundle-relative via -[NSString(AIStringAdditions) stringByExpandingBundlePath] as needed
  */
 + (id)messageViewStyleFromPath:(NSString *)path;
 
diff -r 5e06c4ce8862 -r 7eced108f702 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Mon Oct 11 11:49:30 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Mon Oct 11 12:49:07 2010 -0500
@@ -128,7 +128,7 @@
 
 + (id)messageViewStyleFromPath:(NSString *)path
 {
-	NSBundle *styleBundle = [NSBundle bundleWithPath:path];
+	NSBundle *styleBundle = [NSBundle bundleWithPath:[path stringByExpandingBundlePath]];
 	if(styleBundle)
 		return [[[self alloc] initWithBundle:styleBundle] autorelease];
 	return nil;




More information about the commits mailing list