--- a/Source/AIPreferenceController.m Sat Jun 02 20:49:21 2012 -0400
+++ b/Source/AIPreferenceController.m Sat Jun 02 22:32:56 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"],
- &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 %@",
- 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) { + userPreferredDownloadFolder = [[fm URLForDirectory:NSDesktopDirectory + inDomain:NSUserDomainMask + appropriateForURL:nil create:YES error:nil] path]; return userPreferredDownloadFolder;