Revision: 5663
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5663&view=rev
Author:   hofman
Date:     2009-09-04 11:32:35 +0000 (Fri, 04 Sep 2009)

Log Message:
-----------
move some files functions inline

Modified Paths:
--------------
    trunk/Files_SKExtensions.h
    trunk/Files_SKExtensions.m
    trunk/SKDownload.m
    trunk/SKNotesDocument.m

Modified: trunk/Files_SKExtensions.h
===================================================================
--- trunk/Files_SKExtensions.h  2009-09-04 10:46:55 UTC (rev 5662)
+++ trunk/Files_SKExtensions.h  2009-09-04 11:32:35 UTC (rev 5663)
@@ -38,16 +38,11 @@
 
 #import <Cocoa/Cocoa.h>
 
-// This function is not thread safe
 
-NSString *SKDownloadDirectory();
-
 // These functions are thread safe
 
 extern BOOL SKFileIsInTrash(NSURL *fileURL);
-extern NSURL *SKResolvedURLFromPath(NSString *path);
 
-extern NSString *SKUniqueDirectoryCreating(NSString *basePath, BOOL create);
 extern NSString *SKChewableItemsDirectory();
 extern NSString *SKUniqueTemporaryDirectory();
 extern NSString *SKUniqueChewableItemsDirectory();

Modified: trunk/Files_SKExtensions.m
===================================================================
--- trunk/Files_SKExtensions.m  2009-09-04 10:46:55 UTC (rev 5662)
+++ trunk/Files_SKExtensions.m  2009-09-04 11:32:35 UTC (rev 5663)
@@ -39,24 +39,6 @@
 #import "Files_SKExtensions.h"
 #import <CoreFoundation/CoreFoundation.h>
 
-NSString *SKDownloadDirectory() {
-    
-       static NSString *downloadsDirectory = nil;
-    
-    if (nil == downloadsDirectory) {
-        OSStatus err = fnfErr;
-        FSRef pathRef;
-        CFURLRef downloadsURL;
-        
-        err = FSFindFolder(kUserDomain, kDownloadsFolderType, TRUE, &pathRef);
-        if(err == noErr && (downloadsURL = 
CFURLCreateFromFSRef(CFAllocatorGetDefault(), &pathRef))) {
-            downloadsDirectory = (NSString 
*)CFURLCopyFileSystemPath(downloadsURL, kCFURLPOSIXPathStyle);
-            CFRelease(downloadsURL);
-        }
-    }
-    return downloadsDirectory;
-}
-
 BOOL SKFileIsInTrash(NSURL *fileURL) {
     NSCParameterAssert([fileURL isFileURL]);    
     FSRef fileRef;
@@ -69,36 +51,20 @@
     return result;
 }
 
-extern NSURL *SKResolvedURLFromPath(NSString *path) {
-    NSURL *url = nil;
-    FSRef fileRef;
-    Boolean isFolder, isAlias;
-    if (noErr == FSPathMakeRef((const unsigned char *)[[path 
stringByResolvingSymlinksInPath] fileSystemRepresentation], &fileRef, NULL)) {
-        CFStringRef theUTI = NULL;
-        if (noErr == LSCopyItemAttribute(&fileRef, kLSRolesAll, 
kLSItemContentType, (CFTypeRef *)&theUTI) && theUTI && UTTypeConformsTo(theUTI, 
kUTTypeResolvable))
-            FSResolveAliasFileWithMountFlags(&fileRef, TRUE, &isFolder, 
&isAlias, kARMNoUI);
-       url = [(NSURL *)CFURLCreateFromFSRef(NULL, &fileRef) autorelease];
-    }
-    return url ?: [NSURL fileURLWithPath:path];
-}
-
-NSString *SKUniqueDirectoryCreating(NSString *basePath, BOOL create) {
+static NSString *SKUniqueDirectory(NSString *basePath) {
     CFUUIDRef uuid = CFUUIDCreate(NULL);
     NSString *tmpDirName = [(NSString *)CFUUIDCreateString(NULL, uuid) 
autorelease];
     CFRelease(uuid);
     
     BOOL success = YES;
+    FSRef tmpRef;
+    UniCharCount length = [tmpDirName length];
+    UniChar *tmpName = (UniChar *)NSZoneMalloc(NULL, length * sizeof(UniChar));
+    [tmpDirName getCharacters:tmpName];
+    success = noErr == FSPathMakeRef((UInt8 *)[basePath 
fileSystemRepresentation], &tmpRef, NULL) &&
+              noErr == FSCreateDirectoryUnicode(&tmpRef, length, tmpName, 
kFSCatInfoNone, NULL, NULL, NULL, NULL);
+    NSZoneFree(NULL, tmpName);
     
-    if (create) {
-        FSRef tmpRef;
-        UniCharCount length = [tmpDirName length];
-        UniChar *tmpName = (UniChar *)NSZoneMalloc(NULL, length * 
sizeof(UniChar));
-        [tmpDirName getCharacters:tmpName];
-        success = noErr == FSPathMakeRef((UInt8 *)[basePath 
fileSystemRepresentation], &tmpRef, NULL) &&
-                  noErr == FSCreateDirectoryUnicode(&tmpRef, length, tmpName, 
kFSCatInfoNone, NULL, NULL, NULL, NULL);
-        NSZoneFree(NULL, tmpName);
-    }
-    
     return success ? [basePath stringByAppendingPathComponent:tmpDirName] : 
nil;
 }
 
@@ -143,9 +109,9 @@
 }
 
 NSString *SKUniqueTemporaryDirectory() {
-    return SKUniqueDirectoryCreating(NSTemporaryDirectory(), YES);
+    return SKUniqueDirectory(NSTemporaryDirectory());
 }
 
 NSString *SKUniqueChewableItemsDirectory() {
-    return SKUniqueDirectoryCreating(SKChewableItemsDirectory(), YES);
+    return SKUniqueDirectory(SKChewableItemsDirectory());
 }

Modified: trunk/SKDownload.m
===================================================================
--- trunk/SKDownload.m  2009-09-04 10:46:55 UTC (rev 5662)
+++ trunk/SKDownload.m  2009-09-04 11:32:35 UTC (rev 5663)
@@ -335,7 +335,9 @@
 }
 
 - (void)download:(NSURLDownload *)download 
decideDestinationWithSuggestedFilename:(NSString *)filename {
-    [URLDownload setDestination:[SKDownloadDirectory() 
stringByAppendingPathComponent:filename] allowOverwrite:NO];
+    NSArray *downloadDirs = 
NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, 
YES);
+    if ([downloadDirs count])
+        [URLDownload setDestination:[[downloadDirs lastObject] 
stringByAppendingPathComponent:filename] allowOverwrite:NO];
 }
 
 - (void)download:(NSURLDownload *)download didCreateDestination:(NSString 
*)path {

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2009-09-04 10:46:55 UTC (rev 5662)
+++ trunk/SKNotesDocument.m     2009-09-04 11:32:35 UTC (rev 5663)
@@ -304,7 +304,19 @@
     NSString *path = [[self fileName] stringByReplacingPathExtension:@"pdf"];
     NSError *error = nil;
     if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
-        if (nil == [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:SKResolvedURLFromPath(path) display:YES 
error:&error])
+        // resolve symlinks and aliases
+        NSURL *url = nil;
+        FSRef fileRef;
+        Boolean isFolder, isAlias;
+        if (noErr == FSPathMakeRef((const unsigned char *)[[path 
stringByResolvingSymlinksInPath] fileSystemRepresentation], &fileRef, NULL)) {
+            CFStringRef theUTI = NULL;
+            if (noErr == LSCopyItemAttribute(&fileRef, kLSRolesAll, 
kLSItemContentType, (CFTypeRef *)&theUTI) && theUTI && UTTypeConformsTo(theUTI, 
kUTTypeResolvable))
+                FSResolveAliasFileWithMountFlags(&fileRef, TRUE, &isFolder, 
&isAlias, kARMNoUI);
+           url = [(NSURL *)CFURLCreateFromFSRef(NULL, &fileRef) autorelease];
+        }
+        if (url == nil)
+            url = [NSURL fileURLWithPath:path];
+        if (nil == [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:url display:YES error:&error])
             [NSApp presentError:error];
     } else NSBeep();
 }


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

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to