tags:

views:

15

answers:

2

Hi All

With this code I am trying to get the path in const char *pathPtr from fsRefAEDesc. It gives the correct name and path if there are no special characters in the name of file which is there in fsRefAEDesc. Now if path has some special characters /Users/XYZ/.rtf I don't get a correct fsRef from AEGetDescData(). I believe it has some thing to do with Encoding and tried some them but could make it work.

FSRef fsRef;
//AEDesc fsRefAEDesc; //comes from some where. 

status = AEGetDescData( &fsRefAEDesc, (void*)(&fsRef), sizeof(FSRef));
//OSErr result = FSMakeFSRefUnicode(&fsRef, 1024, (UniCharPtr)(&fsRef),   kTextEncodingUnknown, &fileRef);
AEDisposeDesc( &fsRefAEDesc );

 CFURLRef* gotURLRef = CFURLCreateFromFSRef(NULL, &fsRef);
 CFStringRef macPath = CFURLCopyFileSystemPath(gotURLRef,  kCFURLPOSIXPathStyle);

 const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());

Is there is any way to read such paths?
Thanks in advance!
M
A: 

At what point in your code does the problem occur? For instance, if you insert CFShow(macPath), do you see the right path in the debug log? If so, then you are not passing the right encoding to CFStringGetCStringPtr. Use UTF-8.

JWWalker
Manish
It might be that the URL contains the right characters, but the Unicode escapes are being added for display in the log.An FSRef is a file reference, not a file name. The FSRef is not the problem.
JWWalker
A: 

Also tried this for gotURLRef but I got the same on my console i.e. "/Users/Manish/Desktop/\u27a4\u00a9\u261a.png"

The Unicode escape sequence is what you get when going through CFURL calls. URL has very limited character range.

You can try FSRefMakePath. It will get you UTF8 encoded path from a FSRef.

Stephen Chu