From: <ho...@us...> - 2007-08-30 12:23:35
|
Revision: 2778 http://skim-app.svn.sourceforge.net/skim-app/?rev=2778&view=rev Author: hofman Date: 2007-08-30 05:04:37 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Make sure the application support folder is created if needed. We might have asked for the path without creating it before. Modified Paths: -------------- trunk/SKApplicationController.m Modified: trunk/SKApplicationController.m =================================================================== --- trunk/SKApplicationController.m 2007-08-30 11:22:19 UTC (rev 2777) +++ trunk/SKApplicationController.m 2007-08-30 12:04:37 UTC (rev 2778) @@ -363,18 +363,18 @@ pathDict = CFDictionaryCreateMutable(NULL, 3, NULL, &kCFTypeDictionaryValueCallBacks); NSString *path = (NSString *)CFDictionaryGetValue(pathDict, (void *)domain); + FSRef foundRef = NULL; + OSStatus err = noErr; - if (path == nil) { - FSRef foundRef; - OSStatus err = noErr; - + if (path == nil || (create && [[NSFileManager defaultManager] fileExistsAtPath:path] == NO)) { err = FSFindFolder(domain, kApplicationSupportFolderType, create ? kCreateFolder : kDontCreateFolder, &foundRef); if (err != noErr) { if (create) NSLog(@"Error %d: the system was unable to find your Application Support folder.", err); return nil; } - + } + if (path == nil) { CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &foundRef); if (url != nil) { @@ -390,19 +390,19 @@ path = [path stringByAppendingPathComponent:appName]; CFDictionarySetValue(pathDict, (void *)domain, (void *)path); - - // the call to FSFindFolder creates the parent hierarchy, but not the directory we're looking for - if (create) { - BOOL dirExists = [[NSFileManager defaultManager] fileExistsAtPath:path]; - if (dirExists == NO) { - BOOL pathIsDir; - dirExists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&pathIsDir]; - if (dirExists == NO || pathIsDir == NO) - [[NSFileManager defaultManager] createDirectoryAtPath:path attributes:nil]; - // make sure it was created - dirExists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&pathIsDir]; - NSAssert1(dirExists && pathIsDir, @"Unable to create folder %@", path); - } + } + + // the call to FSFindFolder creates the parent hierarchy, but not the directory we're looking for + if (create) { + BOOL dirExists = [[NSFileManager defaultManager] fileExistsAtPath:path]; + if (dirExists == NO) { + BOOL pathIsDir; + dirExists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&pathIsDir]; + if (dirExists == NO || pathIsDir == NO) + [[NSFileManager defaultManager] createDirectoryAtPath:path attributes:nil]; + // make sure it was created + dirExists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&pathIsDir]; + NSAssert1(dirExists && pathIsDir, @"Unable to create folder %@", path); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |