adium 3363:731004b1c10d: Use `-[NSString(AIStringAdditions) stri...

commits at adium.im commits at adium.im
Fri Oct 15 03:33:03 UTC 2010


details:	http://hg.adium.im/adium/rev/731004b1c10d
revision:	3363:731004b1c10d
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.
(transplanted from 7eced108f702ddaaf16b978711066464aa36cdac)
Subject: adium 3364:1dd2d5e3c166: Decrease fragility by clearing any webkit style path that contains .app.  If for some odd reason the user is using an external style with .app in the name, they will simply occur a nearly-trivial performance hit when opening their first message window.

details:	http://hg.adium.im/adium/rev/1dd2d5e3c166
revision:	3364:1dd2d5e3c166
author:		Evan Schoenberg
date:		Thu Oct 14 22:29:08 2010 -0500

Decrease fragility by clearing any webkit style path that contains .app.  If for some odd reason the user is using an external style with .app in the name, they will simply occur a nearly-trivial performance hit when opening their first message window.
(transplanted from 04d6ee8c45ac1cd71ef0710a4672dfff0e973362)

diffs (126 lines):

diff -r ecd5bd357b36 -r 1dd2d5e3c166 Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m	Thu Oct 14 22:30:59 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m	Thu Oct 14 22:29:08 2010 -0500
@@ -23,6 +23,7 @@
 #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"
@@ -30,6 +31,7 @@
 @interface AIWebKitMessageViewPlugin ()
 - (void) resetStylesForType:(AIWebkitStyleType)styleType;
 - (void) xtrasChanged:(NSNotification *)notification;
+- (void)clearHardcodedBuiltInStylePaths;
 @end
 
 @implementation AIWebKitMessageViewPlugin
@@ -41,7 +43,8 @@
 {
 	styleDictionary = nil;
 	[adium createResourcePathForName:MESSAGE_STYLES_SUBFOLDER_OF_APP_SUPPORT];
-
+	[self clearHardcodedBuiltInStylePaths];
+	
 	//Setup our preferences
 	[adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed:WEBKIT_DEFAULT_PREFS forClass:[self class]]
 										  forGroup:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
@@ -193,12 +196,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];
 		}
@@ -222,18 +228,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];
+		}
 	}
 }
 
@@ -266,4 +278,19 @@
 	return [NSString stringWithFormat:@"%@:%@", style, key];
 }
 
+#pragma mark -
+/*!
+ * @brief Clears cached style bundle pathes if they are built-in but not bundle-relative; Adium 1.4b18 and prior made these.
+ */
+- (void)clearHardcodedBuiltInStylePaths
+{
+	if ([[adium.preferenceController preferenceForKey:KEY_CURRENT_WEBKIT_STYLE_PATH
+												group:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY] rangeOfString:@".app"].location != NSNotFound)
+		[self resetStylesForType:AIWebkitRegularChat];
+
+	if ([[adium.preferenceController preferenceForKey:KEY_CURRENT_WEBKIT_STYLE_PATH
+												group:PREF_GROUP_WEBKIT_GROUP_MESSAGE_DISPLAY] rangeOfString:@".app"].location != NSNotFound)
+		[self resetStylesForType:AIWebkitGroupChat];
+}
+
 @end
diff -r ecd5bd357b36 -r 1dd2d5e3c166 Plugins/WebKit Message View/AIWebkitMessageViewStyle.h
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h	Thu Oct 14 22:30:59 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h	Thu Oct 14 22:29:08 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 ecd5bd357b36 -r 1dd2d5e3c166 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Thu Oct 14 22:30:59 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Thu Oct 14 22:29:08 2010 -0500
@@ -132,7 +132,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