Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > resolving aliases

resolving aliases
Thread Tools
seb2
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jan 22, 2002, 06:57 PM
 
hi everybody,

i want to find out about the favorites someone set. neither nsuserdefaults nor nsfilemanager nor nsworkspace offer me a simple list of favorites.

so i thought that it might be in some .plist. doesn't seem to be.

then i thought that i'd just resolve the aliases in ~/library/favorites.

the question is: how do i resolve aliases? resolving symlinks is easily done with nsfilewrapper, but aliases?

i have an idea for a workaround, but i'm not sure it'll work and also it would be very ugly.

any ideas?

edit: i'm aware of the carbon alias manager. don't tell me there's no way to do that from cocoa.

[ 01-22-2002: Message edited by: seb2 ]
     
Wixar
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Jan 22, 2002, 10:43 PM
 
You are welcome to use this method I wrote (as a category on NSString). It's from my JPEGDeux program. Make sure to #import <Carbon/Carbon.h> as well.

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>

<font color = brown>//returns a path to the file pointed at by self if self is an alias, self otherwise</font>
<font color = brown>//yes, we do follow chains of aliases</font>
<font color = brown>//returns nil if self cannot be resolved. Does not attempt to mount volumes.</font>
<font color = brown>//if isDir is not nil, returns whether or not the resolved file is a directory</font>
- (NSString*)resolveAliasesIsDir BOOL*)pIsDir {
Boolean isDir, wasAlias;
FSRef ref;
OSStatus result;
result=FSPathMakeRef([self UTF8String], &ref, &isDir);
if (result != noErr) return nil;
if (isDir) {
if (pIsDir) *pIsDir=YES;
return self;
}
result=FSResolveAliasFileWithMountFlags(&ref, YES, &isDir, &wasAlias, kARMNoUI | kARMSearch);
if (pIsDir) *pIsDir=isDir;
if (result != noErr) return nil;
if (wasAlias) {
unsigned char pathBuff[<font color = blue>512</font>];
result=FSRefMakePath(&ref, pathBuff, sizeof pathBuff);
if (result != noErr) return nil;
return [NSString stringWithCString athBuff];
}
return self;
}

</font>[/code]

Beware: while looking back over my code, I think it may have issues with aliases that refer to files with non-ASCII characters in their names.

-Peter
     
Wixar
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Jan 22, 2002, 10:45 PM
 
Oh, to answer your second question, there's no way to do it from Cocoa. Yet.
     
seb2  (op)
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jan 23, 2002, 07:12 PM
 
carbon really is something i haven't yet discovered, but i'll see what i can make of it.

your help is really appreciated, thank you very much!
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:38 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,