Revision: 4367
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4367&view=rev
Author:   hofman
Date:     2008-08-08 20:17:17 +0000 (Fri, 08 Aug 2008)

Log Message:
-----------
Separate code to resolve aliases and symlinks

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

Modified: trunk/Files_SKExtensions.h
===================================================================
--- trunk/Files_SKExtensions.h  2008-08-07 10:05:01 UTC (rev 4366)
+++ trunk/Files_SKExtensions.h  2008-08-08 20:17:17 UTC (rev 4367)
@@ -48,7 +48,8 @@
 extern BOOL SKFileExistsAtPath(NSString *path);
 extern NSDate *SKFileModificationDateAtPath(NSString *path);
 extern NSString *SKPathFromFileSystemRepresentation(const char *path);
-extern NSString *SKRealPath(NSString *path);
+extern NSURL *SKResolvedURLFromPath(NSString *path);
+
 extern NSString *SKUniqueDirectoryCreating(NSString *basePath, BOOL create);
 extern NSString *SKChewableItemsDirectory();
 extern NSString *SKUniqueTemporaryDirectory();

Modified: trunk/Files_SKExtensions.m
===================================================================
--- trunk/Files_SKExtensions.m  2008-08-07 10:05:01 UTC (rev 4366)
+++ trunk/Files_SKExtensions.m  2008-08-08 20:17:17 UTC (rev 4367)
@@ -124,16 +124,17 @@
     return thePath;
 }
 
-NSString *SKRealPath(NSString *path) {
+extern NSURL *SKResolvedURLFromPath(NSString *path) {
+    NSURL *url = nil;
     FSRef fileRef;
-    NSURL *url = nil;
-    if (CFURLGetFSRef((CFURLRef)[NSURL fileURLWithPath:path], &fileRef))
-        url = (NSURL*)CFURLCreateFromFSRef(NULL, &fileRef);
-    if (url) {
-        path = [url path];
-        [url release];
+    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 path;
+    return url ? url : [NSURL fileURLWithPath:path];
 }
 
 NSString *SKUniqueDirectoryCreating(NSString *basePath, BOOL create) {

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2008-08-07 10:05:01 UTC (rev 4366)
+++ trunk/SKNotesDocument.m     2008-08-08 20:17:17 UTC (rev 4367)
@@ -55,6 +55,7 @@
 #import "NSDocument_SKExtensions.h"
 #import "NSMenu_SKExtensions.h"
 #import "NSView_SKExtensions.h"
+#import "Files_SKExtensions.h"
 
 static NSString *SKNotesDocumentWindowFrameAutosaveName = 
@"SKNotesDocumentWindow";
 
@@ -281,18 +282,7 @@
     NSString *path = [[self fileName] stringByReplacingPathExtension:@"pdf"];
     NSError *error = nil;
     if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
-        FSRef ref;
-        NSURL *url = nil;
-        Boolean isFolder, wasAliased;
-        if (noErr == FSPathMakeRef((const unsigned char *)[[path 
stringByResolvingSymlinksInPath] fileSystemRepresentation], &ref, NULL)) {
-            CFStringRef theUTI = NULL;
-            if (noErr == LSCopyItemAttribute(&ref, kLSRolesAll, 
kLSItemContentType, (CFTypeRef *)&theUTI) && theUTI && UTTypeConformsTo(theUTI, 
kUTTypeResolvable))
-                FSResolveAliasFileWithMountFlags(&ref, TRUE, &isFolder, 
&wasAliased, kARMNoUI);
-           url = [(NSURL *)CFURLCreateFromFSRef(NULL, &ref) autorelease];
-        }
-        if (url == nil)
-            url = [NSURL fileURLWithPath:path];
-        if (nil == [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:url display:YES error:&error])
+        if (nil == [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:SKResolvedURLFromPath(path) 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.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to