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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Become a Certified Penetration Testing Engineer

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.

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apple Hardware

From novice to tech pro — start learning today.