Revision: 4008
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4008&view=rev
Author:   hofman
Date:     2008-06-11 17:04:11 -0700 (Wed, 11 Jun 2008)

Log Message:
-----------
Use cocoa function to find app support directories. We never create them, so 
don't bother.

Modified Paths:
--------------
    trunk/SKApplicationController.h
    trunk/SKApplicationController.m
    trunk/SKDocumentController.m
    trunk/SKPDFDocument.m

Modified: trunk/SKApplicationController.h
===================================================================
--- trunk/SKApplicationController.h     2008-06-11 20:40:16 UTC (rev 4007)
+++ trunk/SKApplicationController.h     2008-06-12 00:04:11 UTC (rev 4008)
@@ -69,7 +69,7 @@
 
 - (void)saveCurrentOpenDocuments:(id)sender;
 
-- (NSString *)applicationSupportPathForDomain:(int)domain create:(BOOL)create;
+- (NSArray *)applicationSupportDirectories;
 - (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString 
*)extension;
 - (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString 
*)extension inDirectory:(NSString *)subpath;
 

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2008-06-11 20:40:16 UTC (rev 4007)
+++ trunk/SKApplicationController.m     2008-06-12 00:04:11 UTC (rev 4008)
@@ -444,58 +444,18 @@
     [[[NSDocumentController sharedDocumentController] documents] 
makeObjectsPerformSelector:@selector(saveRecentDocumentInfo)];
 }
 
-- (NSString *)applicationSupportPathForDomain:(int)domain create:(BOOL)create {
-    static CFMutableDictionaryRef pathDict = nil;
-    if (pathDict == nil)
-        pathDict = CFDictionaryCreateMutable(NULL, 3, NULL, 
&kCFTypeDictionaryValueCallBacks);
-    
-    NSString *path = (NSString *)CFDictionaryGetValue(pathDict, (void 
*)domain);
-    
-    if (path == nil || (create && [[NSFileManager defaultManager] 
fileExistsAtPath:path] == NO)) {
-        FSRef foundRef;
-        OSStatus err = noErr;
-        
-        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) {
-                path = [(NSURL *)url path];
-                CFRelease(url);
-            }
-            
-            NSString *appName = [[NSBundle mainBundle] 
objectForInfoDictionaryKey:(NSString *)kCFBundleExecutableKey];
-            
-            if(appName == nil)
-                [NSException raise:NSObjectNotAvailableException 
format:NSLocalizedString(@"Unable to find CFBundleIdentifier for %@", 
@"Exception message"), [NSApp description]];
-            
-            path = [path stringByAppendingPathComponent:appName];
-            
-            CFDictionarySetValue(pathDict, (void *)domain, (void *)path);
-        }
+- (NSArray *)applicationSupportDirectories {
+    static NSArray *applicationSupportDirectories = nil;
+    if (applicationSupportDirectories == nil) {
+        NSMutableArray *pathArray = [NSMutableArray array];
+        NSString *appName = [[NSBundle mainBundle] 
objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
+        NSEnumerator *pathEnum = 
[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, 
NSAllDomainsMask, YES) objectEnumerator];
+        NSString *path;
+        while (path = [pathEnum nextObject])
+            [pathArray addObject:[path 
stringByAppendingPathComponent:appName]];
+        applicationSupportDirectories = [pathArray copy];
     }
-    
-    // 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);
-        }
-    }
-    
-    return path;
+    return applicationSupportDirectories;
 }
 
 - (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString 
*)extension {
@@ -506,17 +466,14 @@
     NSFileManager *fm = [NSFileManager defaultManager];
     NSString *filename = [file stringByAppendingPathExtension:extension];
     NSString *fullPath = nil;
+    NSEnumerator *pathEnum = [[self applicationSupportDirectories] 
objectEnumerator];
     NSString *appSupportPath = nil;
-    int domains[3] = {kUserDomain, kLocalDomain, kNetworkDomain};
-    int i;
     
-    for (i = 0; fullPath == nil && i < 3; i++) {
-        if (appSupportPath = [self applicationSupportPathForDomain:domains[i] 
create:NO]) {
-            fullPath = subpath ? [appSupportPath 
stringByAppendingPathComponent:subpath] : appSupportPath;
-            fullPath = [fullPath stringByAppendingPathComponent:filename];
-            if ([fm fileExistsAtPath:fullPath] == NO)
-                fullPath = nil;
-        }
+    while (appSupportPath = [pathEnum nextObject]) {
+        fullPath = subpath ? [appSupportPath 
stringByAppendingPathComponent:subpath] : appSupportPath;
+        fullPath = [fullPath stringByAppendingPathComponent:filename];
+        if ([fm fileExistsAtPath:fullPath] == NO)
+            fullPath = nil;
     }
     if (fullPath == nil) {
         fullPath = [[NSBundle mainBundle] sharedSupportPath];

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2008-06-11 20:40:16 UTC (rev 4007)
+++ trunk/SKDocumentController.m        2008-06-12 00:04:11 UTC (rev 4008)
@@ -367,10 +367,11 @@
     if (customExportTemplateFiles == nil) {
         NSFileManager *fm = [NSFileManager defaultManager];
         NSMutableSet *templateFiles = [NSMutableSet set];
-        int domains[3] = {kUserDomain, kLocalDomain, kNetworkDomain};
-        int i;
-        for (i = 0; i < 3; i++) {
-            NSString *templatesPath = [[[NSApp delegate] 
applicationSupportPathForDomain:domains[i] create:NO] 
stringByAppendingPathComponent:@"Templates"];
+        NSEnumerator *pathEnum = [[[NSApp delegate] 
applicationSupportDirectories] objectEnumerator];
+        NSString *appSupportPath;
+        
+        while (appSupportPath = [pathEnum nextObject]) {
+            NSString *templatesPath = [appSupportPath 
stringByAppendingPathComponent:@"Templates"];
             BOOL isDir;
             if ([fm fileExistsAtPath:templatesPath isDirectory:&isDir] && 
isDir) {
                 NSEnumerator *fileEnum = [[fm subpathsAtPath:templatesPath] 
objectEnumerator];

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2008-06-11 20:40:16 UTC (rev 4007)
+++ trunk/SKPDFDocument.m       2008-06-12 00:04:11 UTC (rev 4008)
@@ -1483,21 +1483,14 @@
         } else {
             NSString *path = [environment objectForKey:@"PATH"];
             NSMutableArray *paths = [NSMutableArray 
arrayWithObjects:@"/usr/local/bin", nil];
+            NSEnumerator *pathEnum = [[[NSApp delegate] 
applicationSupportDirectories] objectEnumerator];
             NSString *appSupportPath;
             if ([path length]) 
                 [paths insertObject:path atIndex:0];
-            if (appSupportPath = [[NSApp delegate] 
applicationSupportPathForDomain:kUserDomain create:NO]) {
+            while (appSupportPath = [pathEnum nextObject]) {
                 [paths addObject:appSupportPath];
                 [paths addObject:[appSupportPath 
stringByAppendingPathComponent:@"Scripts"]];
             }
-            if (appSupportPath = [[NSApp delegate] 
applicationSupportPathForDomain:kLocalDomain create:NO]) {
-                [paths addObject:appSupportPath];
-                [paths addObject:[appSupportPath 
stringByAppendingPathComponent:@"Scripts"]];
-            }
-            if (appSupportPath = [[NSApp delegate] 
applicationSupportPathForDomain:kNetworkDomain create:NO]) {
-                [paths addObject:appSupportPath];
-                [paths addObject:[appSupportPath 
stringByAppendingPathComponent:@"Scripts"]];
-            }
             [environment setObject:[paths componentsJoinedByString:@":"] 
forKey:@"PATH"];
         }
         


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to