// Test code for buf report 9833110 // By Daniel Stødle, daniel@scsc.no, 2011. #import int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *path = @"/Volumes/MobileBackups", *displayname = nil; const UInt8 *cpath = (UInt8*)[path UTF8String]; FSRef ref; Boolean isDirectory = true; [NSApplication sharedApplication]; printf("Path: %s\n", [path UTF8String]); // First: Obtain the display name using the recomended Cocoa API printf("NSFileManager: %s\n", [[[NSFileManager defaultManager] displayNameAtPath:path] UTF8String]); // Next, use Launch Services. First make an FSRef with the default options if (FSPathMakeRefWithOptions(cpath, kFSPathMakeRefDefaultOptions, &ref, &isDirectory) == noErr) { if (LSCopyDisplayNameForRef(&ref, (CFStringRef*)&displayname) == noErr) { printf("LSCopyDisplayNameForRef w/kFSPathMakeRefDefaultOptions: %s\n", [displayname UTF8String]); [displayname release]; } } // Then try the other option we have at our disposal when making the FSRef if (FSPathMakeRefWithOptions(cpath, kFSPathMakeRefDoNotFollowLeafSymlink, &ref, &isDirectory) == noErr) { if (LSCopyDisplayNameForRef(&ref, (CFStringRef*)&displayname) == noErr) { printf("LSCopyDisplayNameForRef w/kFSPathMakeRefDoNotFollowLeafSymlink: %s\n", [displayname UTF8String]); [displayname release]; } } // Finally, try using Launch Services with a URL as input instead if (LSCopyDisplayNameForURL((CFURLRef)[NSURL fileURLWithPath:path], (CFStringRef*)&displayname) == noErr) { printf("LSCopyDisplayNameForURL: %s\n", [displayname UTF8String]); [displayname release]; } [pool release]; return 0; }