Hi,
I actually detect whether a file is an alias this way:
I use a NSString category where self is the filePath.

- (BOOL)IsAliasOld
{
    FSRef    sourceRef;
    
    OSErr    err = [self GetFSRef:&sourceRef];
    if(err) return NO;
    
    Boolean    isFSDirectory, aliasFileFlag;
    
    err = FSIsAliasFile(&sourceRef, &aliasFileFlag, &isFSDirectory);
    if(err) return NO;
    else return aliasFileFlag;
}

- (OSErr)GetFSRef:(FSRef*)sourceRef
{
    const char *cSrcPath = [[NSFileManager defaultManager]
fileSystemRepresentationWithPath:self];
    if(cSrcPath == 0 || *cSrcPath == _NUL) return -1;
    
    OSErr err = FSPathMakeRefWithOptions((UInt8*)cSrcPath,
kFSPathMakeRefDoNotFollowLeafSymlink, sourceRef, NULL);
    return err;
}


Since FSIsAliasFile is deprecated (I compile for 10.9) I would now use

- (BOOL)IsAliasNew
{
    NSString    *type = [[NSWorkspace sharedWorkspace] typeOfFile:self
error:nil];
    return [type isEqualToString:@"com.apple.alias-file"];
}

The problem is that the IsAliasNew method is 3.7 times slower than the
IsAliasOld method. Do you know a way to accomplish that with a faster
method?


Regards
-- Leonardo


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to