How Do I Access user data folder on mac using carbon

I am trying to get path to user data in C++ with carbon.

The path is /Users/{username}/Library/Application Support

I have seen code like
      FSRef fsRef;
      char szPath[1024];
      OSErr tError = noErr;
      tError = FSFindFolder(kOnAppropriateDisk,kPreferenceFolderType,kDontCreateFolder,&fsRef);
      tError = FSRefMakePath(&fsRef,(UInt8*)path,1024);

However since I am writing cross-application plug-in for adobe application, I will not have a mac to test on for another couple of days. Can someone verify code that would work for me.
LVL 2
steven_bryantAsked:
Who is Participating?
 
pgnatyukConnect With a Mentor Commented:
I attached the code.
CoreServices framework should be added to the project (FSFindFolder and FSRefMakePath are from there).
char path[PATH_MAX];
FSRef foundRef;
OSErr err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, kDontCreateFolder, &foundRef);
if (err == noErr)
   FSRefMakePath(&foundRef, (UInt8*)path, sizeof(path));

Open in new window

0
 
pgnatyukCommented:
kPreferenceFolderType - what is this?
Usually it looks like:
myOSStatus = FSFindFolder(kUserDomain,kChewableFolderType,kCreateFolder,&myTempFolderFSRef);

In the next line:
 tError = FSRefMakePath(&fsRef,(UInt8*)path,1024);

'path' - what is this? Probably you wanted to declare
unsigned char path[260]?

Do you need to get to your bundle?

Here you will find many examples and the last one is similar to yours.
http://www.cocoadev.com/index.pl?ApplicationSupportFolder
0
 
steven_bryantAuthor Commented:
Thanks pgnatyuk for your comment.
I just copied and pasted code without really inspecting too much.

However is FSFindFolde carbon?

Also would it be possible to test the code and rewrite it, since I can't test at this time
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
pgnatyukCommented:
I re-read your question again and see: "The path is /Users/{username}/Library/Application Support". So I do understand more or less what you need.
Yes, it is Carbon. I'll check it.
 
0
 
steven_bryantAuthor Commented:
Here is another piece of code I received on Adobe forum http://forums.adobe.com/message/2729174#2729174

FSRef yourUserFolderRef;
OSErr err = FSFindFolder(kUserDomain, kCurrentUserFolderType, kDontCreateFolder, &yourUserFolderRef);
 
CFURLRef fURL = CFURLCreateFromFSRef(kCFAllocatorDefault, &yourUserFolderRef);
CFURLRef fHomeURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, fURL, CFSTR("Library/Application Support"), true);
CFRelease(fURL);
 
CFStringRef fHFSPath = CFURLCopyFileSystemPath(fHomeURL, kCFURLHFSPathStyle);

What do you think about it?
0
 
pgnatyukCommented:
You last comment is about the same - simply another folder. I've posted a link where all this stuff is explained.
http://www.cocoadev.com/index.pl?ApplicationSupportFolder
0
 
steven_bryantAuthor Commented:
However, I have not tested it yet at this time, but it looks goof
0
 
steven_bryantAuthor Commented:
what is the #include for core foundation framework
0
 
pgnatyukCommented:
In Xcode you simple add a framework. Through popup menu. Or -framework CoreServices to the compile and lnk flags.
 
0
 
steven_bryantAuthor Commented:
Thanks. Please excuse my total mac ineptness. I imagine that the plugin project will already include that, but if i'm stuck i'll holler back. Thanks for your help.
0
 
steven_bryantAuthor Commented:
One more question. Will this work with Unicode string. Lets say username is non-english. Am I getting back a unicode or at least UTF8 string?
0
 
pgnatyukCommented:
I work more with Cocoa than with Carbon. I do not understand why you need Carbon. The latest Xcode even does not have these project templates. Everything works fine in Cocoa. NSString covers all these Unicode problems.
0
 
steven_bryantAuthor Commented:
I'm kind of confused myself. But I think the indesign sdk which uses c++ needs carbon code.

Could you give me cocoa sample that I can test to see if it works
0
 
pgnatyukCommented:
If your carbon code works, leave it as it is.  Inside a cocoa project (objective-c) you can use c, c++, etc
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.