adium 4846:224889d2c89e: Try to recreate the saved downloads dir...

commits at adium.im commits at adium.im
Sun Jun 3 04:45:58 UTC 2012


details:	http://hg.adium.im/adium/rev/224889d2c89e
revision:	4846:224889d2c89e
branch:		(none)
author:		Frank Dowsett <wixardy at adium.im>
date:		Sat Jun 02 22:32:56 2012 -0400

Try to recreate the saved downloads directory if we have one and it doesn't exist or use the user's downloads directory, if neither of those exist then try the desktop. I also removed the query for Safari's directory. Fixes #13824
Subject: adium 4847:3860ca6e903c: Rob's right, 200 is too small, increase it to the current max; 1280 might end up being too small for some people.

details:	http://hg.adium.im/adium/rev/3860ca6e903c
revision:	4847:3860ca6e903c
branch:		(none)
author:		Frank Dowsett <wixardy at adium.im>
date:		Sun Jun 03 00:45:17 2012 -0400

Rob's right, 200 is too small, increase it to the current max; 1280 might end up being too small for some people.

diffs (89 lines):

diff -r b7b9e309b4b1 -r 3860ca6e903c Resources/AppearanceDefaults.plist
--- a/Resources/AppearanceDefaults.plist	Sat Jun 02 20:49:21 2012 -0400
+++ b/Resources/AppearanceDefaults.plist	Sun Jun 03 00:45:17 2012 -0400
@@ -21,7 +21,7 @@
 	<key>Vertical Autosizing</key>
 	<false/>
 	<key>Vertical Height</key>
-	<integer>200</integer>
+	<integer>1280</integer>
 	<key>Window Opacity</key>
 	<real>1</real>
 	<key>Window Style</key>
diff -r b7b9e309b4b1 -r 3860ca6e903c Source/AIPreferenceController.m
--- a/Source/AIPreferenceController.m	Sat Jun 02 20:49:21 2012 -0400
+++ b/Source/AIPreferenceController.m	Sun Jun 03 00:45:17 2012 -0400
@@ -521,57 +521,25 @@
 	
 	userPreferredDownloadFolder = [[self preferenceForKey:@"UserPreferredDownloadFolder"
 													group:PREF_GROUP_GENERAL] stringByExpandingTildeInPath];
-	
+
+	NSFileManager *fm = [NSFileManager defaultManager];
 	if (!userPreferredDownloadFolder) {
-		//10.5: ICGetPref() for kICDownloadFolder is useless
-		CFURLRef	urlToDefaultBrowser = NULL;
-		
-		//Use Safari's preference as a default if it's the default browser and it is set
-		if (LSGetApplicationForURL((CFURLRef)[NSURL URLWithString:@"http://google.com"],
-								   kLSRolesViewer,
-								   NULL /*outAppRef*/,
-								   &urlToDefaultBrowser) != kLSApplicationNotFoundErr) {
-			NSString	*defaultBrowserName = nil;
-			
-			defaultBrowserName = [[NSFileManager defaultManager] displayNameAtPath:[(NSURL *)urlToDefaultBrowser path]];
-			
-			if ([defaultBrowserName rangeOfString:@"Safari"].location != NSNotFound) {
-				/* ICGetPref() for kICDownloadFolder returns any previously set preference, not the default ~/Downloads or the current
-				 * Safari setting, in 10.5.0, with Safari the default browser
-				 */
-				CFPropertyListRef safariDownloadsPath = CFPreferencesCopyAppValue(CFSTR("DownloadsPath"),CFSTR("com.apple.Safari"));
-				if (safariDownloadsPath) {
-					//This should return a CFStringRef... we're using another app's prefs, so make sure.
-					if (CFGetTypeID(safariDownloadsPath) == CFStringGetTypeID()) {
-						userPreferredDownloadFolder = (NSString *)safariDownloadsPath;
-					}
-					
-					[(NSObject *)safariDownloadsPath autorelease];
-				}					
-			}
-		}
-
-		NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
-		if ([searchPaths count]) {
-			userPreferredDownloadFolder = [searchPaths objectAtIndex:0];
-		}
+		userPreferredDownloadFolder = [[fm URLForDirectory:NSDownloadsDirectory
+												  inDomain:NSUserDomainMask
+										 appropriateForURL:nil create:YES error:nil] path];
 	}
 
-	/* If we can't write to the specified folder, fall back to the desktop and then to the home directory;
-	 * if neither are writable the user has worse problems then an IM download to worry about.
-	 */
-	if (![[NSFileManager defaultManager] isWritableFileAtPath:userPreferredDownloadFolder]) {
-		NSString *originalFolder = userPreferredDownloadFolder;
-
-		userPreferredDownloadFolder = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"];
-
-		if (![[NSFileManager defaultManager] isWritableFileAtPath:userPreferredDownloadFolder]) {
-			userPreferredDownloadFolder = NSHomeDirectory();
-		}
-
-		NSLog(@"Could not obtain write access for %@; defaulting to %@",
-			  originalFolder,
-			  userPreferredDownloadFolder);
+	//If the existing folder doesn't exist anymore, try to create it falling back to the desktop if that fails
+	BOOL isDir = NO, created = NO;
+	if (userPreferredDownloadFolder && ![fm fileExistsAtPath:userPreferredDownloadFolder isDirectory:&isDir]) {
+		//Try to create the saved folder
+		created = [fm createDirectoryAtPath:userPreferredDownloadFolder withIntermediateDirectories:YES attributes:nil error:nil];
+	}
+	if (!isDir && !created) {
+		//Try the desktop
+		userPreferredDownloadFolder = [[fm URLForDirectory:NSDesktopDirectory
+												  inDomain:NSUserDomainMask
+										 appropriateForURL:nil create:YES error:nil] path];
 	}
 
 	return userPreferredDownloadFolder;




More information about the commits mailing list